标签归档:Zabbix

Zabbix错误”zbx_mem_malloc(): out of memory”

Zabbix Server突然挂了,查看log报错如下:

using configuration file: /etc/zabbix/zabbix_server.conf
...
[file:dbconfig.c,line:545] zbx_mem_malloc(): out of memory (requested 16 bytes)
[file:dbconfig.c,line:545] zbx_mem_malloc(): please increase CacheSize configuration parameter

报错里已经很明确的提示了修复办法:please increase CacheSize configuration parameter

所以,我们就去zabbix_server.conf中找到CacheSize字段

### Option: CacheSize
#   Size of configuration cache, in bytes.
#   Shared memory size for storing host, item and trigger data.
#
# Mandatory: no
# Range: 128K-8G
# Default:
# CacheSize=8M

根据服务器配置情况,修改CacheSize

### Option: CacheSize
#   Size of configuration cache, in bytes.
#   Shared memory size for storing host, item and trigger data.
#
# Mandatory: no
# Range: 128K-8G
# Default:
CacheSize=2048M

重启Zabbix Server即可

systemctl start zabbix-server

Zabbix 3.0中文乱码解决方案

Zabbix出现中文乱码的可能原因主要是:

  1. Zabbix使用的数据库编码不为utf8
  2. Zabbix自带的字体有部分文字不支持

第一种情况,Zabbix将出现大范围的乱码,这种情况只能通过删除数据库,并使用utf8字体重建数据库解决

create database zabbix default charset utf8;

第二种情况,Zabbix主要在图表区域显示乱码。在监控图表页面,最新、最小、平均、最大这几个字显示为乱码。这种情况是由于zabbix图表自带的字体graphfont.ttf不支持中文导致的。我们需要进行替换

首先,在Windows系统中,找到我们要的字体,这里选择微软雅黑这个常用字体。

复制到桌面,获得两个.ttf字体文件

第一个是普通字体,第二个是加粗字体。我们选择第一个,上传到Zabbix所在服务器。

上传后,将字体移动到zabbix所在目录的fonts目录下。默认安装位置为

/usr/share/zabbix/fonts

在这个目录下,我们还可以看见zabbix的默认字体文件graphfont.ttf

最后,修改zabbix的配置文件include/defines.inc.php,将其中的graphfont修改为msyh即可

define('ZBX_FONT_NAME', 'graphfont');
define('ZBX_GRAPH_FONT_NAME', 'graphfont');

替换为

define('ZBX_FONT_NAME', 'msyh');
define('ZBX_GRAPH_FONT_NAME', 'msyh');

Zabbix Server Setup on Ubuntu(LNMP)

Author@henry 20160218

Installing Zabbix Server

apt-get install zabbix-server-mysql zabbix-frontend-php

Zabbix Server Configuration

vi /etc/zabbix/zabbix_server.conf

Search for the following properties and set them accordingly. Some may already be set correctly, and some you may have to add. Choose a password as well:

DBName=zabbix
DBUser=zabbix
DBPassword=<YOUR_PASSWD>

MySQL Configuration

mysql -u root -p
password:
> create user 'zabbix'@'localhost' identified by '<DB_PASSWD>';
> create database zabbix;
> grant all privileges on zabbix.* to 'zabbix'@'localhost';
> flush privileges;
> \q;
bye

import database tables;

cd /usr/share/zabbix-server-mysql/
sudo gunzip *.gz

mysql -u zabbix -p zabbix < schema.sql
mysql -u zabbix -p zabbix < images.sql
mysql -u zabbix -p zabbix < data.sql

PHP-FPM Configuration

vi /etc/php5/fpm/php.ini

Search for and adjust the following entries. If they do not exist, add them:

post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = UTC

restart php-fpm

service php5-fpm restart

Zabbix Configuration

copy the Zabbix-specific php file into the configuration directory:

cp /usr/share/doc/zabbix-frontend-php/examples/zabbix.conf.php.example /etc/zabbix/zabbix.conf.php

edit configuration file

vi /etc/zabbix/zabbix.conf.php

Edit the following values. Use the same info as when you set up the database earlier:

$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = '<YOUR_PASSWD>'

$ZBX_SERVER                     = '<SERVER_IP>';
$ZBX_SERVER_PORT                = '10051';
$ZBX_SERVER_NAME                = 'zabbix';

Nginx Configuration

add site into Nginx's site-available directory

vi /etc/nginx/site-available/zabbix

sample nginx server configuration file:

root@localhost:/etc/nginx/sites-available# cat zabbix 
server {
    listen 80;
    server_name monitor.domainname.com
    access_log /var/log/nginx/monitor_access.log;
    error_log /var/log/nginx/monitor_error.log;

    root /usr/share/zabbix;

    location / { 
        index index.php;
        error_page 403 404 502 503 504 /zabbix/index.php;
    }

    location ~ \.php($|/) {
        fastcgi_index index.php;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
     }

    location ~ \.(jpg|jpeg|gif|png|ico)$ {
        access_log off; 
        expires 33d; 
    }
}

enable zabbix server

cd /etc/nginx/site-enabled
ln -s ../site-available/zabbix
service nginx restart

Start Zabbix Service

vi /etc/default/zabbix-server

Go to the bottom and adjust the "START" property to read "yes":

START=yes

start zabbix service

service zabbix-server start

Front End Configuration

Visit you site use following url

http://monitor.yourdomain.com/

You will be presented with a login screen. The default credentials are as follows:

Username = admin
Password = zabbix

Login succeed, everything works, congrat!

Bug fix

  • Bug:
    ini_set(): Use of mbstring.internal_encoding is deprecated
    
  • Fix:
    vi /usr/share/zabbix/include/locales.inc.php
    

    Comment out the following line

    # line 25: 
    ini_set('mbstring.internal_encoding', 'UTF-8');
    

Ref: