Method 1: replace font
Modify web front end VIM of zabbix / www / HTML / zabbix / include / definitions.inc.php
Replace DejaVuSans with simkai in two places
define('ZBX_FONT_NAME', 'DejaVuSans'); define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans');
Replace DejaVuSans with simkai
define('ZBX_FONT_NAME', 'simkai'); define('ZBX_GRAPH_FONT_NAME', 'simkai')
I don't think this method is good. Let's see method 2
Method 2: modify the database code
Because of the character set format of mysql database, the default character set we use is UTF8, while the character set in mysql is latin1. When creating the database, it is not specified as UTF8 format, which will also cause the problem of garbled code.
# mysqldump -uzabbix -p zabbix > /tmp/zabbix.sql # sed -i 's/latin1/utf8/' /tmp/zabbix.sql
Delete the original database and create a new zabbix database
# mysqladmin -uzabbix -p drop zabbix Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'zabbix' database [y/N] y Database "zabbix" dropped # mysql -uzabbix -p mysql> create database zabbix create character set utf8; # mysql -uroot -predhat zabbix < /tmp/zabbix.sql
Do you think the above two methods can't solve the problem? Then refer to method 3
Method 3: modify the PHP file
The first is to recompile and install php, disable the - enable GD JIS conv option, which is expensive;
The second is to modify the php code:
1. Find the function imagettftext() in the file include/gaphs-inc.php;
2. After finding the file, copy the following php code to the file. Add the following function corresponding to imagettftext():
function to_entities($string){ $len = strlen($string); $buf = ""; for($i = 0; $i < $len; $i++){ if (ord($string[$i]) <= 127){ $buf .= $string[$i]; } else if (ord ($string[$i]) <192){ //unexpected 2nd, 3rd or 4th byte $buf .= "?"; } else if (ord ($string[$i]) <224){ //first byte of 2-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 31) << 6) + (ord($string[$i + 1]) & 63) ); $i += 1; } else if (ord ($string[$i]) <240){ //first byte of 3-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 15) << 12) + ((ord($string[$i + 1]) & 63) << 6) + (ord($string[$i + 2]) & 63) ); $i += 2; } else { //first byte of 4-byte seq $buf .= sprintf("&#%d;", ((ord($string[$i + 0]) & 7) << 18) + ((ord($string[$i + 1]) & 63) << 12) + ((ord($string[$i + 2]) & 63) << 6) + (ord($string[$i + 3]) & 63) ); $i += 3; } } return $buf; }
Add the above code to the graphs-inc.php file under zabbix/include, and then modify the imagettftext() function in the file in turn
Change the last $string parameter to "entities ($string)
Modify the style reference diagram as follows:
At this point, you will find that zabbix's chart can display Chinese correctly without restarting the service
Method 3 refers to linux commune