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

环境准备

三台主机
一台日志服务器,利用上一个案例实现,IP:192.168.39.7,
一台数据库服务器,利用上一个案例实现,IP:192.168.39.27,
一台当httpd+php 服务器,并安装loganalyzer展示web图形,IP:192.168.39.77 日志服务器工具 loganalyzer-4.1.8.tar.gz

准备服务器:

# 日志服务器
[root@centos7 ~]$hostname rsyslog
[root@centos7 ~]$exit
[root@rsyslog ~]$
# 数据库服务器
[root@centos7 ~]$hostname mysql
[root@centos7 ~]$exit
[root@mysql ~]$
# websrv服务器
[root@centos ~]# hostname websrv
[root@centos ~]# exit
[root@websrv ~]$

日志服务器:

  1. 在rsyslog服务器上安装连接mysql模块相关的程序包
[root@rsyslog ~]$yum install rsyslog-mysql -y
  1. 找到sql脚本发送到数据库
# 下载辅助软件查找
[root@rsyslog ~]$yum install mlocate
[root@rsyslog ~]$updatedb # 更新数据库信息
[root@rsyslog ~]$locate mysql-createDB.sql # 使用locatedb查找脚本文件存放路径
/usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql [root@rsyslog ~]$cat /usr/share/doc/rsyslog-8.24.0/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@rsyslog ~]$scp /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql 192.168.39.27:/root # 发送到数据库服务器
The authenticity of host '192.168.39.27 (192.168.39.27)' can't be established.
ECDSA key fingerprint is SHA256:XVNFzEbN3eaCzTwYrlQg2SzHZXHbd0dS0YKLuIOXVr0.
ECDSA key fingerprint is MD5:df:4d:86:ba:0c:e6:c1:a2:6c:45:71:e9:ac:ea:1d:a5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.39.27' (ECDSA) to the list of known hosts.
root@192.168.39.27's password:
mysql-createDB.sql 100% 1046 588.1KB/s 00:00
  1. 修改配置文件启动服务模块并且写如数据库信息(用于给数据库服务器发送日志信息)
# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad ommysql # 添加这一行 # Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
*.info;mail.none;authpriv.none;cron.none :ommysql:192.168.39.27,Syslog,syslog,taotaobao
#配置rsyslog将日志保存到mysql中
[root@centos8 ~]#vim /etc/rsyslog.conf
####MODULES####
#在 MODULES 语言下面,如果是 CentOS 8 加下面行
module(load="ommysql")
#在 MODULES 语言下面,如果是 CentOS 7,6 加下面行
$ModLoad ommysql

数据库服务器:

  1. 安装数据库
[root@mysql ~]$yum install mariadb-server -y

[root@mysql ~]$systemctl start mariadb.service
  1. 执行考过来的脚本
[root@mysql ~]$mysql <
anaconda-ks.cfg .cshrc .tcshrc
.bash_history ifcfg-eth0 .viminfo
.bash_logout init_env_191113.sh .vimrc
.bash_profile mysql-createDB.sql
.bashrc .pki/
[root@mysql ~]$mysql < mysql-createDB.sql # 直接导入数据库
  1. 创建Syslog库使用的账号
[root@mysql ~]$mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-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)]> grant all on Syslog.* to syslog@'192.168.39.%' identified by 'taotaobao'; # 注意这里的数据库名要对应执行的sql脚本里的数据库名。
Query OK, 0 rows affected (0.00 sec)

测试日志服务器和数据库是否连接:

  • 数据库端查看Syslog库没启动服务之前是空的
MariaDB [Syslog]> show tables;
+------------------------+
| Tables_in_Syslog |
+------------------------+
| SystemEvents |
| SystemEventsProperties |
+------------------------+
2 rows in set (0.00 sec) MariaDB [Syslog]> MariaDB [Syslog]> SELECT COUNT(*) FROM SystemEvents;
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
  • 启动rsyslog服务
[root@rsyslog ~]$systemctl restart rsyslog.service

[root@rsyslog ~]$logger "this is a test log" # 日志服务器触发日志(logger触发日志命令)
  • 查看数据库是否有数据(可以多测试几遍)
MariaDB [Syslog]> SELECT COUNT(*) FROM SystemEvents;
+----------+
| COUNT(*) |
+----------+
| 8 |
+----------+
1 row in set (0.00 sec)

websrv服务器端:

  1. 解压缩工具
[root@websrv ~]# ll
-rw-r--r-- 1 root root 2943754 Oct 10 13:04 loganalyzer-4.1.8.tar.gz # web界面日志服务工具包
[root@websrv ~]# tar xvf loganalyzer-4.1.8.tar.gz
  1. 安装需要的服务实现LAMP架构
# 注意这里的php版本一定要是在5.6版本相同或以上要不这个软件不支持
[root@websrv ~]# yum install httpd php56-php-fpm.x86_64 php56-php-mysqlnd.x86_64 -y
  1. 把loganalyzer需要的目录切到网站目录下
[root@websrv loganalyzer-4.1.8]# ll
total 100
drwxrwxr-x 13 root root 4096 Sep 26 23:41 src
-rw-rw-r-- 1 root root 48571 Sep 26 23:41 ChangeLog
drwxrwxr-x 2 root root 43 Sep 26 23:41 contrib
-rw-rw-r-- 1 root root 35497 Sep 26 23:41 COPYING
drwxrwxr-x 3 root root 258 Sep 26 23:41 doc
-rw-rw-r-- 1 root root 8449 Sep 26 23:41 INSTALL [root@websrv loganalyzer-4.1.8]# mv src/ /var/www/html/log # 切到网站目录下 [root@websrv loganalyzer-4.1.8]# ll /var/www/html/
total 4
drwxrwxr-x 13 root root 4096 Sep 26 23:41 log # 修改所有者为apache
[root@websrv loganalyzer-4.1.8]# cd /var/www/html/
[root@websrv html]# chown -R apache.apache log/
  1. 修改httpd配置文件支持php-fpm
# 添加index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule> # 找到这个模块位置,添加中间三行内容。
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
</IfModule>
  1. 创建调用模块文件(或者理解为反向代理)
[root@websrv html]# vim /etc/httpd/conf.d/fcgi.conf
Directoryindex index.php
Proxyrequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
第4、5这两项的配置在centos7上要加。centos8是默认配置好的不用修改。
  1. web界面测试

  • 进行检测

  • 这里如果错了可能会显示没有用于写的文件

  • 解决方法(是缺少这个文件导致的)
[root@websrv html]# cd log/
[root@websrv log]# pwd
/var/www/html/log
[root@websrv log]# touch config.php # 创建这个文件
[root@websrv log]# chmod 666 config.php # 给这个文件所有人可读和可写权限(根据工作需求更改)
  • 这些信息是最后显示的日志格式是什么样的

  • 填写数据库的信息

  • 查看添加的表名
[root@centos7 ~]$mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.60-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)]> use Syslog;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [Syslog]> show tables;
+------------------------+
| Tables_in_Syslog |
+------------------------+
| SystemEvents | # 这个表是作为存储日志信息使用的
| SystemEventsProperties |
+------------------------+
2 rows in set (0.00 sec)
  • 成功



  • 查看报告书界面(但是没有饼状图不清晰)

[root@websrv html]# yum install php56-php-gd.x86_64 -y  # 支持画饼状图的包
[root@websrv html]# systemctl restart httpd.service php56-php-fpm.service # 重启服务
  • 刷新web界面(这样就会产生比较清晰的饼状图)

通过 loganalyzer 展示数据库中的系统日志的更多相关文章

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

    一.安装mysql # yum -y install mariadb-server # systemctl enable --now mariadb && systemctl stat ...

  2. jsp案例--展示数据库中的数据

    一.什么是jsp? JAVA SERVER PAGES java的动态网页,servlet用来获取数据处理业务,擅长处理与java代码有关的内容.jsp展示数据,擅长处理与html有关的内容. 二.如 ...

  3. Python Django CMDB项目实战之-2创建APP、建模(models.py)、数据库同步、高级URL、前端页面展示数据库中数据

    基于之前的项目代码来编写 Python Django CMDB项目实战之-1如何开启一个Django-并设置base页index页文章页面 现在我们修改一个文章列表是从数据库中获取数据, 下面我们就需 ...

  4. django开发博客01-页面展示数据库中的数据

    1.首先在views.py中引入models.py的 Category这个类 然后在函数中(blog)写执行逻辑 categorys 返回的对象是是一个list"<QuerySet [ ...

  5. Linux学习-通过loganalyzer展示MySQL中rsyslog日志

    一.实验环境 系统:CentOS7.6 软件包:apache,php,mariadb-server (都是基于光盘yum源) 源码包:loganalyzer-4.1.7.tar.gz (http:// ...

  6. C#-WinForm-ListView-表格式展示数据、如何将数据库中的数据展示到ListView中、如何对选中的项进行修改

    在展示数据库中不知道数量的数据时怎么展示最好呢?--表格 ListView - 表格形式展示数据 ListView 常用属性 HeaderStyle - "详细信息"视图中列标头的 ...

  7. 使用js批量选中功能实现更改数据库中的status状态值(批量展示)

    我们在开发项目的时候经常会在后台管理时用到批量展示功能来动态的修改数据库的值.下面以修改数据库的status状态值来实现批量展示功能.批量选中功能引用js来实现.前端html代码: <table ...

  8. mysql 从数据库中获取多条记录,二维展示数据

    展示要求: 客户/日期 2017-10-16 1017-10-17 2017-10-18 客户1       客户2       数据库中数据: 解决办法: 1.新建一个实体类:客户名称.客户数据(A ...

  9. 将数据库中的内容展示出来并将某些value值转换成汉字

    1.将数据库中的内容展示出来 前台代码未做改变,刚开始未显示的原因是因为 data-field 跟数据库不一样data-field 需要跟数据库中的一样才可以 2.将某些value值转换成汉字 在li ...

随机推荐

  1. Floyd && Dijkstra +邻接表 +链式前向星(真题讲解来源:城市路)

    1381:城市路(Dijkstra) 时间限制: 1000 ms         内存限制: 65536 KB提交数: 4066     通过数: 1163 [题目描述] 罗老师被邀请参加一个舞会,是 ...

  2. libnl的移植

    libnl简介 libnl是为了方便应用程序使用netlink接口而开发的一个库.这个库为原始netlink消息传递以及不同的netlink,family专用接口提供了一个统一的接口.libnl2.0 ...

  3. iOS13暂时关闭黑暗模式+应用内状态栏无法显示问题解决办法

    现象: iOS13黑暗模式开启后,app显示会出现很多意外显示情况.暂时屏蔽是最好的选择.当开启黑暗模式,且在项目的target对应的info.plist中添加以下设置时(禁用黑暗模式): <k ...

  4. 区块链学习笔记:D02 区块链的技术发展历史和趋势

    对于区块链的技术发展历史,其实在我的印象中也就对比特币有所了解,也听过什么火币之类的玩意,但是具体是什么.怎么运作的就不清楚了... 这次的内容首先是讲解了区块链的技术演进,一张图一目了然,虽然里面涉 ...

  5. 《手把手教你》系列进阶篇之1-python+ selenium自动化测试 - python基础扫盲(详细教程)

    1. 简介 如果你从一开始就跟着宏哥看博客文章到这里,基础篇和练习篇的文章.如果你认真看过,并且手动去敲过每一篇的脚本代码,那边恭喜你,至少说你算真正会利用Python+Selenium编写自动化脚本 ...

  6. 数据挖掘算法(三)--logistic回归

    数据挖掘算法学习笔记汇总 数据挖掘算法(一)–K近邻算法 (KNN) 数据挖掘算法(二)–决策树 数据挖掘算法(三)–logistic回归 在介绍logistic回归之前先复习几个基础知识点,有助于后 ...

  7. Zookeeper Watcher接口

    在ZooKeeper中,接口类Watcher用于表示一个标准的事件处理器,其定义了事件通知相关的逻辑,包含KeeperState和EventType两个枚举类,分别代表了通知状态和事件类型,同时定义了 ...

  8. 第3节:Java基础 - 必知必会(上)

    第3节:Java基础 - 必知必会(上) 本篇是基础篇的第一小节,我们从最基础的java知识点开始学习.本节涉及的知识点包括面向对象的三大特征:封装,继承和多态,并且对常见且容易混淆的重要概念覆盖和重 ...

  9. BZOJ 3265 志愿者招募加强版(单纯形)

    3265: 志愿者招募加强版 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 848  Solved: 436[Submit][Status][Disc ...

  10. 洛谷 题解 P1025 【数的划分】

    将n个小球放到k个盒子中的情况总数 = (a)至少有一个盒子只有一个小球的情况数 + (b)没有一个盒子只有一个小球的情况数 这样写出表达式: a.因为盒子不加区分,那么=情况数与"将n-1 ...