zabbix监控中常碰到的字符集问题有三个:
1.图形中显示中文乱码
解决方法:
#1.从window主机路径C:\Windows\Fonts下选择一种自己喜欢的字体,如mysh.ttf(雅黑); #2.将拷贝出来的字体上传到zabbix server网页文件的fonts目录下,并命名为 DejaVuSans.ttf [root@zhu1 ~]# mv /var/www/html/fonts/DejaVuSans.ttf /var/www/html/fonts/DejaVuSans.ttf.old mv /var/www/html/fonts/mysh.ttf /var/www/html/fonts/DejaVuSans.ttf #这样便能解决这个乱码问题
2.历史记录处出现问号乱码
这与zabbix数据库所使用的字符集有关,解决方法如下:
1.查看当前的默认字符集
mysql> show create database zabbix; +----------+-------------------------------------------------------------------+ | Database | Create Database | +----------+-------------------------------------------------------------------+ | zabbix | CREATE DATABASE `zabbix` /*!40100 DEFAULT CHARACTER SET latin1 */ | +----------+-------------------------------------------------------------------+ 1 row in set (0.00 sec) #安装时在导入三个sql文件时,zabbix数据库中创建的表的字符集也是latin1 mysql> show variables like 'character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
2.这是由于字符集不是utf8引起的,现在的解决方法有两种:
当当前zabbix数据库中已存在一定的数据的解决办法
1)备份zabbix数据库
[root@zhu1 ~]# mysqldump -uroot -p123456 zabbix > zabbix.sql
2)修改备份文件
[root@zhu1 ~]# sed -i 's/latin1/utf8/g' zabbix.sql
3)删除zabbix数据库
mysql> drop database zabbix;
4)关闭mysql数据库,设置默认字符集
[root@zhu1 ~]# vim /etc/my.cnf [mysqld] log-bin datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock default-character-set = utf8 #添加该项
5)启动mysql并恢复zabbix数据库
[root@zhu1 ~]# mysql -uroot -p123456 zabbix < zabbix.sql
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 'character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
6)访问页面
2.当安装后发现,则可以:
#1.删除zabbix数据库 #2.设置mysql数据库的默认字符集为utf8 #3.重新创建zabbix数据库并导入三个sql文件
总结:
2
--with-charset=CHARSET Default character set, use one of: binary armscii8 ascii big5 cp1250 cp1251 cp1256 cp1257 cp850 cp852 cp866 cp932 dec8 eucjpms euckr gb2312 gbk geostd8 greek hebrew hp8 keybcs2 koi8r koi8u latin1 latin2 latin5 latin7 macce macroman sjis swe7 tis620 ucs2 ujis utf8 --with-extra-charsets=CHARSET,CHARSET,... Use charsets in addition to default (none, complex, all, or a list selected from the above sets) #上面这两个是编译安装mysql事对字符集设置的参数,当不进行设置时默认便是latin1,
转载于:https://blog.51cto.com/zhujiangtao/1313630