Monitoring service Zabbix

Posted by Scott_J on Tue, 28 Sep 2021 05:05:58 +0200

Monitoring service Zabbix

Common monitoring software

  • cacti is good at drawing flow diagram and architecture diagram
  • nagios is good at complex alarm configuration
  • zabbix
  • prometheus

zabbix introduction

zabbix is an enterprise class open source solution that provides distributed system monitoring and network monitoring based on WEB interface

zabbix can monitor various network parameters to ensure the safe operation of the server system; Flexible notification mechanism is provided to enable system administrators to quickly locate / solve various problems.

Notification mechanism:

  • mail
  • WeChat (official account)
  • SMS (zabbix doesn't bring it and needs to be developed)
  • Telephone (zabbix doesn't bring it and needs to be developed)
  • artificial
  • voice
    Mail and voice notification mechanisms are widely used

zabbix composition:

  • zabbix server
  • zabbix agent

zabbix server can provide remote server / network status monitoring, data collection and other functions through SNMP, zabbix agent, ping, port monitoring and other methods.
It can run on Linux, Ubuntu, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X and other platforms.

zabbix agent needs to be installed on the monitored target server. It mainly collects hardware information or memory, CPU and other information related to the operating system.

The zabbix server can monitor the service status of the remote server independently and cooperate with the zabbix agent. It can poll the zabbix agent to actively receive the monitoring data (agent mode) and passively receive the data sent by the zabbix agent (trapping mode).

zabbix features

  • Main features of zabbix:

    • Simple installation and configuration, low learning cost
    • Support multiple languages (including Chinese)
    • Free open source
    • Automatically discover servers and network devices
    • Distributed monitoring and WEB centralized management
    • Can be monitored without agent
    • User security authentication and soft authorization
    • Set or view the monitoring results through the WEB interface
    • Notification functions such as email
  • Monitoring indicators:

    • System monitoring
      • Memory, CPU, hard disk
    • network monitoring
      • Network card, network equipment (router, switch)
    • Business monitoring
      • Process, port, log
    • Hardware monitoring (IPMI sensor)
      • Quantity and temperature

Deploy zabbix

Environmental description:

environmentIPApplications to install
The server192.168.218.132lanmp architecture
zabbix server
zabbix agent
client192.168.218.133zabbix agent

Note: because zabbix is developed in php language, you must first deploy lamp architecture to support running php web pages

zabbix service installation

//Install dependent packages
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel

//Put the installation package under / usr/src and unzip it
[root@localhost src]# ls 
apr-1.7.0              debug                mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
apr-1.7.0.tar.gz       httpd-2.4.49         php-7.4.24
apr-util-1.6.1         httpd-2.4.49.tar.gz  php-7.4.24.tar.xz
apr-util-1.6.1.tar.gz  kernels              zabbix-5.4.4.tar.gz
[root@localhost src]# tar xf zabbix-5.4.4.tar.gz 

//Create user
[root@localhost zabbix-5.4.4]# useradd -r -M -s /sbin/nologin zabbix

//Create database
mysql> create database zabbix character set utf8 collate utf8_bin;

//Authorized user
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix123';
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

//Import the database in strict order and cannot be reversed
[root@localhost ~]# cd /usr/src/zabbix-5.4.4/database/mysql/
[root@localhost mysql]# ls 
data.sql  double.sql  images.sql  Makefile.am  Makefile.in  schema.sql
[root@localhost mysql]# mysql -uroot -p123456 zabbix < schema.sql
[root@localhost mysql]# mysql -uroot -p123456 zabbix < images.sql
[root@localhost mysql]# mysql -uroot -p123456 zabbix < data.sql 

//Compile zabbix
[root@localhost zabbix-5.4.4]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
[root@localhost zabbix-5.4.4]# make install

The above server installation is completed

zabbix server configuration

//Modify server configuration file
[root@localhost zabbix-5.4.4]# cd /usr/local/etc/
[root@localhost etc]# ls 
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d
[root@localhost etc]# vim zabbix_server.conf
 search DBPassword,modify# DBPassword=zabbix123

//Start zabbix
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
 Note: an error will appear. Port 10051 is not opened. Check/tmp/zabbix_server.log You will find that you can't connect to the database because/var/lib/mysql/mysql.sock non-existent

//Launch 10051 port solution
[root@localhost ~]# mkdir /var/lib/mysql
[root@localhost ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# ss -antl 
State     Recv-Q    Send-Q       Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128                0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         128                0.0.0.0:10050             0.0.0.0:*                  
LISTEN    0         128                0.0.0.0:10051             0.0.0.0:*                  
LISTEN    0         128              127.0.0.1:9000              0.0.0.0:*                  
LISTEN    0         128                   [::]:22                   [::]:*                  
LISTEN    0         80                       *:3306                    *:*                  
LISTEN    0         128                      *:80                      *:* 

web interface installation and configuration of zabbix server

zabbix web interface pre installation configuration

//Configure virtual host
[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# mkdir zabbix

[root@localhost zabbix-5.4.4]# cp -r ui/* /usr/local/apache/htdocs/zabbix/

[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/htdocs/

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
//Add at the end
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.zabbix.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
    <Directory "/usr/local/apache/htdocs/zabbix">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

//Modify php services
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# systemctl restart php-fpm 

//Set the permissions of the zabbix/conf directory so that ZABBIX has the permission to generate the configuration file zabbix.conf.php
[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf

//Restart httpd
[root@localhost ~]# systemctl restart httpd

The above zabbix deployment has been completed. You can enter IP to access the installation

Log in to zabbix

zabbix default login user name and password:

user namepassword
Adminzabbix

Topics: PHP Linux Operation & Maintenance