Centos6.5syslog-ng 3.25Mysql1,yum install syslog-ng.x86_64 2,yum install mysql.x86_64 &
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
--结束END--
本文标题: 将syslog ng日志写入MySQL(远程)数据库
本文链接: https://lsjlt.com/news/47635.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0