编辑 vim /etc/rsyslog.conf文件,如下:
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
$WorkDirectory /var/lib/rsyslog
$template myformat,“%TIMESTAMP:1:10:date-rfc3339% %TIMESTAMP:19:12:date-rfc3339% %hostname% %syslogtag%%msg%\n”
$ActionFileDefaultTemplate myformat
$IncludeConfig /etc/rsyslog.d/.conf
$OmitLocalLogging on
$IMJournalStateFile imjournal.state
$Modload ommysql
.info;mail.none;authpriv.none;cron.none /var/log/messages
authpriv. /var/log/secure
mail. -/var/log/maillog
cron.* /var/log/cron
.emerg :omusrmsg:
uucp,news.crit /var/log/spooler
local1.* /var/log/xcoder.debug
local7.* /var/log/boot.log
local0.* /var/log/xcoder.info
local0.* :ommysql:数据库ip,数据库名称,数据库用户名,数据库密码
重启服务
systemctl restart rsyslog.service
注释:local0.*也就是把日志 /var/log/xcoder.info写入到数据库中