之前部署了Zabbix-3.0.3监控系统,在安装数据库时已经将zabbix库设置了utf-8字符。

首先确定zabbix开启了中文支持功能:
登录到zabbix服务器的数据目录下(前面部署的zabbix数据目录是/data/www/zabbix),打开 locales.inc.php文件
[root@Zabbix-server include]# pwd
/usr/local/nginx/html/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
/usr/local/nginx/html/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)

***************当你发现自己的才华撑不起野心时,就请安静下来学习吧***************

发表评论

邮箱地址不会被公开。 必填项已用*标注