通过loganalyzer展示数据库中的日志

通过loganalyzer展示数据库中的日志

loganalyzer是用 php 语言实现的日志管理系统,可将MySQL数据库的日志用丰富的WEB方式进行展示
官网:https://loganalyzer.adiscon.com

三台主机
一台日志服务器,利用上一个案例实现,IP:10.0.0.160,
一台数据库服务器,利用上一个案例实现,IP:10.0.0.170
一台当httpd+php 服务器,并安装loganalyzer展示web图形,IP:10.0.0.150

#在10.0.0.160 rsyslog服务器上安装连接mysql模块相关的程序包
[root@centos8 ~]#yum install rsyslog-mysql
[root@centos8 ~]#rpm -ql rsyslog-mysql
/usr/lib/.build-id
/usr/lib/.build-id/d7
/usr/lib/.build-id/d7/77fc839aa07e92f0a8858cf3f122996436c7df
/usr/lib64/rsyslog/ommysql.so
/usr/share/doc/rsyslog/mysql-createDB.sql
#查看sql脚本文件内容
[root@centos8 ~]#cat /usr/share/doc/rsyslog/mysql-createDB.sql
#将sql脚本复制到数据库服库上
[root@centos8 ~]#scp /usr/share/doc/rsyslog/mysql-createDB.sql 10.0.0.170:/data

#10.0.0.170准备MySQL Server
[root@centos8 ~]#yum install mariadb-server
#在mariadb数据库服务器上创建相关数据库和表,并授权rsyslog能连接至当前服务器
[root@centos8 ~]#systemctl --now enable mariadb
[root@centos8 ~]#mysql 
MariaDB [(none)]> source /data/mysql-createDB.sql
MariaDB [Syslog]> GRANT ALL ON Syslog.* TO 'rsyslog'@'10.0.0.%' IDENTIFIED BY '123456';
MariaDB [Syslog]> flush privileges;

#10.0.0.160上配置日志服务器将日志发送至指定数据库
#配置rsyslog将日志保存到mysql中
[root@centos8 ~]#vim /etc/rsyslog.conf
#
####MODULES####
#在 MODULES 语言下面,如果是 CentOS 8 加下面行
module(load="ommysql") 
#在 MODULES 语言下面,如果是 CentOS 7,6 加下面行
$ModLoad ommysql 
#在RULES语句块加下面行的格式
#facility.priority :ommysql:DBHOST,DBNAME,DBUSER, PASSWORD 
*.info :ommysql:10.0.0.170,Syslog,rsyslog,123456
[root@centos8 ~]#systemctl restart rsyslog

#在日志服务器上生成日志
[root@centos8 ~]#logger "this is a test log"
#在数据库上查询到上面的测试日志
MariaDB [Syslog]> SELECT * FROM SystemEvents\G;


#在10.0.0.150主机上安装httpd, php和相关软件包
[root@centos8 ~]#yum -y install httpd php-fpm php-mysqlnd php-gd
[root@centos8 ~]#systemctl enable --now httpd php-fpm
#从http://loganalyzer.adiscon.com/downloads/ 下载loganalyzer-4.1.12.tar.gz
[root@centos8 ~]#tar xvf loganalyzer-4.1.12.tar.gz 
[root@centos8 ~]#mv loganalyzer-4.1.12/src/ /var/www/html/log
[root@centos8 ~]#touch /var/www/html/log/config.php 
[root@centos8 ~]#chmod 666 /var/www/html/log/config.php
#删除config.php,重新创建可以重新配置初始化
访问http://10.0.0.150/log 实现初始化
选择:MySQL Native, Syslog Fields, Monitorware
#注意数据库名,特别是表明默认的大小写不对,应该是:SystemEvents

#安全加强
[root@centos8 ~]#chmod 644 /var/www/html/log/config.php
posted @ 2021-11-16 22:35  小糊涂90  阅读(34)  评论(0编辑  收藏  举报