zabbix monitoring service deployment

Posted by cuteflower on Tue, 28 Sep 2021 05:55:39 +0200

1. Introduction to ZABBIX

zabbix is an enterprise class open source solution based on WEB interface (which can be operated on the website) to provide distributed system monitoring and network monitoring functions. In addition, there are monitoring software such as cacti (good at drawing, flow diagram, architecture diagram, etc.), nagios (good at complex alarm configuration), zabbix (collection drawing, alarm, etc.), prometheus (10000 class).

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.

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.

Notification mechanism:

  • mail
  • WeChat (official account)
  • short message
  • Telephone
  • artificial
  • voice

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 the remote server; At the same time, it can also cooperate with zabbix agent, poll zabbix agent to actively receive monitoring data (agent mode), and passively receive data sent by zabbix agent (trapping mode).
In addition, the zabbix server also supports SNMP (v1,v2) and 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
    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, temperature

3. zabbix configuration file

zabbix configuration files are divided into:

  • Server side configuration file (/ usr/local/etc/zabbix_server.conf)
  • Client configuration file (/ usr/local/etc/zabbix_agentd.conf)
  • ZABBIX proxy configuration file (/ usr/local/etc/zabbix_proxy.conf)

Server side configuration file ZABBIX_ Common configuration parameters of server.conf:

parametereffect
LogFileSet the storage path of server log files
ListenIPSet the server listening IP
ListenPortSet the port number on which the server listens
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 the 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
HostnameSpecify the host name of this machine, which must be consistent with the web interface 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. Deploy zabbix

Environmental requirements:

environmentApps to install
The serverlamp architecture, zabbix server, zabbix agent
clientzabbix agent

zabbix is developed in php, so you must first deploy the lamp architecture to run php web pages

[root@localhost ~]# mysql -V
mysql  Ver 14.14 Distrib 5.7.34 , for linux-glibc2.12 (x86_64) using  EditLine wrapper

[root@localhost ~]# httpd -v
Server version: Apache/2.4.48 (Unix)
Server built:   Sep 26 2021 23:26:24

[root@localhost ~]# php -v
PHP 7.4.24 (cli) (built: Sep 27 2021 08:12:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
LISTEN     0      128             127.0.0.1:9000                                *:*                  
LISTEN     0      128                     *:111                                 *:*                  
LISTEN     0      5           192.168.122.1:53                                  *:*                  
LISTEN     0      128                     *:22                                  *:*                  
LISTEN     0      128             127.0.0.1:631                                 *:*                  
LISTEN     0      100             127.0.0.1:25                                  *:*                  
LISTEN     0      80                     :::3306                               :::*                  
LISTEN     0      128                    :::111                                :::*                  
LISTEN     0      128                    :::80                                 :::*                  
LISTEN     0      128                    :::22                                 :::*                  
LISTEN     0      128                   ::1:631                                :::*                  
LISTEN     0      100                   ::1:25                                 :::*        

9000, 803306 ports are up
Dependent packages required to install zabbix

[root@localhost ~]# yum -y install net-snmp-devel libevent-devel

Unzip and create user

[root@localhost src]# tar xf zabbix-5.4.4.tar.gz -C /usr/local/
[root@localhost ~]# useradd -r -M -s /sbin/nolong zabbix

Configuring the zabbix database

[root@localhost ~]# mysql -uroot -p1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.02 sec)

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

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

mysql> quit
Bye

[root@localhost ~]# cd /usr/local/zabbix-5.4.4/database/mysql/
[root@localhost mysql]# mysql -uzabbix -pzabbix  zabbix < schema.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix zabbix < images.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix zabbix < data.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

Compile and install

[root@localhost zabbix-5.4.4]# ./configure --enable-server \

Set zabbix database connection password

Set database information
[root@localhost zabbix-5.4.4]# vim /usr/local/etc/zabbix_server.conf
# Mandatory: no
# Default:
DBPassword=zabbix   

Start zabbix

[root@localhost ~]# mkdir /var/lib/mysql
[root@localhost ~]# ln -s /tmp/mysql.sock /var/lib/mysql/
[root@localhost ~]# zabbix_server
[root@localhost ~]#  zabbix_agentd
[root@localhost ~]# ss -antl

web interface installation and configuration of zabbix server

[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 ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

Replication front end

[root@localhost ~]# cd /usr/local/zabbix-5.4.4/
[root@localhost zabbix-5.4.4]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost zabbix-5.4.4]# cp ui/* /usr/local/apache/htdocs/zabbix/ -r
[root@localhost zabbix-5.4.4]# chown -R apache.apache /usr/local/apache/htdocs

Configure virtual host

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
//Add the following at the end of the configuration file
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName zabbix.wangjingjing.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>

Set the permissions of zabbix/conf directory zabbix.conf.php

[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]#  apachectl -t
Syntax OK

Restart apache

[root@localhost ~]# apachectl stop
[root@localhost ~]# apachectl start

Turn off the firewall, selinux

[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#getenforce
disabled

Result not shown
To be continued...

Topics: Linux Ubuntu IoT