以前部署了Zabbix-3.0.3監控系統,在安裝數據庫時已經將zabbix庫設置了utf-8字符。php
首先肯定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.phpmysql
而後登錄zabbix後,點擊右上角的「用戶」圖標,將語言設置爲「中文」:web
修改成「中文」語言後,添加監控項的配置,發現監控圖中出現中文亂碼!sql
這個問題是因爲zabbix的web端沒有中文字庫致使,只須要加上中文字庫加上便可~數據庫
解決辦法以下:vim
1.從windows下控制面板->字體->選擇一種中文字庫例如「楷體」 【複製-粘貼出來,而後拷貝到zabbix服務器上】windows
將這個文件拷貝到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.ttfspa
而後,接着修改代碼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)