LAMP+logzilla+sphinx+syslog-ng实现集中日志管理(第一版)[原创]

一、前言


       目前查看系统日志比较被动,遇到系统不正常或故障时才会主动去检查服务器系统日志,这样一来不能及时了解系统的运行情况,因此部署Logzilla+sphine+syslog-ng来弥补这不足。以下为安装、部署平台详细步骤。(Logzilla是什么新东西?其实前身就是php-syslog-ng,引用作者的话“Php-syslog-ng is now known as LogZilla. Same owner, better code :-)”)

二、平台初始化


#yum install libdbi* libnet
#cpan Date::Calc Text::LevenshteinXS String::CRC32

三、下载相关包


#cd /home/install
#mkdir logzilla;cd logzilla
#wget http://www.balabit.com/downloads/files/eventlog/0.2/eventlog_0.2.9.tar.gz
#wget http://www.balabit.com/downloads/files/syslog-ng/open-source-edition/3.0.3/setups/rhel-5-i386/syslog-ng-3.0.3-1.rhel5.i386.rpm

四、开始安装


# cp eventlog_0.2.9.tar.gz /usr/src/redhat/SOURCES/
# tar zxvf  eventlog_0.2.9.tar.gz
# cd eventlog-0.2.9/
# rpmbuild –ba eventlog.spec.bb
# cd /usr/src/redhat/RPMS/x86_64
# rpm -Uvh libevtlog*

#cd /home/install/logzilla
#rpm -Uvh syslog-ng-3.0.3-1.rhel5.i386.rpm

五、安装logzilla


#cd /www/webroot/
#wget http://php-syslog-ng.googlecode.com/files/logzilla_3.0.85.tgz
#tar -zxvf logzilla_3.0.85.tgz
#cd logzilla/scripts
#./install.pl

(根据实际情况来回应就OK了)

===================
        LogZilla Installation
====================
Enter the MySQL root username [root]: 
Enter the password for root [mysql]: 
Database to install to [syslog]: 
Database table to install to [logs]: 
Enter the name of the MySQL server [127.0.0.1]: 
Enter the port of the MySQL server [3306]: 
Enter the name to create as the owner of the logs database [syslogadmin]: 
Enter the password for the syslogadmin user [syslogadmin]: 
Enter the name to create as the WEBSITE owner [admin]: 
Enter the password for admin [admin]: 
Enter your email address [[email protected]]: 
Enter a name for your website [The home of LogZilla]: 
Enter the base url for your site (include trailing slash) [/logs/]: /
Where should log files be stored? [/var/log/logzilla]: 
How long should I keep old logs? (in days) [30]: 
========================================
        Path Updates
========================================
Getting ready to replace paths in all files with "/www/webroot/logzilla"
Ok to continue? [y]: 
Updating file paths
Modifying ../scripts/db_insert.pl
Modifying ../scripts/contrib/system_configs/logzilla.crontab
Modifying ../scripts/contrib/system_configs/syslog-ng.conf
Modifying ../scripts/contrib/system_configs/logzilla.apache
Modifying ../sphinx/indexer.sh
Modifying ../sphinx/sphinx.conf
Updating log paths
Modifying ../scripts/contrib/system_configs/logzilla.crontab
Modifying ../scripts/contrib/system_configs/logzilla.logrotate
====================
        Database Installation
====================
All data will be installed into the syslog database
Ok to continue? [y]: 
====================
        Config.php generation
====================
Generating /www/webroot/logzilla/html/config/config.php
Ok to continue? [y]: 
====================
        System files
====================
Adding LogZilla logrotate.d file to /etc/logrotate.d
Ok to continue? [y]: 
Where is your syslog-ng.conf file located? [/etc/syslog-ng/syslog-ng.conf]: /opt/syslog-ng/etc/syslog-ng.conf
Adding syslog-ng configuration to /opt/syslog-ng/etc/syslog-ng.conf
Ok to continue? [y]: 
Found 1 sources
Which source definition would you like to use? [s_all]: 
        LogZilla installation complete...
Note: you may need to enable the MySQL Event Scheduler in your /etc/my.cnf file.
Please visit http://forum.logzilla.info/index.php/topic,71.0.html for more information.
Also, please visit http://nms.gdd.net/index.php/Install_Guide_for_LogZilla_v3.0#UDP_Buffers to learn how to increase your UDP buffer size (otherwise you may drop messages).
Please run /etc/init.d/syslog-ng restart

六、安装 Sphinx


#cd logzilla/sphinx/src
#tar xzvf sphinx-0.9.9.tar.gz

#cd sphinx-0.9.9
#./configure –prefix `pwd`/../..
#make && make install

#cd /www/webroot/logzilla/sphinx
#vi sphinx.conf
#!/usr/bin/php 替换成实际php的位置,如#!/usr/local/php/bin/php
#./indexer.sh full
#bin/searchd

提示:
ERROR: index 'idx_logs': sql_query_pre[0]: Column 'max_id' cannot be null (DSN=mysql://syslogadmin:***@127.0.0.1:3306/syslog).
如果看到该信息,属正常,因为现在还没有数据:)

添加作业:

30 0 1 * */www/webroot/logzilla/sphinx/indexer.sh full >>/www/webroot/logzilla/sphinx/log/sphinx_indexer.log 2>&1
*/5 * * * */www/webroot/logzilla/sphinx/indexer.sh delta >>/www/webroot/logzilla/sphinx/log/sphinx_indexer.log 2>&1
0 0 * * */www/webroot/logzilla/sphinx/indexer.sh merge >>/www/webroot/logzilla/sphinx/log/sphinx_indexer.log 2>&1

添加rc.local
#vi /etc/rc.local

/www/webroot/logzilla/sphinx/bin/searchd -c /www/webroot/logzilla/sphinx/sphinx.conf

七、配置Mysql


# mysql -u<username> -p<password>  
mysql> SELECT @@event_scheduler;  
+-------------------+  
| @@event_scheduler |  
+-------------------+  
| OFF               |  
+-------------------+  
1 row in set (0.00 sec)

激活event_scheduler

view plainprint?
mysql> SET GLOBAL event_scheduler = 1;   
Query OK, 0 rows affected (0.00 sec)  
  
mysql> SELECT @@event_scheduler;  
+-------------------+  
| @@event_scheduler |  
+-------------------+  
| ON                |  
+-------------------+  
1 row in set (0.00 sec)  
mysql> quit;

八、修改Syslog-ng配置


v#i /opt/syslog-ng/etc/syslog-ng.conf

(略)

九、修改apache配置


#vi httpd.conf

view plainprint?
# LogZilla  
   Alias /logs "/www/webroot/logzilla/html/"  
   <Directory "/www/webroot/logzilla/html/">  
       Options Indexes MultiViews FollowSymLinks  
       AllowOverride All  
   Order allow,deny  
   Allow from all  
   </Directory>

重启apache服务:/etc/init.d/apache2 restart

十、IONCube授权


http://127.0.0.1/logs/login.php
1.gif
下载源码包ioncube_loaders_lin_x86-64.tar.gz

#mkdir -p /usr/local/ioncube
#tar -zxvf ioncube_loaders_lin_x86-64.tar.gz
#cd ioncube
#cp * /usr/local/ioncube/
#vi /usr/local/php/lib/php.ini
zend_extension = /usr/local/ioncube/ioncube_loader_lin_5.2.so

#/etc/init.d/apache2 restart

十一、安装完毕


http://127.0.0.1/logs/login.php
根据install.pl配置的管理员帐号密码进行登录。
1、MainPage
4.png
2、StatPage
5.png
十二、客户端配置


#vi /etc/syslog.conf
在最后添加以下,其中syslog.admin.com.cn为主机域名,也可以直接用IP代替。

*.emerg;*.err;*.warning         @syslog.admin.com.cn

#/etc/init.d/syslog restart

测试:logger -p local4.err "This is a local.err test message."

参考文献:
http://nms.gdd.net/index.php/Install_Guide_for_LogZilla_v3.0

如大家有什么疑问或感兴趣的话题可以通过weibo与我交流:http://t.qq.com/yorkoliu

转自:http://blog.liuts.com/post/207/#entrymore

原创文章,作者:s19930811,如若转载,请注明出处:http://www.178linux.com/1753

(0)
s19930811s19930811
上一篇 2015-03-27 17:15
下一篇 2015-03-27 18:00

相关推荐

  • DNS配置案例 二

    DNS配置案例 二 DNS配置案例 二 1 §·DNS的配置与案例 1 §·测试工具 3 §·主配置文件格式:/etc/named.conf 7 §·缓存名称服务器的配置: 8 §·配置解析一个正向区域 : 以loveme.com域为例: 10 §·配置解析一个反向区域 : 以loveme.com域为例: 15 §·配置从DNS服务器 19 §·问…

    Linux干货 2016-09-26
  • 马哥教育21期网络班—第六周课程+练习—-成长进行时

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; [root@localhost ~]# cp /etc/rc.d/rc.sysinit /tmp/rc.sysinit&nbs…

    Linux干货 2016-08-03
  • 马哥教育网络第21期-第十四周课程练习

    系统的INPUT和OUTPUT默认策略为DROP; iptables -P INPUT DROP iptables -P OUTPUT DROP 1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的页面不允许访问; web服务器仅允许…

    Linux干货 2016-12-26
  • 文本三剑客之AWK

    文本三剑客—-awk(3) awk简介 awk是一个强大的文本分析工具,与grep(查找)、sed(编辑)一并称为“文本处理三剑客”。awk最强大的功能是对数据分析并生成报告。 awk有3个不同版本: awk、nawk和gawk,未作特别说明,一般指gawk,gawk是AWK的GNU版本。 awk其名称得自于它的创始人 Alfred Aho 、P…

    2017-07-17
  • 文件查找:locate/find

    文件查找就是在文件系统上查找符合条件的文件,工具名分别为:locate和find locate是非实时查找或数据库查找的工具;而find则是实时查找工具。 locate locate依赖于事先构建的索引。索引的构建是在系统较为空闲时自动进行(即为周期性任务),也可以手动更新数据库(updatedb) 注意:索引构建过程需要遍历整个根文件系统,极其消耗资源。 …

    Linux干货 2016-03-12
  • 第十周作业

    1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情)     CentOS系统启动流程:     1.加电自检:由bios去检测各硬件是否存在且是否正常运行,然后进行硬件初始化     2.选择启动顺序,加载mbr:根据bios设置的设备启动顺序,…

    2017-07-03