25.2 配置使用基於mysql儲存日誌資訊

來源:互聯網
上載者:User

標籤:linux   rsyslog   mariadb   

配置環境:

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/86/CA/wKiom1fKv1yjUGw7AAB5GoJsMJA730.jpg" title="02.jpg" alt="wKiom1fKv1yjUGw7AAB5GoJsMJA730.jpg" />


1、準備好MySQL伺服器,建立使用者,授權對Syslog資料庫的全部存取權限

[[email protected] ~]# yum -y install mariadb-server

[[email protected] ~]# systemctl start mariadb.service 

[[email protected] ~]# mysql

MariaDB [(none)]> grant all on Syslog.* to  ‘syslog‘@‘192.168.1.%‘ identified by ‘syspass‘;

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> \q

[[email protected] ~]# vim /etc/my.cnf

在[mysqld_safe](10左右)前添加

skip_name_resolve=on

innodb_file_per_table=on

[[email protected] ~]# systemctl restart mariadb.service


2、安裝rsyslog-mysql程式包

[[email protected] ~]# yum -y install rsyslog-mysql  mysql

[[email protected] ~]# rpm -ql rsyslog-mysql

/lib64/rsyslog/ommysql.so

/usr/share/doc/rsyslog-mysql-5.8.10

/usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql


3、建立rsyslog-mysql依賴的資料庫

[[email protected] ~]# mysql -h 192.168.1.131 -usyslog -psyspass < /usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql


4、配置rsyslog使用ommysql模組

[[email protected] ~]# vim /etc/rsyslog.conf 

(1)在#### GLOBAL DIRECTIVES ####(約21)前添加

$ModLoad ommysql

(2)在#### RULES ####下修改日誌規則

格式:facility.priority     :ommysql:DBHOST,DB,DBUSER,USERPASS

如:

修改

*.info;mail.none;authpriv.none;cron.none                /var/log/messages

*.info;mail.none;authpriv.none;cron.none:ommysql:192.168.1.131,Syslog,syslog,syspass

[[email protected] ~]# service rsyslog restart


5、安裝服務測試


安裝vsftpd

[[email protected] ~]# yum -y install vsftpd

查看記錄檔

[[email protected] ~]# tail /var/log/messages 

發現沒有日誌記錄


查看mysqlLog Service器

[[email protected] ~]# mysql -h192.168.1.131 -usyslog -psyspass

mysql> use Syslog;

MariaDB [Syslog]> select count(*) from SystemEvents;                 

+----------+

| count(*) |

+----------+

|        3 |

+----------+

1 row in set (0.00 sec)

發現日誌已記錄到Log Service器


6、安裝loganalyzer

(1)配置webserver,支援php

[[email protected] ~]# yum -y install httpd php php-mysql php-gd

(2)安裝配置loganalyzer

[[email protected] ~]# tar xf loganalyzer-3.6.5.tar.gz 

[[email protected] ~]# mv loganalyzer-3.6.5/src/ /var/www/html/loganalyzer

[[email protected] ~]# cd !$

[[email protected] loganalyzer]# cp /root/loganalyzer-3.6.5/contrib/* .

[[email protected] loganalyzer]# chmod +x *.sh

[[email protected] loganalyzer]# ./configure.sh 

[[email protected] loganalyzer]# ./secure.sh

[[email protected] loganalyzer]# chmod 666 config.php


本文出自 “追夢” 部落格,請務必保留此出處http://sihua.blog.51cto.com/377227/1845989

25.2 配置使用基於mysql儲存日誌資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.