分布式監控系統Zabbix-3.0.3-完整安裝記錄(4)-解決zabbix監控圖中出現中文亂碼問題


 

之前部署了Zabbix-3.0.3監控系統,在安裝數據庫時已經將zabbix庫設置了utf-8字符。

首先確定zabbix開啟了中文支持功能:
登錄到zabbix服務器的數據目錄下(前面部署的zabbix數據目錄是/data/www/zabbix),打開 locales.inc.php文件
[root@Zabbix-server include]# pwd
/data/www/zabbix/include
[root@Zabbix-server include]# vim locales.inc.php

然后登陸zabbix后,點擊右上角的“用戶”圖標,將語言設置為“中文”:

 

修改為“中文”語言后,添加監控項的配置,發現監控圖中出現中文亂碼!

這個問題是由於zabbix的web端沒有中文字庫導致,只需要加上中文字庫加上即可~

解決辦法如下:

1.從windows下控制面板->字體->選擇一種中文字庫例如“楷體”           【復制-粘貼出來,然后拷貝到zabbix服務器上】

 

將這個文件拷貝到zabbix的數據目錄的fonts目錄下

之前部署的zabbix數據目錄是/data/www/zabbix
[root@Zabbix-server fonts]# pwd
/data/www/zabbix/fonts
[root@Zabbix-server fonts]#ls
DejaVuSans.ttf

將上面從windows的“控制面板”----“字體”里下載下來的simkai.ttf文件拷貝到這里。
並且將之前的字體文件DejaVuSans.ttf移動到別處
[root@Zabbix-server fonts]# ls
simkai.ttf

然后,接着修改代碼include/defines.inc.php文件中的字體配置,將里面關於字體設置從DejaVuSans替換成simkai       【vim替換技巧:%s/DejaVuSans/simkai】
其中:simkai為字庫名字,不包含ttf后綴

這樣,修改后,zabbix監控圖形中的中文字就不會出現亂碼了!!
如下:

***********************************************************************************
以上的前提是zabbix數據庫在創建的時候已經將字符集設置成utf8了。
如果在創建zabbix數據庫的時候沒有指定utf8,默認字符集是lantin1,則需要修改字符集,如下:

查看數據庫默認字符集:
mysql> show create database zabbix;
+----------+-----------------------------------------------------------------+
| Database | Create Database |
+----------+-----------------------------------------------------------------+
| zabbix | CREATE DATABASE `zabbix` /*!40100 DEFAULT CHARACTER SET lantin1 */ |
+----------+-----------------------------------------------------------------+

查看字符集值:
mysql> show variables like 'collation%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

mysql> show variables like 'character%';
+--------------------------+----------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------+
| character_set_client | lantin1 |
| character_set_connection | lantin1 |
| character_set_database | lantin1 |
| character_set_filesystem | binary |
| character_set_results | lantin1 |
| character_set_server | lantin1 |
| character_set_system | lantin1 |
| character_sets_dir | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)

mysql>

需要做如下修改:
mysql>set character_set_client =utf8;
mysql>set character_set_connection=utf8;
mysql>set character_set_database =utf8;
mysql>set character_set_results =utf8;
mysql>set character_set_server =utf8;
mysql>set character_set_system =utf8;
mysql>SET collation_server = utf8_general_ci;
mysql>SET collation_database = utf8_general_ci;

修改數據庫默認字符集:
mysql>ALTER DATABASE `zabbix` DEFAULT CHARACTER SET utf8;

再次查看字符集就都是utf8了:
mysql> show create database zabbix;
+----------+-----------------------------------------------------------------+
| Database | Create Database |
+----------+-----------------------------------------------------------------+
| zabbix | CREATE DATABASE `zabbix` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show variables like 'collation%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

mysql> show variables like 'character%';
+--------------------------+----------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM