之前部署了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)