實驗1:更換存放文件php
[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中html
本機 [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中mysql
一、準備MySQL server(192.168.2.16) [root@localhost ~]#yum -y install mariadb-server [root@localhost ~]#systemctl start mariadb 二、在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) 三、在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/ #將此庫傳到數據庫服務器 四、在MySQL server 服務器上爲rsyslog建立數據庫及表 [root@localhost ~]#mysql -uroot -p < /data/mysql-createDB.sql Enter password: MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | Syslog | 五、配置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展現數據庫中的日誌sql
一、準備一臺主機amp組合 (192.168.2.26) [root@localhost ~]#yum -y install httpd php php-mysql php-gd [root@localhost ~]#systemctl start httpd #啓動服務 二、測試lamp環境搭建是否成功 三、安裝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 四、瀏覽器安裝 http://192.168.2.6 填寫信息主機大小寫 五、安裝完成後 [root@localhost log]#chmod 644 config.php #修改權限