Zabbix introduction and deployment

Posted by manlio on Thu, 03 Mar 2022 07:39:45 +0100

1. Zabbix introduction

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

Zabbix can monitor various network parameters to ensure the safe operation of the server system; And provide flexible notification mechanism to enable system administrators to quickly locate / solve various problems.

Zabbix consists of two parts, Zabbix server and optional component 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.

Zabbix server can independently monitor the service status of remote server; At the same time, it can also cooperate with Zabbix agent to poll Zabbix agent to actively receive monitoring data (agent mode) and passively receive data sent by Zabbix agent (trapping mode).
In addition, Zabbix server also supports SNMP (v1,v2), which can be used with SNMP software (e.g. net SNMP).

2. 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

  • Main functions of Zabbix:

  • CPU load

  • Memory usage

  • Disk usage

  • Network status

  • Port monitoring

  • Log monitoring

3. Zabbix profile

There are two types of Zabbix configuration files:

  • Server side configuration file / usr/local/etc/Zabbix_server.conf
  • Client configuration file / usr/local/etc/Zabbix_agentd.conf
  • Zabbix agent configuration file / usr/local/etc/Zabbix_proxy.conf

Server side configuration file Zabbix_server.conf common configuration parameters:

parametereffect
LogFileSet the storage path of server log file
ListenIPSet the server listening IP
ListenPortSet the port number of the server listening
PidFileSet the storage path of server process number file
DBHostSpecify the database server IP of Zabbix
DBNameSpecify the database library name used by Zabbix
DBUserSpecify the Zabbix database login user
DBPasswordSpecify Zabbix database login password
DBPortSpecify the Zabbix database port number
UserSet which user Zabbix runs as
AlertScriptsPathSet the storage path of alarm script
ExternalScriptsExternal script storage path

Client profile Zabbix_agentd.conf common configuration parameters:

parametereffect
ServerSpecify the IP or domain name of the Zabbix server
ServerActiveSpecify the IP or domain name of the Zabbix server
HostnameThe host name of this web configuration item must be consistent with that of this web configuration item
UnsafeUserParametersWhether to enable user-defined monitoring items. The optional value is {1
UserParameterSpecify custom monitoring script parameters
LogFileSet the storage path of client log files

4. Zabbix components

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-mxyhhl2o-1646288784714)( https://www.jlin.red/upload/2021/10/Zabbix%E7%BB%84%E4%BB%B6 -3864679409624eae8b4273ad8b56d977. jpg)]

  • Zabbix server: the core component responsible for receiving the report information sent by the agent. All configuration, statistics and operation data are organized by the agent
  • Zabbix database: users store all configuration information and data collected by Zabbix server
  • Zabbix web: the interface interface of Zabbix, which usually runs on the same host as the Server
  • Zabbix agent: deployed on the monitored host, responsible for collecting local data and sending it to the server or proxy
  • Zabbix proxy: it is often used in distributed monitoring environment. The proxy Server collects some monitored monitoring data and sends it to the Server (usually it needs to be used for more than 500 hosts)

5. Zabbix principle

Zabbix agent is installed on the monitored host and is responsible for regularly collecting various local data of the monitored end and sending it to Zabbix server. Zabbix server receives the data and stores the data in Zabbix database. Users can see the front-end data image based on the visual interface of Zabbix web. When Zabbix monitors a specific project, it will set a trigger threshold. When the monitored indicators exceed the threshold set by the trigger, it will take some necessary actions, including sending information (e-mail, wechat, SMS), sending commands (SHELL command, Reboot, Restart, Install, etc.).

6. Deploy Zabbix

Environmental description:

environmentIPApps to install
The server192.168.91.134lamp architecture; Zabbix server´╝Ť Zabbix agent
client192.168.91.134Zabbix agent

Because Zabbix is developed in php language, we must first deploy the lamp architecture to support running php web pages

be careful:

  • Before installing the lamp architecture, you'd better restore the snapshot first and then install it
  • If you want to deploy Zabbix, install the latest version of mysql in lamp. Don't install the latest version of 8.0.10 for php. Just install version 7.4.24

php7.4.24 package link: https://www.php.net/distributions/php-7.4.24.tar.xz

Zabbix server installation

//Install dependent packages
[root@JLin ~]# yum -y install net-snmp-devel libevent-devel gcc gcc-c++ make
 
//Download Zabbix
[root@JLin ~]# wget -O https://cdn.zabbix.com/Zabbix/sources/stable/5.4/Zabbix-5.4.4.tar.gz /usr/src/

//decompression
[root@JLin ~]# cd /usr/src/
[root@JLin ~]# tar xf Zabbix-5.4.4.tar.gz

//Create user
[root@JLin ~]# useradd -r -M -s /sbin/nologin Zabbix

//Turn off the firewall
[root@JLin src]# systemctl disable --now firewalld 
[root@JLin src]# setenforce 0

//Configuring the Zabbix database
mysql> create database Zabbix character set utf8 collate utf8_bin; 
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on Zabbix.* to 'Zabbix'@'localhost' identified by 'Zabbix123';
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush  privileges;
Query OK, 0 rows affected (0.00 sec)

[root@JLin mysql]# cd /usr/src/Zabbix-5.4.4/database/mysql
[root@JLin mysql]# mysql -uroot -p123456 Zabbix   < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@JLin mysql]# mysql -uroot -p123456 Zabbix   < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@JLin mysql]# mysql -uroot -p123456 Zabbix   < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

//Compile and install
[root@JLin Zabbix-5.4.4]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

[root@JLin Zabbix-5.4.4]# make install

//Server configuration
[root@JLin Zabbix-5.4.4]# vim /usr/local/etc/Zabbix_server.conf
DBPassword=Zabbix123

[root@JLin Zabbix-5.4.4]# mkdir /var/lib/mysql 
[root@JLin Zabbix-5.4.4]# ln -s /tmp/mysql.sock /var/lib/mysql/
[root@JLin Zabbix-5.4.4]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64
[root@JLin Zabbix-5.4.4]# Zabbix_server 
[root@JLin Zabbix-5.4.4]# Zabbix_agentd 
[root@JLin Zabbix-5.4.4]# ss -antl
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port 
LISTEN 0      128        127.0.0.1:9000       0.0.0.0:*    
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      80                 *:3306             *:*    
LISTEN 0      128                *:80               *:*    
LISTEN 0      128             [::]:22            [::]:* 

//Installation and web interface
[root@JLin Zabbix-5.4.4]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@JLin Zabbix-5.4.4]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@JLin Zabbix-5.4.4]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@JLin Zabbix-5.4.4]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@JLin Zabbix-5.4.4]# systemctl restart php-fpm


[root@JLin Zabbix-5.4.4]# mkdir /usr/local/httpd/htdocs/Zabbix 
[root@JLin Zabbix-5.4.4]# cp -a ui/* /usr/local/httpd/htdocs/Zabbix/
[root@JLin Zabbix-5.4.4]# chown -R apache.apache /usr/local/httpd/htdocs/

[root@JLin Zabbix-5.4.4]# vim /usr/local/httpd/conf/httpd.conf 
<VirtualHost *:80>
    DocumentRoot "/usr/local/httpd/htdocs/Zabbix"
    ServerName www.csl.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/httpd/htdocs/Zabbix/$1
    <Directory "/usr/local/httpd/htdocs/Zabbix">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

//Set the permissions of the Zabbix/conf directory so that Zabbix has the permission to generate the configuration file Zabbix conf.php
[root@JLin Zabbix-5.4.4]# chmod 777 /usr/local/httpd/htdocs/Zabbix/conf
[root@JLin Zabbix-5.4.4]# systemctl restart httpd
[root@JLin Zabbix-5.4.4]# systemctl restart php-fpm

Install Zabbix web interface
[external chain picture transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-c0xfaf1n-1646288784715)( https://www.jlin.red/upload/2021/10/Zabbix1-9940111e1dbe4b279741e4d110eb0d3a.jpg )]
[external chain picture transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-fk6pdqhf-1646288784715)( https://www.jlin.red/upload/2021/10/Zabbix2-eb6f35d554914e83b98ee59050314c39.jpg )]
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-b0j6dtx1-1646288784716)( https://www.jlin.red/upload/2021/10/Zabbix3-d96a3a6b66ae4b2e9301d6b560199a43.jpg )]
[external chain picture transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-4divkrjw-1646288784716)( https://www.jlin.red/upload/2021/10/Zabbix4-39b4027352c843359b1ae92a6de25df8.jpg )]
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-80xegbam-1646288784716)( https://www.jlin.red/upload/2021/10/Zabbix5-ab0f1d77d4154a97b42337dc9c58485b.jpg )]
[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-zdbtzmhu-1646288784716)( https://www.jlin.red/upload/2021/10/Zabbix6-300aa24bf87946688ea713d18159bd8d.jpg )]
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-2pe4dglr-1646288784717)( https://www.jlin.red/upload/2021/10/Zabbix7-4dd09200300c4eaaa38c5ba0615370da.jpg )]
[the external chain image transfer fails. The source station may have anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-l2lzcba6-1646288784717)( https://www.jlin.red/upload/2021/10/Zabbix8-6fe7da96005b4c4fa0e8f7424ec38c01.jpg )]

Topics: Linux Operation & Maintenance Zabbix server