Centos6.5
syslog-ng 3.25
mysql
1,yum install syslog-ng.x86_64
2,yum install mysql.x86_64 // 支持mysql 命令运行
3,mkfifo –m 777 /var/log/mysql.pipe // 创建通道并赋予权限
4, logsys-ng.conf // 修改配置文件
//源
source s_sys {
file ("/proc/kmsg" program_override("kernel: "));
unix-stream ("/dev/log");
internal();
# udp(ip(0.0.0.0) port(514));
};
//规则 用默认的,自己写也行
filter f_default { level(info..emerg) and
not (facility(mail)
or facility(authpriv)
or facility(cron)); };
// 传输目标
destination mysql {
program("mysql -h10.10.10.10 -uxxxxx -pxxxxx table < /var/log/mysql.pipe");
pipe("/var/log/mysql.pipe"
template("INSERT INTO w_sys_logs (host, facility, priority, level, tag,
datetime, program, msg) VALUES ( ‘$HOST‘, ‘$FACILITY‘, ‘$PRIORITY‘,
‘$LEVEL‘, ‘$TAG‘, ‘$YEAR-$MONTH-$DAY $HOUR:$MIN:$SEC‘, ‘$PRORAM‘,
‘$MSG‘ );n") template-escape(yes) ); };
// table 为 数据库名
// 消息组合
log { source(s_sys); filter(f_default);destination(mysql); };
// 创建数据库
DROP TABLE IF EXISTS `w_sys_logs`;
CREATE TABLE `w_sys_logs` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`host` varchar(32) DEFAULT NULL,
`facility` varchar(10) DEFAULT NULL,
`priority` varchar(10) DEFAULT NULL,
`level` varchar(10) DEFAULT NULL,
`tag` varchar(10) DEFAULT NULL,
`datetime` datetime DEFAULT NULL,
`program` varchar(15) DEFAULT NULL,
`msg` text,
PRIMARY KEY (`id`),
KEY `host` (`host`),
KEY `program` (`program`),
KEY `datetime` (`datetime`),
KEY `priority` (`priority`),
KEY `facility` (`facility`)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8;
转载请注明:http://8463390.blog.51cto.com/8453390/1911623
本文出自 “一刀在手 群魔退散” 博客,请务必保留此出处http://yi1hu.blog.51cto.com/8453390/1911623
原文地址:http://yi1hu.blog.51cto.com/8453390/1911623