三、配置rsyslog或syslog-ng
rsyslog:
yum install -y rsyslog rsyslog-mysql
编辑/etc/rsyslog.conf
$ModLoad imudp.so $UDPServerRun 514 $ModLoad ommysql $template cacti_syslog,"INSERT INTO syslog_incoming(facility, priority, date, time, host, message) values (%syslogfacility%, %syslogpriority%, '%timereported:::date-mysql%', '%timereported:::date-mysql%', '%HOSTNAME%', '%msg%')", SQL *.* >localhost,syslog,cactiuser,cactifans.org;cacti_syslog在文件最后添加以上内容,然后重启rsyslog,并设置开机启动
chkconfig rsyslog on
service rsyslog restart
syslog-ng:
rpm -Uvh Fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum install -y syslog-ng
编辑/etc/syslog-ng/syslog-ng.conf
source net { udp(); }; destination d_mysql { pipe("/tmp/mysql.pipe" template("INSERT INTO syslog_incoming (host, facility, priority, date, time, message) VALUES ( '$HOST', '$FACILITY', '$PRIORITY', '$YEAR-$MONTH-$DAY', '$HOUR:$MIN:$SEC', '$MSG' );\n") template-escape(yes) ); }; log { source(net); destination(d_mysql); }; log { source(s_sys); destination(d_mysql); };在文件最后添加以上内容,然后编写一个脚本把syslog-ng接收到的数据写进mysql
新建bash /sbin/syslogtomysql
#!/bin/bash if [ ! -e /tmp/mysql.pipe ]; then mkfifo /tmp/mysql.pipe fi while [ -e /tmp/mysql.pipe ] do mysql -u cactiuser --password=cactifans.org syslog < /tmp/mysql.pipe done保存退出,
chmod +x /sbin/syslogtomysql
nohup /sbin/syslogtomysql &
echo "nohup /sbin/syslogtomysql &" >> /etc/rc.local
/etc/init.d/syslog-ng start
chkconfig syslog-ng on