rsyslog日志信息转存到远程mariadb服务器
实验配置
-
centos 7.6 mini 192.168.38.7
实现rsyslog服务
-
centos 7.6 mini 192.168.38.17
实现mariadb服务
实验步骤
38.17上的操作
1、安装mariadb并启动
yum install -y mariadb-server
systemctl enable --now mariadb
2、创建rsyslog服务连接账号
mysql -uroot -p123456 -e 'grant all on Syslog.* to rsyslog@"192.168.38.%" identified by "123456";'
38.7上的操作
1、安装rsyslog连接mysql模块
yum install -y rsyslog-mysql
2、远程连接mariadb服务器创建Syslog数据库
mysql -h192.168.38.17 -ursyslog -p123456 < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql;
3、修改rsyslog配置文件
vi /etc/rsyslog.conf
#### MODULES ####
添加下面一行数据
$ModLoad ommysql
#### RULES ####
添加下面一行数据
*.info;mail.none;authpriv.none;cron.none :ommysql:192.168.38.17,Syslog,rsy
slog,123456
4、重新启动rsyslog服务
systemctl restart rsyslog
5、生成一条测试日志
logger "This is a test log"
6、查看本地日志文件是否记录
tail -5 /var/log/messages
Oct 11 19:37:09 7_07 systemd: Stopped System Logging Service.
Oct 11 19:37:09 7_07 systemd: Starting System Logging Service...
Oct 11 19:37:09 7_07 rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-38.el7" x-pid="6581" x-info="http://www.rsyslog.com"] start
Oct 11 19:37:09 7_07 systemd: Started System Logging Service.
Oct 11 19:38:12 7_07 root: This is a test log
7、查看远程数据库是否记录
mysql -h192.168.38.17 -ursyslog -p123456 -e'select * from Syslog.SystemEvents\G;'
省略之前内容....
*************************** 7. row ***************************
ID: 7
CustomerID: NULL
ReceivedAt: 2019-10-11 19:38:12
DeviceReportedTime: 2019-10-11 19:38:12
Facility: 1
Priority: 5
FromHost: 7_07
Message: This is a test log
NTSeverity: NULL
Importance: NULL
EventSource: NULL
EventUser: NULL
EventCategory: NULL
EventID: NULL
EventBinaryData: NULL
MaxAvailable: NULL
CurrUsage: NULL
MinUsage: NULL
MaxUsage: NULL
InfoUnitID: 1
SysLogTag: root:
EventLogType: NULL
GenericFileName: NULL
SystemID: NULL
实现loganalyzer查看远程数据库存储的日志信息
实验前提
- 实现rsyslog日志信息转存到远程mariadb服务器
实验步骤
在38.7中的操作
1、安装相关软件
yum install -y httpd php php-mysql php-gd wget
2、下载loganalyzer-4.1.5
wget http://download.adiscon.com/loganalyzer/loganalyzer-4.1.5.tar.gz
3、解压并移动到httpd目录下
tar xf loganalyzer-4.1.5.tar.gz
cp -a loganalyzer/src/ /var/www/html/loganalyzer
4、创建loganalyzer配置文件
cd /var/www/html/loganalyzer/
touch /var/www/html/loganalyzerconfig.php
chmod 666 /var/www/html/loganalyzerconfig.php # 修改权限使其能根据用户配置生成配置文件
5、启动httpd服务
systemctl enable --now httpd
6、通过网页生成配置文件
http://192.168.38.7/loganalyzer
根据提示填写相关信息
...
第七步信息
Source Type MYSQL Native
Database Host 192.168.38.17
Database Name Syslog
Database Tablename SystemEvents (注意大小写,它写错了)
Database User rsyslog
Database Password 123456
7、完成后将config.php权限还原
chmod 644 /var/www/html/loganalyzerconfig.php