標籤:rsyslog 中文 亂碼 loganalyzer ip
因為看見許多朋友也都遇到過我這種情況,所以拿出來供大家參考下,我用的loganalyzer版本是Installed version: 3.6.5
這裡先貼下:650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/6C/0F/wKioL1U_Hp_SHww0AAcCKK_kkXc867.jpg" title="QQ圖片20150428133945.png" style="float:none;" alt="wKioL1U_Hp_SHww0AAcCKK_kkXc867.jpg" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6C/13/wKiom1U_HTDQ7cq5AAGqhcDf6Rc334.jpg" style="float:none;" title="QQ圖片20150428133755.png" alt="wKiom1U_HTDQ7cq5AAGqhcDf6Rc334.jpg" />
添加ip欄位
1.php檔案添加欄位
vim ./include/constants_logstream.php +354 修改這個PHP檔案
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6C/15/wKiom1U_LuCBQtauAAQiya5-_ps033.jpg" title="QQ圖片20150428135952.png" style="float:none;" alt="wKiom1U_LuCBQtauAAQiya5-_ps033.jpg" />
2.視圖添加欄位
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6C/10/wKioL1U_MEuBlr3VAATEgLuhTig369.jpg" title="QQ圖片20150428141546.png" style="float:none;" alt="wKioL1U_MEuBlr3VAATEgLuhTig369.jpg" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6C/11/wKioL1U_MM3CofwAAAE7UAH1FgE872.jpg" title="QQ圖片20150428134647.png" alt="wKioL1U_MM3CofwAAAE7UAH1FgE872.jpg" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/6C/10/wKioL1U_MEeTUV4XAAFqvnEvSis527.jpg" title="QQ圖片20150428134716.png" style="float:none;" alt="wKioL1U_MEeTUV4XAAFqvnEvSis527.jpg" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6C/10/wKioL1U_MEXy5_SyAAJ_TkyFc9E304.jpg" style="float:none;" title="QQ圖片20150428134744.png" alt="wKioL1U_MEXy5_SyAAJ_TkyFc9E304.jpg" />
3.資料庫添加欄位
修改/etc/rsyslog.conf 檔案添加一下2行。
$template insertpl,"insert into SystemEvents (Message, Facility, FromHost, FromIP,Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values (‘%msg%‘, %syslogfacility%,‘%HOSTNAME%‘, ‘%fromhost-ip%‘, %syslogpriority%, ‘%timereported:::date-mysql%‘, ‘%timegenerated:::date-mysql%‘, %iut%, ‘%syslogtag%‘)",SQL *.* :ommysql:localhost,Syslog,logger,123456;insertplmysql> USE Syslog; mysql> ALTER TABLE SystemEvents ADD FromIP VARCHAR(60) DEFAULT NULL AFTER FromHost;
這裡要注意看下database mapping 資料庫對應映射關係。要是映射不對,IP列會顯示不出來。rsyslog配置有修改,所以完成要記得重啟rsyslog服務。到這裡IP問題基本都可以解決了。rsyslog記錄模板化IP欄位--mysql寫入欄位--loganalyzer最上層顯示。
解決中文顯示亂碼的問題:
1.源碼檔案編碼改為utf8
編輯網站裡的include/functions_common.php檔案,找到含有return htmlentities欄位的行;return htmlentities($myStr, ENT_NOQUOTES, $content[‘HeaderDefaultEncoding‘]);// "UTF-8");修改為:return htmlentities($myStr, ENT_NOQUOTES, $content[‘HeaderDefaultEncoding‘], "UTF-8");注意小挂號有去除,分號改逗號。
2.視圖喜好設定改為utf8
admin center -->preference-->global options only 設定預設字元為utf-8
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6C/10/wKioL1U_LP7yUp2mAAIQECySOKQ095.jpg" title="QQ圖片20150428144041.png" alt="wKioL1U_LP7yUp2mAAIQECySOKQ095.jpg" />
3.查看mysql是否編碼為utf8
mysql> statusERROR 2006 (HY000): MySQL server has gone awayNo connection. Trying to reconnect...Connection id: 3771Current database: syslog--------------mysql Ver 14.14 Distrib 5.5.21, for Linux (x86_64) using EditLine wrapperConnection id: 3771Current database: syslogCurrent user: [email protected]SSL: Not in useCurrent pager: stdoutUsing outfile: ‘‘Using delimiter: ;Server version: 5.5.21-log Source distributionProtocol version: 10Connection: Localhost via UNIX socketServer characterset: utf8Db characterset: utf8Client characterset: latin1Conn. characterset: latin1UNIX socket: /tmp/mysql.sockUptime: 1 hour 38 min 30 secThreads: 29 Questions: 257366 Slow queries: 3726 Opens: 669 Flush tables: 1 Open tables: 179 Queries per second avg: 43.547
但是這裡的用戶端字元為latin1,改為utf8後,查看systemevents發現插入的資料全是亂碼。
Server version: 5.5.21-log Source distributionProtocol version: 10Connection: Localhost via UNIX socketServer characterset: utf8Db characterset: utf8Client characterset: utf8Conn. characterset: utf8
由此發現rsyslog插入mysql用的編碼是latin1.
5.用戶端插入和資料初始化為utf8 編碼
於是在my.cnf裡設定為
init_connect=‘SET NAMES utf8‘
強制串連用到編碼為utf8重啟mysql後解決了亂碼的問題
本文出自 “孜孜不倦的學習著...” 部落格,請務必保留此出處http://jonyisme.blog.51cto.com/3690784/1639746
rsyslog+loganalyzer+mysql的IP添加與中文亂碼解決