將日誌記錄在是mysql中,實現loganalyzer

來源:互聯網
上載者:User

標籤:mysql   日誌   報表   

三台主機

    192.168.191.106(代號106)   產生日誌    

    192.168.191.107(代號107)   實現存放日誌的資料庫  

    192.168.191.173(代號173)   實現日誌報表  

1、實現rsyslog將日誌記錄於MySQL中 

(1)在107上:

        yum install mariadb-server

        systemctl start mariadb

        mysql_secure_installation 執行安全指令碼 

(2)在106上:yum install rsyslog-mysql

 rpm -ql rsyslog-mysql

 scp /usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql 192.168.191.107:/root

(3)在107上運行指令碼

  mysql-uroot -pcentos < createDB.sql    或者登陸資料庫,執行指令碼

  grantall on Syslog.* to ‘loguser‘ @ ‘192.168.191.106‘ identified by ‘centos‘

(4)在106上串連測試

    mysql -uloguser -pcentos -h‘192.168.191.107‘                  

(5)支援日誌

   在106上 vim /etc/rsyslog.conf

    添加該行:        

        $ModLoad ommysql  

    修改這一行:

    *.info;mail.none;authpriv.none;cron.none  :ommysql:192.168.191.107,Syslog,loguser,centos 

  重啟服務:service  rsyslog restart

(6)在107上

          mysql -uroot -pcentos

          show databases;

          useSyslog;

          selectcount(*)from SystemEvents;查看有幾條記錄

          from SystemEvents \G;  查看記錄詳細資料

    

    650) this.width=650;" src="https://s3.51cto.com/oss/201710/24/c27cb867558246d156581806eed51d6f.png" style="float:none;" title="1.png" alt="c27cb867558246d156581806eed51d6f.png" />


(7)測試:在106上組建記錄檔,logger “This is a test log”

  在107查看

             650) this.width=650;" src="https://s3.51cto.com/oss/201710/24/d100d765fc2b78cc127801c3dac48e09.png" title="2.png" style="float:none;" alt="d100d765fc2b78cc127801c3dac48e09.png" />

        select count * from SystemEvents \G;

    650) this.width=650;" src="https://s4.51cto.com/oss/201710/24/51c405e8f07d54afdfd17f97e5024f2e.png" title="3.png" style="float:none;" alt="51c405e8f07d54afdfd17f97e5024f2e.png" />  

   可以看到確實多了一條記錄

2、實現通過loganalyzer展示資料庫中的日誌

    1>在173上:實現lap

        (1)安裝包   

           httpd預設安裝過了

           yum install php  php-mysql  php-gd  

        (2)service httpd  start 啟動服務

        (3)測試

           vim /var/www/html/index.php           

<?php          phpinfo();?>

    在瀏覽器訪問http://192.168.191.173/index.php  顯示下面資訊則實現lap

      650) this.width=650;" src="https://s3.51cto.com/oss/201710/24/259a152130a96045a1109df349bd13d3.png" title="4.png" alt="259a152130a96045a1109df349bd13d3.png" />  

  2>在173上實現loganalyzer

       (1)rz 匯入檔案  loganalyzer-4.1.5.gz

          tar xvf loganalyzer-4.1.5.gz

       (2) cd loganalyzer-4.1.5

          mv src /var/www/html/log

       (3)cd /var/www/html/log

            touch config.php

            chmod 666 config.php

      或者在該目錄下 執行該指令碼 configure.sh

       650) this.width=650;" src="https://s3.51cto.com/oss/201710/24/f4b82513df0bb4a665759e28c00f708d.png" title="6.png" alt="f4b82513df0bb4a665759e28c00f708d.png" />

       service httpd  restart  重啟服務

(4)瀏覽器訪問http:// 192.168.191.173/log

      650) this.width=650;" src="https://s3.51cto.com/oss/201710/25/43bec6b5c0aa38fb0c1611dde4122136.png" title="2.png" alt="43bec6b5c0aa38fb0c1611dde4122136.png" />

     650) this.width=650;" src="https://s4.51cto.com/oss/201710/24/7b3b0a1da23800949574daa2a1e08596.png" title="7.png" alt="7b3b0a1da23800949574daa2a1e08596.png" />

      其他步預設next;下面一頁有固定格式

     650) this.width=650;" src="https://s2.51cto.com/oss/201710/24/808687aac637b56de058a0276e193acc.png" title="213234.png" alt="808687aac637b56de058a0276e193acc.png" /> 

(5)成功,點擊產生想要的報表

     650) this.width=650;" src="https://s1.51cto.com/oss/201710/25/d4f8796b3bf073faa8f63c4c66aa3dd9.png" title="1.png" alt="d4f8796b3bf073faa8f63c4c66aa3dd9.png" /> 

本文出自 “Linux 學習記錄” 部落格,請務必保留此出處http://guanm.blog.51cto.com/13126952/1976131

將日誌記錄在是mysql中,實現loganalyzer

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.