1.我用Mariadb(Mysql),所以先给rsyslog安装mysql支持。
[root@test ~]# dnf install rsyslog-mysql
2.在mysql里导入rsyslog默认使用的数据库信息(库名是Syslog),并添加rsyslog需要的mysql用户:
[root@test ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3127
Server version: 10.3.11-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> source /usr/share/doc/rsyslog/mysql-createDB.sql
MariaDB [(none)]> grant all privileges on Syslog.* to 'sysloguser'@'localhost' identified by '125456';
MariaDB [(none)]> flush privileges;
3.修改/etc/rsyslog.conf文件,在#### MODULES ####的那一段最后添加mysql支持:
# mysql
$ModLoad ommysql
然后在后面添加采集条件,把对应的日志添加到数据库:
#关于条件和输出相关其他设置请参阅rsyslog官方文档,我只说我这里的
#条件->日志里hostname等于192.168.10.100的 :使用mysql:mysql主机,库名,用户名,密码
:hostname,isequal,"192.168.10.100" :ommysql:localhost,Syslog,sysloguser,125456
4.重启rsyslog,如果有日志,就会在刚才的数据库Syslog里了。