實現流程:Cacti服務器安裝syslog-ng爲中央日誌服務器,Cacti經過syslog插件展現,從服務器經過網絡將日誌實時發送到中央日誌服務器。
Cacti下syslog插件安裝:
#http://www.haiyun.me
cd /home/wwwroot/cacti/plugins/
wget -O syslog.tar.gz http://docs.cacti.net/_media/plugin:syslog-v1.22-2.tgz
tar zxvf syslog.tar.gzphp
新建syslog數據庫並受權:
mysql -u root -p
create database syslog;
grant all privileges on syslog.* to cacti@localhost;mysql
導入syslog數據庫:
mysql -u root -p syslog < syslog/syslog.sqlweb
修改syslog插件配置文件,而後經過web界面安裝syslog插件,略過。
vim syslog/config.php
$use_cacti_db = false; #不使用cacti默認數據庫
#定義syslog數據庫信息
if (!$use_cacti_db) {
$syslogdb_type = 'mysql';
$syslogdb_default = 'syslog';
$syslogdb_hostname = 'localhost';
$syslogdb_username = 'cactiuser';
$syslogdb_password = 'password';
$syslogdb_port = 3306;sql
Cacti服務器端安裝syslog-ng服務端,yum安裝需先安裝epel源。
yum -y install syslog-ng
service syslog stop
chkconfig syslog off
service syslog-ng start
chkconfig syslog-ng on數據庫
編輯syslog-ng配置文件添加如下內容:
vim /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); };vim
新建日誌數據庫導入腳本:
vim /etc/syslog-ng/syslog.sh
#!/bin/bash
if [ ! -e /tmp/mysql.pipe ]; then
mkfifo /tmp/mysql.pipe
fi
while [ -e /tmp/mysql.pipe ]
do
mysql -u root --password=passwd syslog < /tmp/mysql.pipe
donebash
啓動腳本並配置開機啓動:
sh /etc/syslog-ng/syslog.sh &
echo "sh /etc/syslog-ng/syslog.sh" >> /etc/rc.local服務器
從服務器配置syslog將日誌發送到syslog-ng服務器:
echo "*.* @server" >> /etc/syslog.conf
/etc/init.d/syslog restart
網絡