Get the App
SLTechnology News&Howtos  ›  Database  › 

Write syslog ng logs to the MySQL (remote) database

Shulou Source: shulou.com Published: 2022-06-01 06:10:49 11月06日 Update

Centos6.5

Syslog-ng 3.25

Mysql

1,yum install syslog-ng.x86_64

2Jing yum install mysql.x86_64 / / supports mysql command to run

3Mkfifo-m 777 / var/log/mysql.pipe / / create a channel and grant permissions

4, logsys-ng.conf / / modify the configuration file

/ / Source

Source s_sys {

File ("/ proc/kmsg" program_override ("kernel:"))

Unix-stream ("/ dev/log")

Internal ()

# udp (ip (0.0.0.0) port (514)

}

/ / use the default rules, or you can write them yourself

Filter f_default {level (info..emerg) and

Not (facility (mail))

Or facility (authpriv)

Or facility (cron);}

/ / Transmission destination

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 is the database name

/ / message combination

Log {source (s_sys); filter (f_default); destination (mysql);}

/ / create a database

DROP TABLE IF EXISTS `wpragsys _ logs`

CREATE TABLE `wpragsys _ logs` (

`id` bigint (20) unsigned NOT NULL AUTO_INCREMENT

`host` varchar (32) DEFAULT NULL

`roomy` 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 `roomy` (`roomy`)

) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8

For reprint, please indicate: http://8463390.blog.51cto.com/8453390/1911623

Tags: Data database commands files permissions messages targets rules channels transport support combination run configuration log Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker OPPO Reno Shulou Technology MariaDB