• loganalyzer 展示数据库中的日志


    1 实验目标:

    利用rsyslog日志服务,将收集的日志记录于MySQL中,通过loganalyzer 展示数据库中的日志

    2 环境准备

    三台主机:

    • 一台日志服务器,利用上一个案例实现,IP:192.168.100.100
    • 一台数据库服务器,利用上一个案例实现,IP:192.168.100.101
    • 一台当httpd+php 服务器,并安装loganalyzer展示web图形,IP:192.168.100.102
    • 在这里插入图片描述

    3 实现步骤

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

    安装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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    查看sql脚本文件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
    );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    将sql脚本复制到数据库服库

    [root@centos8 ~]#scp /usr/share/doc/rsyslog/mysql-createDB.sql 192.168.100.101:/root/
    
    • 1

    3.2 准备MySQL Server

    [root@centos8 ~]#yum install mysql-server
    #在mariadb数据库服务器上创建相关数据库和表,并授权rsyslog能连接至当前服务器
    [root@centos8 ~]#mysql -u 
    [root@centos8 ~]#mysql>source /root/mysql-createDB.sql
    [root@centos8 ~]#mysql>GRANT ALL ON Syslog.* TO 'rsyslog'@'192.168.100.%' IDENTIFIED 
    BY '123456';
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

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

    #配置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:192.168.100.101,Syslog,rsyslog,123456
    [root@centos8 ~]#systemctl restart rsyslog.service
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

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

    [root@centos8 ~]#yum -y install httpd php-fpm php-mysqlnd php-gd
    [root@centos8 ~]#systemctl enable --now httpd php-fpm
    
    • 1
    • 2

    3.5 在192.168.100.102主机上安装LogAnalyzer

    #从http://loganalyzer.adiscon.com/downloads/ 下载loganalyzer-4.1.13.tar.gz
    [root@centos8 ~]#tar xvf loganalyzer-4.1.10.tar.gz 
    [root@centos8 ~]#mv loganalyzer-4.1.13/src/ /var/www/html/log
    [root@centos8 ~]#touch /var/www/html/log/config.php
    [root@centos8 ~]#chmod 666 /var/www/html/log/config.php
    
    • 1
    • 2
    • 3
    • 4
    • 5

    3.6 基于 web 页面初始化

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

    在这里插入图片描述
    在这里插入图片描述

    3.7 测试

    可以通过可视化界面查看分析日志信息
    在这里插入图片描述

    3.8 安全加固

    [root@centos8 ~]#chmod 644 /var/www/html/log/config.php
    
    • 1
  • 相关阅读:
    【室友用一局王者荣耀的时间学会了用BI报表数据处理】
    python实现基于smtp发送邮件
    ThreadLocal优化
    站在自动装配角度浅析Spring和SpringBoot的区别
    Dify后端源码目录结构和蓝图
    [idekCTF 2022]Paywall - LFI+伪协议+filter_chain
    【ABAP】如何理解SAP中的CLIENT (客户端)
    算法leetcode|76. 最小覆盖子串(rust重拳出击)
    537、RabbitMQ详细入门教程系列 -【消费者Consumer(一)】 2022.08.31
    c++ SQLite 特别好用的库使用实例-查询(2)
  • 原文地址:https://blog.csdn.net/qq_43555873/article/details/128002009