Centos6.5
syslog-ng 3.25
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 -h20.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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。