centos8 安装配置rsyslog + LogAnalyzer + mysql

centos8 安装配置rsyslog + LogAnalyzer + mysql

在这里插入图片描述

模拟三台主机
一台rsyslog日志服务器,IP:10.0.0.168
一台mysql数据库服务器,IP:10.0.0.178
一台当httpd+php 服务器,并安装loganalyzer展示web图形,IP:10.0.0.188

1、在rsyslog服务器上安装连接mysql模块相关的程序包

[root@centos8mn ~]#yum install rsyslog-mysql -y

[root@centos8mn ~]#systemctl enable --now rsyslog.service

#查看sql脚本文件内容
[root@centos8mn ~]#cat /usr/share/doc/rsyslog/mysql-createDB.sql
CREATE DATABASE Syslog;
USE Syslog;
CREATE TABLE SystemEvents
(
        ID int unsigned not null auto_increment primary key,
        CustomerID bigint,
        ReceivedAt datetime NULL,
        DeviceReportedTime datetime NULL,
        Facility smallint NULL,
        Priority smallint NULL,
        FromHost varchar(60) NULL,
        Message text,
        NTSeverity int NULL,
        Importance int NULL,
        EventSource varchar(60),
        EventUser varchar(60) NULL,
        EventCategory int NULL,
        EventID int NULL,
        EventBinaryData text NULL,
        MaxAvailable int NULL,
        CurrUsage int NULL,
        MinUsage int NULL,
        MaxUsage int NULL,
        InfoUnitID int NULL ,
        SysLogTag varchar(60),
        EventLogType varchar(60),
        GenericFileName VarChar(60),
        SystemID int NULL
);

CREATE TABLE SystemEventsProperties
(
        ID int unsigned not null auto_increment primary key,
        SystemEventID int NULL ,
        ParamName varchar(255) NULL ,
        ParamValue text NULL
);

[root@centos8mn ~]#scp /usr/share/doc/rsyslog/mysql-createDB.sql 10.0.0.178:/data

2、准备MySQL Server

[root@centos8mn ~]#yum -y install mariadb-server

[root@centos8mn ~]#systemctl enable --now mariadb

[root@centos8mn ~]#mysql

MariaDB [(none)]> source /data/mysql-createDB.sql
Query OK, 1 row affected (0.000 sec)

Database changed
Query OK, 0 rows affected (0.003 sec)

Query OK, 0 rows affected (0.005 sec)

MariaDB [Syslog]> GRANT ALL ON Syslog.* TO 'rsyslog'@'10.0.0.%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.000 sec)

3、配置日志服务器将日志发送至指定数据库

[root@centos8mn ~]#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.178,Syslog,rsyslog,123456

[root@centos8mn ~]#systemctl restart rsyslog.service

4、测试

#在日志服务器上生成日志
[root@centos8mn ~]#logger "this is a test log"
#在数据库上查询到上面的测试日志
mysql>SELECT COUNT(*) FROM SystemEvents

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

在10.0.0.188主机上安装httpd, php和相关软件包

[root@centos8mn ~]#yum -y install httpd php-fpm php-mysqlnd php-gd
[root@centos8mn~]#systemctl enable --now httpd php-fpm

#从http://loganalyzer.adiscon.com/downloads/ 下载loganalyzer-4.1.12.tar.gz

[root@centos8mn ~]#tar xvf loganalyzer-4.1.12.tar.gz
[root@centos8mn ~]#mv loganalyzer-4.1.12/src/ /var/www/html/log
[root@centos8mn ~]#touch /var/www/html/log/config.php
[root@centos8mn ~]#chmod 666 /var/www/html/log/config.php

6、基于 web 页面初始化

访问http://10.0.0.188/log 实现初始化
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值