一、前言
为什么要引入第二版?由于 第一版是基于Logzilla3.0,作者在Logzilla3.0以后做了licensed限制,可以从作者回复邮件的内容得到证实[图1]。因此需要定期去更新license.txt来达到延长使用期限的目的,个人感觉比较麻烦,同时还有主机及日志数的限制,这也是整理第二版的原因,当然,你也可以通过以下途径获取免费、无限制的licensed,见 How to get a free, unlimited, license of LogZilla。但这不是本文所要讨论的话题:),第二版中本人采用logzilla2.9.9版来搭建一个免费、无限制的日志集中管理平台,功能上与3.0差异不大,好了,废话少说,我们开始吧!
平台截图
二、平台初始化
部署LAMP平台(略)
#yum install libdbi* libnet
#cpan Date::Calc Text::LevenshteinXS String::CRC32
#cpan -i Digest::SHA1
#cpan -i Net::MySQL
三、下载相关包
#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_v2.9.9o.tgz
#tar xzvf logzilla_v2.9.9o.tgz
#mkdir -p /var/log/logzilla
六、配置Mysql
# mysql -u -p
mysql> SELECT @@event_scheduler;
+-------------------+
| @@event_scheduler |
+-------------------+
| OFF |
+-------------------+
1 row in set (0.00 sec)
低于Mysql5.1版本会提示如下,如不打算升级到logzilla3.0,没有关系,可以略过此步骤。
mysql> SELECT @@event_scheduler;
ERROR 1193 (HY000): Unknown system variable 'event_scheduler'
激活event_scheduler
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配置
#vi /opt/syslog-ng/etc/syslog-ng.conf
八、修改apache配置
#vi httpd.conf
重启apache服务:/etc/init.d/apache2 restart
九、修改php.ini
Vi /usr/local/php/lib/php.ini
十、配置日志分隔
cp /www/webroot/php-syslog-ng/scripts/contrib/system_configs/logrotate.d /etc/logrotate.d/logzilla
十一、添加作业
@daily /usr/local/php/bin/php /www/webroot/php-syslog-ng/scripts/logrotate.php >> /var/log/php-syslog-ng/logrotate.log
@daily /usr/bin/find /www/webroot/php-syslog-ng/html/jpcache/ -atime 1 -exec rm -f '{}' ';'
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/php/bin/php /www/webroot/php-syslog-ng/scripts/reloadcache.php >> /var/log/php-syslog-ng/reloadcache.log
十二、开始平台安装
# /etc/init.d/syslog-ng restart
http://192.168.0.100/logs/来进行安装
步骤如下:
十三、替换脚本路径
cd /www/wewroot/php-syslog-ng/scripts
./fixpaths.sh
或者直接用sed来修改
#sed -i -e "{ s@/path_to_logzilla@/www/webroot/php-syslog-ng@}" *.*
#/etc/init.d/syslog-ng restart
十四、客户端配置
在最后添加以下,其中syslog.admin.com.cn为主机域名,也可以直接用IP代替。
#vi /etc/syslog.conf
*.emerg;*.err;*.warning @syslog.admin.com.cn
#/etc/init.d/syslog restart
测试:logger -p local4.err "This is a local.err test message."
十五、后续问题
问题一、点击[Graph]时会提示“JpGraph Error Font file "/usr/share/fonts/truetype/msttcorefonts/verdana.ttf" is not readable or does not exist.”
解决方法:
mkdir -p /usr/share/fonts/truetype/msttcorefonts/
上传windows XP/2003/vista/下的字体文件verdana.ttf到/usr/share/fonts/truetype/msttcorefonts/即可。
问题二、logs表无数据,运行/www/webroot/php-syslog-ng/scripts/contrib/dbgen/dbgen.pl
提示:Cannot determine peer address at /usr/lib/perl5/site_perl/5.8.5/Net/MySQL.pm line 277
解决方法:
1、是logzilla2.9.9安装时一个bug,新建的mysql的syslogadmin、sysloguser用户权限没有成功赋予,手工添加上就OK了,感谢【杭州】FIGO提供的故障案例。
2、如第1步不成功,尝试修改/www/webroot/php-syslog-ng/html/config/config.php文件mysql主机地址localhost为127.0.0.1。
问题三、搜索缓存图表只显示两天的数据,最近三天没有数据?
解决方法:
由于search_cache表采用的是MEMORY存储引擎,有大小的限制,修改一下/etc/my.cnf,在[MYSQLD]添加:
tmp_table_size=1G
max_heap_table_size = 1G
再重启mysql就可以了。
效果图:
问题四、不能显示日志当中带有"<"、">"的问题,如思科系统的日志。
感谢[常州]老高提供的故障案例。
解决方法:
在tailresult.php和regularresult.php中查找
在里面添加
即可。
问题五、客户端日志无法入库。
感谢[北京]永远飞扬提供的故障案例。
系统环境:
CentOS release 5.5 (Final) i386 2.6.18-194.el5
LAMP (系统rpm默认安装)
Mysql:5.0.77
Php:PHP 5.1.6
Apache:2.2.3
原因:
perl for mysql驱动异常,直接采用bin/mysql+insert sql语句入库。
解决方法:
#vi /opt/syslog-ng/etc/syslog-ng.conf
*注:配置中的相关参数需根据个人实际环境进行修改。
全世界都在找logzilla_v2.9.9o.tgz包,打包线上的包放上来(修复原先一些小bug)
参考文献: http://nms.gdd.net/index.php/LogZilla_Installation_Guide
如大家有什么疑问或感兴趣的话题可以通过weibo与我交流: http://t.qq.com/yorkoliu
为什么要引入第二版?由于 第一版是基于Logzilla3.0,作者在Logzilla3.0以后做了licensed限制,可以从作者回复邮件的内容得到证实[图1]。因此需要定期去更新license.txt来达到延长使用期限的目的,个人感觉比较麻烦,同时还有主机及日志数的限制,这也是整理第二版的原因,当然,你也可以通过以下途径获取免费、无限制的licensed,见 How to get a free, unlimited, license of LogZilla。但这不是本文所要讨论的话题:),第二版中本人采用logzilla2.9.9版来搭建一个免费、无限制的日志集中管理平台,功能上与3.0差异不大,好了,废话少说,我们开始吧!
[图1]
平台截图
二、平台初始化
部署LAMP平台(略)
引用
#yum install libdbi* libnet
#cpan Date::Calc Text::LevenshteinXS String::CRC32
#cpan -i Digest::SHA1
#cpan -i Net::MySQL
三、下载相关包
引用
#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_v2.9.9o.tgz
#tar xzvf logzilla_v2.9.9o.tgz
#mkdir -p /var/log/logzilla
六、配置Mysql
引用
# mysql -u -p
mysql> SELECT @@event_scheduler;
+-------------------+
| @@event_scheduler |
+-------------------+
| OFF |
+-------------------+
1 row in set (0.00 sec)
低于Mysql5.1版本会提示如下,如不打算升级到logzilla3.0,没有关系,可以略过此步骤。
mysql> SELECT @@event_scheduler;
ERROR 1193 (HY000): Unknown system variable 'event_scheduler'
激活event_scheduler
引用
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配置
#vi /opt/syslog-ng/etc/syslog-ng.conf
- @version: 3.0
- source s_local {
- internal();
- unix-stream("/dev/log");
- file("/proc/kmsg" program_override("kernel: "));
- };
- source s_local {
- udp(ip(0.0.0.0) port(514));
- };
- # destinations
- destination d_messages { file("/var/log/messages"); };
- ###########################################################################################
- # Clay's LogZilla config below
- ###########################################################################################
- # Last updated on 2010-06-15
- ###########################################################################################
- options {
- long_hostnames(off);
- # doesn't actually help on Solaris, log(3) truncates at 1024 chars
- log_msg_size(8192);
- # buffer just a little for performance
- # sync(1); <- Deprecated - use flush_lines() instead
- flush_lines(1);
- # memory is cheap, buffer messages unable to write (like to loghost)
- log_fifo_size(16384);
- # Hosts we don't want syslog from
- #bad_hostname("^(ctld.|cmd|tmd|last)$");
- # The time to wait before a dead connection is reestablished (seconds)
- time_reopen(10);
- #Use DNS so that our good names are used, not hostnames
- use_dns(yes);
- dns_cache(yes);
- #Use the whole DNS name
- use_fqdn(yes);
- keep_hostname(yes);
- chain_hostnames(no);
- #Read permission for everyone
- perm(0644);
- # The default action of syslog-ng 1.6.0 is to log a STATS line
- # to the file every 10 minutes. That's pretty ugly after a while.
- # Change it to every 12 hours so you get a nice daily update of
- # # how many messages syslog-ng missed (0).
- # stats(43200);
- };
- destination d_logzilla {
- program("/www/webroot/php-syslog-ng/scripts/db_insert.pl"
- template("$HOST\t$FACILITY\t$PRIORITY\t$LEVEL\t$TAG\t$YEAR-$MONTH-$DAY\t$HOUR:$MIN:$SEC\t$PROGRAM\t$MSG\n")
- template_escape(yes)
- );
- };
- # Tell syslog-ng to log to our new destination
- log {
- source(s_local);
- destination(d_logzilla);
- };
八、修改apache配置
#vi httpd.conf
- <VirtualHost *:80>
- ServerAdmin liutiansi@gmail.com
- DocumentRoot /www/webroot/php-syslog-ng/html/
- ServerName syslog.com.cn
- ErrorLog logs/syslog.com.cn-error_log
- CustomLog logs/syslog.com.cn-access_log common
- # LogZilla
- Alias /logs "/www/webroot/php-syslog-ng/html/"
- <Directory "/www/webroot/php-syslog-ng/html/">
- Options Indexes MultiViews FollowSymLinks
- AllowOverride All
- Order allow,deny
- Allow from all
- </Directory>
- </VirtualHost>
重启apache服务:/etc/init.d/apache2 restart
九、修改php.ini
Vi /usr/local/php/lib/php.ini
- memory_limit = 128M
- max_execution_time = 300
- /etc/init.d/apache2 restart
十、配置日志分隔
cp /www/webroot/php-syslog-ng/scripts/contrib/system_configs/logrotate.d /etc/logrotate.d/logzilla
十一、添加作业
引用
@daily /usr/local/php/bin/php /www/webroot/php-syslog-ng/scripts/logrotate.php >> /var/log/php-syslog-ng/logrotate.log
@daily /usr/bin/find /www/webroot/php-syslog-ng/html/jpcache/ -atime 1 -exec rm -f '{}' ';'
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/php/bin/php /www/webroot/php-syslog-ng/scripts/reloadcache.php >> /var/log/php-syslog-ng/reloadcache.log
十二、开始平台安装
# /etc/init.d/syslog-ng restart
http://192.168.0.100/logs/来进行安装
步骤如下:
十三、替换脚本路径
引用
cd /www/wewroot/php-syslog-ng/scripts
./fixpaths.sh
或者直接用sed来修改
引用
#sed -i -e "{ s@/path_to_logzilla@/www/webroot/php-syslog-ng@}" *.*
#/etc/init.d/syslog-ng restart
十四、客户端配置
在最后添加以下,其中syslog.admin.com.cn为主机域名,也可以直接用IP代替。
#vi /etc/syslog.conf
*.emerg;*.err;*.warning @syslog.admin.com.cn
#/etc/init.d/syslog restart
测试:logger -p local4.err "This is a local.err test message."
十五、后续问题
问题一、点击[Graph]时会提示“JpGraph Error Font file "/usr/share/fonts/truetype/msttcorefonts/verdana.ttf" is not readable or does not exist.”
解决方法:
mkdir -p /usr/share/fonts/truetype/msttcorefonts/
上传windows XP/2003/vista/下的字体文件verdana.ttf到/usr/share/fonts/truetype/msttcorefonts/即可。
问题二、logs表无数据,运行/www/webroot/php-syslog-ng/scripts/contrib/dbgen/dbgen.pl
提示:Cannot determine peer address at /usr/lib/perl5/site_perl/5.8.5/Net/MySQL.pm line 277
解决方法:
1、是logzilla2.9.9安装时一个bug,新建的mysql的syslogadmin、sysloguser用户权限没有成功赋予,手工添加上就OK了,感谢【杭州】FIGO提供的故障案例。
2、如第1步不成功,尝试修改/www/webroot/php-syslog-ng/html/config/config.php文件mysql主机地址localhost为127.0.0.1。
问题三、搜索缓存图表只显示两天的数据,最近三天没有数据?
解决方法:
由于search_cache表采用的是MEMORY存储引擎,有大小的限制,修改一下/etc/my.cnf,在[MYSQLD]添加:
tmp_table_size=1G
max_heap_table_size = 1G
再重启mysql就可以了。
效果图:
问题四、不能显示日志当中带有"<"、">"的问题,如思科系统的日志。
感谢[常州]老高提供的故障案例。
解决方法:
在tailresult.php和regularresult.php中查找
- if (CISCO_TAG_PARSE )
- {
- $row['msg'] = preg_replace('/\s:/', ':', $row['msg']);
- $row['msg'] = preg_replace('/.*(%.*?:.*)/', '$1', $row['msg']);
- }
在里面添加
- $row['msg'] = preg_replace('/</', ' ', $row['msg']);
- $row['msg'] = preg_replace('/>/', ' ', $row['msg']);
即可。
问题五、客户端日志无法入库。
感谢[北京]永远飞扬提供的故障案例。
系统环境:
CentOS release 5.5 (Final) i386 2.6.18-194.el5
LAMP (系统rpm默认安装)
Mysql:5.0.77
Php:PHP 5.1.6
Apache:2.2.3
原因:
perl for mysql驱动异常,直接采用bin/mysql+insert sql语句入库。
解决方法:
#vi /opt/syslog-ng/etc/syslog-ng.conf
- @version: 3.0
- #Default configuration file for syslog-ng.
- #
- # For a description of syslog-ng configuration file directives, please read
- # the syslog-ng Administrator?ˉs guide at:
- #
- # http://www.balabit.com/dl/html/syslog-ng-admin-guide_en.html/bk01-toc.html
- #
- options {
- # Number of syslog lines stored in memory before being written to files
- flush_lines (1);
- log_fifo_size (2048);
- create_dirs (yes);
- perm (0640);
- dir_perm (0750);
- keep_hostname (yes);
- time_reopen (10);
- log_fifo_size (1024);
- long_hostnames (off);
- use_dns (no);
- use_fqdn (no);
- owner(root);
- group(root);
- perm(0640);
- };
- source s_network_1 {
- udp(ip(0.0.0.0) port(514));
- };
- destination d_network_1 {
- file("/var/log/syslog-ng/network/$YEAR.$MONTH.$DAY/$HOST/$FACILITY.log");
- };
- # Define the destination "d_network_1B" log directory
- destination d_network_1B {
- file ("/var/log/syslog-ng/network/all/network.log");
- };
- log {
- source(s_network_1);
- destination(d_network_1);
- };
- log {
- source(s_network_1);
- destination(d_network_1B);
- };
- destination d_logzilla {
- program("/var/www/html/php-syslog-ng/scripts/db_insert.pl"
- template("$HOST\t$FACILITY\t$PRIORITY\t$LEVEL\t$TAG\t$YEAR-$MONTH-$DAY\t$HOUR:$MIN:$SEC\t$PROGRAM\t$MSG\n"));
- };#
- log {
- source(s_network_1);
- destination(d_logzilla);
- };
- source localhost_all {
- internal();
- unix-stream("/dev/log");
- file("/proc/kmsg" program_override("kernel"));
- };
- destination localhostlog {
- file ("/var/log/syslog-ng/$HOST/$YEAR-$MONTH/$DAY" create_dirs(yes));
- };
- log {
- source(localhost_all);
- destination(localhostlog);
- };
- destination local_logzilla {
- program("/var/www/html/php-syslog-ng/scripts/db_insert.pl"
- template("$HOST\t$FACILITY\t$PRIORITY\t$LEVEL\t$TAG\t$YEAR-$MONTH-$DAY\t$HOUR:$MIN:$SEC\t$PROGRAM\t$MSG\n"));
- };
- destination d_mysql {
- program("/usr/bin/mysql -usyslogadmin -psyslogadmin syslog"
- template("INSERT INTO logs (host, facility, priority, level, tag, datetime, program, msg, seq)
- VALUES ( '$HOST', '$FACILITY', '$PRIORITY', '$LEVEL', '$TAG', '$YEAR-$MONTH-$DAY $HOUR:$MIN:$SEC', '$PROGRAM', '$MSG', '$SEQ' );\n")
- template-escape(yes));
- };
- log {
- source(localhost_all);
- destination(local_logzilla);
- };
*注:配置中的相关参数需根据个人实际环境进行修改。
全世界都在找logzilla_v2.9.9o.tgz包,打包线上的包放上来(修复原先一些小bug)
下载文件 (已下载 1021 次)
参考文献: http://nms.gdd.net/index.php/LogZilla_Installation_Guide
如大家有什么疑问或感兴趣的话题可以通过weibo与我交流: http://t.qq.com/yorkoliu