日志

实验1:更换存放文件

[root@localhost ~]# vim /etc/ssh/sshd_config 
#SyslogFacility AUTHPRIV
SyslogFacility local0

[root@localhost ~]# vim /etc/rsyslog.conf
local0.*            /var/log/sshd.log

[root@localhost ~]# systemctl restart sshd rsyslog

[root@localhost ~]# tail -f /var/log/sshd.log 

实验2:日志存放在192.168.2.6的主机上test.log中

本机
[root@localhost ~]# vim /etc/rsyslog.conf
local0.*                        @@192.168.2.6
[root@localhost ~]# systemctl restart sshd rsyslog

网络主机
[root@localhost ~]# vim /etc/rsyslog.conf
$ModLoad imtcp
$InputTCPServerRun 514

local0.*                    /var/log/test.log

[root@localhost ~]# systemctl restart sshd rsyslog
[root@localhost ~]# tail -f /var/log/test.log

实验3:将rsyslog将日志记录于MySQL中


1、准备MySQL server(192.168.2.16)
[root@localhost ~]#yum -y install mariadb-server
[root@localhost ~]#systemctl start mariadb

2、在MySQL server 上授权rsyslog能连接过来
MariaDB [(none)]> grant all on Syslog.* to loguser@'192.168.2.%' identified by '123456';
Query OK, 0 rows affected (0.16 sec)

3、在rsyslog服务器上安装MySQL模块相关的程序包   (192.168.2.6)
[root@localhost ~]#yum -y install rsyslog-mysql

[root@localhost ~]#rpm -ql rsyslog-mysql
/usr/lib64/rsyslog/ommysql.so       #模块
/usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql

[root@localhost ~]#scp /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql 192.168.2.16:/data/     #将此库传到数据库服务器

4、在MySQL server 服务器上为rsyslog创建数据库及表
[root@localhost ~]#mysql -uroot -p < /data/mysql-createDB.sql 
Enter password: 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| Syslog             |

5、配置rsyslog将日志保存到MySQL中
[root@localhost ~]#vim /etc/rsyslog.conf
$ModLoad ommysql        #添加此行,加载ommysql.so
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

*.info;mail.none;authpriv.none;cron.none                :ommysql:192.168.2.16,Syslog,loguser,123456     #定义规则

[root@localhost ~]#systemctl restart rsyslog

实验4:基于实验3
通过loganalyzer展示数据库中的日志

1、准备一台主机amp组合  (192.168.2.26)
[root@localhost ~]#yum -y install httpd php php-mysql php-gd
[root@localhost ~]#systemctl start httpd    #启动服务

2、测试lamp环境搭建是否成功

3、安装LogAnalyser开源软件
[root@localhost ~]#wget http://download.adiscon.com/loganalyzer/loganalyzer-4.1.7.tar.gz

[root@localhost ~]#tar xvf loganalyzer-4.1.7.tar.gz -C /var/www/html/       #解压到主站目录
[root@localhost ~]#mv loganalyzer-4.1.7/src log
[root@localhost ~]#cd log
[root@localhost log]#touch config.php
[root@localhost log]#chmod 666 config.php

4、浏览器安装
http://192.168.2.6
填写信息主机大小写

5、安装完成后
[root@localhost log]#chmod 644 config.php       #修改权限







转载于:https://blog.51cto.com/14230743/2396002

你可能感兴趣的:(日志)