Deploy Zabbix monitoring software

Keywords: Linux Zabbix PHP MySQL Nginx

Monitoring is very important for operations and maintenance, which can be called the eyes of operations and maintenance personnel.A good monitoring system can help operators quickly find the root cause of the problem, reduce downtime, and improve the speed of troubleshooting.It can be seen from this that, as an operation and maintenance personnel, mastering the use of common monitoring software is one of the most basic skills.

1. Overview of Zabbix

1) Introduction to Zabbix

Zabbix is an enterprise open source operation and maintenance platform based on web interface which provides distributed system monitoring and network monitoring functions. It is also the most widely used monitoring software after the Internet in China. Over 85% of enterprises use ZABBIX as their monitoring solution.Zabbix is easy to start, easy to start, powerful and free from open source. It is easy to manage and configure, and produces beautiful data maps. Its auto-discovery function greatly reduces the workload of daily management. Rich data collection methods and API interfaces allow users to collect data flexibly. Distributed system architecture can support monitoring more devices, in theory, through the plug-in architecture provided by zabbix, can meet any needs of the enterprise (some plug-in features will be charged).

2) Advantages and disadvantages of commonly used monitoring software

Common monitoring tools are: Zabbix, nagios, cacti. This blog only briefly describes these three, with their advantages and disadvantages as follows:



  • 1) Enterprise distributed open source monitoring software (redhat, centos, Ubuntu, Debian) that supports multiple platforms;
  • 2) Simple installation and deployment, flexible integration of various data collection plug-ins;
  • 3) Powerful and complex multi-condition warning;
  • 4) With its own drawing function, the obtained data can be drawn into graphics for a more intuitive display of images;
  • 5) Provide a variety of api interfaces to support calling scripts;
  • 6) When problems occur, commands can be executed remotely automatically (requires agent to set execution rights);
  • 1) It is not convenient to modify projects in batches;
  • 2) There are relatively many alarm settings at the system level, and there are many alarm messages if they are filtered, and the customized items need to be set up by themselves. The process is cumbersome (you can import other people's templates online to modify them);
  • 3) Lack of data summary function, if you can't see the average value of a set of servers, you need to redevelop;
  • 4) The client needs to install the zabbix agent program;


Ngios is an open source enterprise monitoring system that can achieve basic monitoring of system cou, disk, network and other hardware parameters, as well as smtp, pop3 and other basic service types. In addition, by installing plug-ins and writing monitoring scripts, users can achieve application monitoring (less powerful than zabbix)


  • 1) The server, application and device in error will restart automatically and the log will scroll automatically;
  • 2) Flexible configuration allows you to customize shell scripts through distributed monitoring mode;
  • 3) Supporting host monitoring in redundant way, with various alarm settings;
  • 4) The command reloads the configuration file without interrupting Nagios;
  • 1) The event console is very weak and the plug-in is not easy to use.
  • 2) Lack of effort in dealing with performance, flow rate and other indicators;
  • 3) We can not see the historical data but only the alarm events, so it is difficult to trace the cause of the failure.
  • 4) The configuration is complex, and beginners spend more time, energy and cost.


With the advent of Zabbix, this technology has been phased out and you may know more about working longer, which is not much to say!

4) Functions of Zabbix

Zabbix has the following capabilities:

  • 1) It has the functions of common commercial monitoring software (performance monitoring of host, performance monitoring of network devices, database, performance monitoring, FTP and other general protocol monitoring, multiple police reporting modes, detailed report chart drawing);
  • 2) Support automatic discovery of network devices and servers (by configuring automatic discovery of server rules);
  • 3) Support low discovery key s for batch monitoring of dynamic monitoring items (scripts are required);
  • 4) Supporting distributed, centralized display and management of distributed monitoring points;
  • 5) Strong scalability, server provides a common interface (api function), can develop and improve various types of monitoring by itself (write programs according to the relevant interface), write plug-ins easily, can customize monitoring items, alarm level settings;
  • 6) Server/proxy and client modes; Flexible triggers; Can define very flexible problem thresholds called triggers; High customizable alerts; Send notifications, customizable alert upgrades, recipients, media types.CPU load, memory usage, disk usage, network condition, port monitoring, log monitoring, etc.

4) Monitoring principle of Zabbix

Zabbix collects data in c/s mode and displays and configures it on the web side in b/s mode.

Controlled side: host collects data by installing agent, network device collects data by snmp;
Server side: Collect data sent by snmp and agent, write to database, and display in web front end by php+nginx (or apache);

5) Composition of Zabbix

zabbix consists mainly of the following important components for the following purposes:

  • Zabbix Server: The core component responsible for receiving Agent's report information. It organizes all configuration, data statistics, and data operations.
  • Database strongage: Stores all configuration information and collected data;
  • Web interface: is the GUI interface for zabbix, which typically runs on the same host as Zabbix Server;
  • Proxy: An optional component, often used in distributed monitoring environments, where a proxy Server collects part of the data and forwards it to the Server to relieve pressure on the Server;
  • Agent: Deployed on the monitored host (client), responsible for collecting data from the monitored host, such as CPU, memory, database, etc., and sending it to the Server or Proxy side.

6) Zabbix Running Process

1) Agent needs to be installed on the monitored host, which is responsible for collecting data regularly and sending it to the zabbix server;
2) zabbix server stores the data in the database, and zabbix web displays and draws on the front end based on the data;

agent collection data is divided into active and passive modes:
Active: The agent requests the server to obtain an active list of monitors and actively submit the data for monitoring inward detection to the server/proxy;
Passive: the server requests data from the agent for monitoring items, and the agent returns data;

Passive: Compare consumption performance.
In passive mode, the zabbix server (or proxy) asks the agent for data, such as CPU load, and then the zabbix agent returns the results, and the zabbix server periodically requests data from the agent. The biggest problem with this mode is that it increases the workload of the zabbix server and is also the default mode of operation.
Active: High efficiency, but data may be missing.
Active mode is a mode in which zabbix agent actively collects data and returns it to the zabbix server. It no longer requires intervention from the zabbix server, so active mode can reduce the pressure on the zabbix server to some extent.

7) Zabbix Monitoring Architecture

In a real production environment, Zabbix is divided into three architectures based on external factors such as network environment, monitoring scale, etc. as shown in the figure:

(1) server-client architecture (direct connection)

The server-client architecture is the simplest architecture of Zabbix. It allows data interaction between the monitor and the monitored directly between the zabbix server and the ZABBIX agent without any agent. It is suitable for monitoring environments with simple network and few devices.

(2) master-node-client architecture (node architecture)

The master-node-client architecture is Zabbix's most sophisticated monitoring architecture and is suitable for large-scale environments that span networks, rooms and devices.Each node is also a server-side.A proxy is available below the node, or you can connect directly to the client.Node has its own configuration file and database.What it does is synchronize the configuration information with the monitor data item master.Node ensures the integrity of the architecture when the master fails or is corrupted;

(3) server-proxy-client architecture (proxy architecture)

proxy is a bridge between server and client. proxy itself does not have a front end, and it does not store data. It only temporarily stores the data sent by the agent, and then submits it to the server.This architecture is often compared to the master-node-client architecture, and is generally applicable for monitoring medium-sized network architectures across rooms and networks.

2. Setting up an LNMP environment

Since deploying Zabbix requires an environment using LNMP, it needs to be deployed beforehand.For detailed project deployment, you can refer to Build LNMP The next explanation of the LNMP command is no longer detailed!

1) Install Nginx

download nginx package

[root@zabbix ~]# yum -y install pcre-devel openssl-devel zlib-devel 
[root@zabbix ~]# tar zxf nginx-1.14.0.tar.gz && cd nginx-1.14.0
[root@zabbix nginx-1.14.0]# ./configure && make && make install
//Just use nginx to provide a simple web page startup!
[root@zabbix ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
//Create symbolic links and start later

2) Install PHP

download PHP Package

[root@zabbix ~]#  yum -y install freetype-devel libpng-devel libjpeg-devel libxml2-devel bzip2-devel libcurl-devel
//Dependencies required to install php
[root@zabbix ~]#  tar zxf libmcrypt-2.5.7.tar.gz && cd libmcrypt-2.5.7
[root@zabbix libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt && make && make install
//Install libmcrypt
[root@zabbix ~]# tar zxf php-5.6.27.tar.gz && cd php-5.6.27
[root@zabbix php-5.6.27]# ./configure --prefix=/usr/local/php5.6 \
 --with-config-file-path=/etc --with-mysql=/usr/local/mysql \
 --with-mysqli=/usr/local/mysql/bin/mysql_config \
 --with-mysql-sock=/usr/local/mysql/mysql.sock \
 --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt=/usr/local/libmcrypt \
 --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-zlib \
 --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml \
 --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization \
 --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp \
 --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets \
 --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext \
 --enable-session --with-curl && make && make install
//Compile and install php
[root@zabbix ~]# cp /root/php-5.6.27/php.ini-production /etc/php.ini
[root@zabbix ~]# cp /root/php-5.6.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@zabbix ~]#  chmod +x /etc/init.d/php-fpm 
[root@zabbix ~]# chkconfig --add php-fpm
[root@zabbix ~]# cd /usr/local/php5.6/etc
[root@zabbix etc]# cp php-fpm.conf.default php-fpm.conf
[root@zabbix etc]# sed -i 's#;pid = run/ = run/' php-fpm.conf
[root@zabbix etc]# sed -i 's/listen = =' php-fpm.conf
[root@zabbix etc]# sed -i 's/pm.max_children = 5/pm.max_children = 50/g' php-fpm.conf
[root@zabbix etc]# sed -i 's/pm.start_servers = 2/pm.start_servers = 5/g' php-fpm.conf
[root@zabbix etc]# sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g' php-fpm.conf
[root@zabbix etc]# sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 35/g' php-fpm.conf
[root@zabbix etc]# systemctl start php-fpm  
[root@zabbix etc]# ss -lnt | grep 9000
LISTEN     0      128          *:9000                     *:*          
//Ensure successful PHP startup

3) Configure nginx to connect with PHP

[root@zabbix ~]# vim /usr/local/nginx/conf/nginx.conf
        location ~ \.php$ {
            root           html;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;           //Modify this line

[root@zabbix ~]# echo -e "<?php\nphpinfo();\n?>" > /usr/local/nginx/html/index.php
[root@zabbix ~]# nginx -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@zabbix ~]# nginx

Access tests;

4) Install mysql database

download mysql database software The script to install mysql is provided at one click. Just execute the script directly!

[root@zabbix ~]# ls | grep mysql
[root@zabbix ~]# sh
//After installation, the password for database user root is 123

Here we will not test the link between PHP and mysql, and have confidence in the LMP we have built!

3. Install Zabbix

download Zabbix Package

[root@zabbix ~]# tar zxf fping-3.12.tar.gz  && cd fping-3.12
[root@zabbix fping-3.12]#  ./configure && make && make install
//Compile and install fping to enable Zabbix to support automatic discovery
[root@zabbix fping-3.12]# groupadd zabbix
[root@zabbix fping-3.12]# useradd zabbix -M -g zabbix
[root@zabbix fping-3.12]# chown zabbix:zabbix /usr/local/sbin/fping
//Create a zabbix user to use the fping command
[root@zabbix ~]# yum -y  install  net-snmp net-snmp-devel curl-devel OpenIPMI-devel libssh2-devel java-devel
//Dependencies required to install zabbix
[root@zabbix ~]# tar zxf zabbix-3.2.1.tar.gz && cd zabbix-3.2.1
[root@zabbix zabbix-3.2.1]# ./configure --prefix=/usr/local/zabbix --enable-server \
 --enable-agent --enable-java --with-mysql=/usr/local/mysql/bin/mysql_config \
 --with-net-snmp --with-libcurl --with-openipmi && make && make install
//--enable-java: for monitoring tomcat programs in the future;
//--with-openipmi: Enables it to monitor device hardware information
[root@zabbix ~]# ln  -s  /usr/local/zabbix/bin/*  /usr/local/bin/ 
[root@zabbix ~]# ln  -s  /usr/local/zabbix/sbin/*  /usr/local/sbin/
//Create symbolic links for common zabbix commands
[root@zabbix ~]# mysql -u root -p123
mysql> create database zabbix character set utf8;
mysql> grant all privileges on zabbix.* to 'zabbix'@'192.168.1.%' identified by '';
//Create zabbix database and users
[root@zabbix ~]# cd /root/zabbix-3.2.1/database/mysql/
[root@zabbix mysql]# mysql -uzabbix -h zabbix < schema.sql
[root@zabbix mysql]# mysql -uzabbix zabbix -h < images.sql
[root@zabbix mysql]#  mysql -uzabbix zabbix -h < data.sql 
//Enter the appropriate directory to import the appropriate database files
//Remember to import in order, otherwise you may get unexpected
[root@zabbix mysql]# cd /usr/local/zabbix/etc
[root@zabbix etc]# egrep -v '^#|^$' zabbix_server.conf
FpingLocation=/usr/sbin/fping           //fping file path
//Above is the modified configuration file
[root@zabbix etc]# find   / -name
[root@zabbix etc]# echo "/usr/local/mysql/lib" >> /etc/
//Add interface file path for libmysqlclinet
[root@zabbix etc]# ldconfig 
//The main purpose is to search for shared dynamic link libraries (such as lib*.so*) in the default search directories/lib and/usr/lib, as well as directories listed in the dynamic library configuration file/etc/ to create the connection and cache files required by the dynamic loader (
[root@zabbix etc]# find  /  -name  mysql.sock
[root@zabbix etc]# ln  -s /usr/local/mysql/mysql.sock  /tmp/
//Add mysql.sock file to tmp directory, otherwise error will occur at startup
[root@zabbix etc]# cd  /root/zabbix-3.2.1/
[root@zabbix zabbix-3.2.1]# cp  misc/init.d/fedora/core/zabbix_server  /etc/init.d/
[root@zabbix zabbix-3.2.1]# chmod +x /etc/init.d/zabbix_server 
[root@zabbix zabbix-3.2.1]# sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g" /etc/rc.d/init.d/zabbix_server
//Change the installation path of zabbix in the zabbix system script
[root@zabbix zabbix-3.2.1]# systemctl daemon-reload 
[root@zabbix zabbix-3.2.1]# /etc/init.d/zabbix_server start
Reloading systemd:                                         [  Determine  ]
Starting zabbix_server (via systemctl):                    [  Determine  ]
[root@zabbix zabbix-3.2.1]# ss -lnt | grep 10051
LISTEN     0      128          *:10051                    *:*          
//Add as system service and start, make sure its port is listening, default is 10051
//View/tmp/zabbix_server.log if startup fails
[root@zabbix ~]# cp -r /root/zabbix-3.2.1/frontends/php/ /usr/local/nginx/html/zabbix
//Copy zabbix's page directory to nginx's page root directory
[root@zabbix ~]# ps -ef | grep php
//From the query results, you can see that the user running the php program is nobody
[root@zabbix ~]# chown -R nobody:nobody /usr/local/nginx/html/zabbix/
//So you need to ensure that users running PHP have absolute permissions on this directory or you won't be able to change the data

Client Access Test:

Modify php configuration file based on prompted warnings

[root@zabbix ~]# sed -i 's/post_max_size = 8M/post_max_size = 16M/g'  /etc/php.ini
[root@zabbix ~]# sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php.ini
[root@zabbix ~]# sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini
[root@zabbix ~]# echo -e "date.timezone = Asia/Shanghai" >> /etc/php.ini
[root@zabbix ~]# echo -e "always_populate_raw_post_data = -1" >> /etc/php.ini
[root@zabbix ~]# systemctl restart php-fpm
//Restart php to load the configuration file

Continue to access the web page, as shown in the following figure:

You can see that the interface has become Chinese!

However, we need to pay attention to the problem of Chinese scrambling in zabbix. We need to use the following methods to modify the problem of Chinese scrambling!

[root@zabbix ~]# ls | grep SIMKAI.TTF
[root@zabbix ~]# sed -i 's/DejaVuSans/simkai.ttf/g' /usr/local/nginx/html/zabbix/include/
[root@zabbix ~]# mv SIMKAI.TTF /usr/local/nginx/html/zabbix/fonts/simkai.ttf

If you do not solve the problem of Chinese random code, you will have a lot of trouble in the future work!

This blog mainly describes how to set up a zabbix monitoring system, which will start with a paragraph here!


Posted by neverett on Tue, 07 Jan 2020 16:12:30 -0800