Distributed application monitoring platform zabbix

1. Relevant knowledge of the monitoring system 
 1.1 Reasons for the use of the monitoring system

 When we need to pay attention to whether the related indicators are normal in real time, there are often many hardware resources such as servers and network devices. If we want to monitor them more conveniently and centrally, zabix can implement centralized monitoring and management applications

The original intention of monitoring is that when some indicators do not meet our needs, we can find abnormalities in the first place.

Monitoring can give me:

When needed, raise to remind us of server problems

When a problem occurs, the root cause of the problem can be found

Website/Server Availability
 

 1.2 Availability of the website
 
When the system is highly available, the standard to measure its reliability is represented by n 9, a ratio of the system usage time to the total time in a year, the higher the value, the stronger the reliability, and different The number level of 9 represents the stability of the system.

One 9: (1-90%)*365=36.5 days, which means that the maximum possible business interruption time of the software system in one year of continuous operation is 36.5 days

Two 9s: (1-99%)*365=3.65 days, which means that the maximum possible business interruption time of the software system in one year of continuous operation is 3.65 days

Three 9s: (1-99.9%)*365*24=8.76 hours, which means that the maximum possible business interruption time of the software system in one year of continuous operation is 8.76 hours

Four 9s: (1-99.99%)*365*24=0.876 hours=52.6 minutes, which means that the maximum possible business interruption time of the software system in one year of continuous operation is 52.6 minutes

5 nines: (1-99.999%)*365*24*60=5.26 minutes, which means that the maximum possible business interruption time of the software system in one year of continuous operation is 5.26 minutes

6 nines: (1-99.9999%)*365*24*60*60=31 seconds, indicating that the maximum possible business interruption time of the software system in one year of continuous operation is 31 seconds
 

Like some big factories, it can even reach an exaggerated level of 20 nines 
 

1.3 Commonly used monitoring systems on the market 
Commonly used monitoring software on the market:

Traditional operation and maintenance: zabbix, Nagios
Cloud native environment: Prometheus (developed in go language)
  2. Knowledge about
zabbix 2.1 Overview of zabbix

Zabbix is ​​an open source monitoring system that provides distributed monitoring and centralized web management pages

 Zabbix has the functions of common commercial monitoring software, host performance monitoring, network equipment performance monitoring, database performance monitoring, ftp, http and other general protocol monitoring, when the monitored indicators are abnormal, it can send an alarm based on E-mail

zbbix provides reports and real-time graphical data processing to realize 7x24-hour centralized monitoring of the monitoring host

Zabbix collects monitoring data through C/S mode, and displays and configures them on the web side through B/S mode. The monitored object only needs to support the SNMP protocol or run the Zabbix agents agent program. The listening port of the server is 10051, and the monitored end is Zabbix——agents agent monitors port 10050
 

2.2 What is zabbix?
1. Zabbix is ​​an enterprise-level open source solution that provides distributed system monitoring and network monitoring functions based on a web interface.
Two zabbix can monitor various network parameters to ensure the safe operation of the server system; and provide a flexible notification mechanism to allow system administrators to quickly locate/solve various problems.
Three zabbix consists of 2 parts, zabbix server and optional component zabbix agent. Collect data through the c/s mode, and display and configure it on the web side through the B/s mode.
Four zabbix server can provide remote server/network status monitoring, data collection and other functions through SNMP (Simple Network Management Protocol), zabbix agent, ping, port monitoring and other methods, and it can run on platforms such as Linux. (Multiple platforms are supported, and windows also supports it)
5. zabbix agent needs to be installed on the target server to be monitored. It mainly completes the collection of hardware information or memory, CPU and other information related to the operating system.
 

2.3 The monitoring principle of zabbix 
 
The zabbix agent is installed on the monitored host. The zabbix agent is responsible for collecting various local data of the client on a regular basis and sending it to the zabbix server. After receiving the data, the zabbix server stores the data in the database. Users based on Zabbix WEB can see the data and display the image on the front end. When zabbix monitors a specific project, the project will set a trigger threshold. When the monitored indicator exceeds the threshold set by the trigger, some necessary actions will be taken, including: sending information (email, WeChat, SMS) ), sending commands (shell commands, reboot, restart, install, etc.).
 

2.4 Five common programs in zabbix monitoring system
 
Zabbix server: zabbix server daemon process, in which zabbix_agent, zabbix_get, zabbix_sender, zabbix_proxy data are finally submitted to zabbix server;
zabbix agent: client daemon process, responsible for collecting client data , for example: collect CPU load, memory, hard disk usage, etc.;
zabbix proxy: zabbix distributed proxy daemon process, usually larger than 500 hosts, requires distributed monitoring architecture deployment; zabbix get
: zabbix data receiving tool, used alone The commands are usually executed on the server or proxy side to obtain remote client information;
●zabbix sender: zabbix data sending tool, the user sends data to the server or proxy side, usually the user takes a long time to check.
 

2.5 Zabbix 6.0 new features:

1. Zabbix server high availability prevents hardware failure or downtime during planned maintenance period:
• Natively choose to join HA cluster configuration
• Define one or more standby nodes
• Monitor the status of Zabbix server cluster nodes in real time
• Zabbix server can be installed without external tools Configured in HA cluster mode

2. Zabbix 6.0 LTS has a new Kubernetes monitoring function, which can collect indicators from multiple dimensions in the Kubernetes system:
• Automatic discovery and monitoring of Kubernetes nodes and pods
• Agentless collection of Kubernetes pods and node information
• Obtain high-level Kubernetes node hosts information
 

Zabbix 6.0 functional components:

●Zabbix Server
The zabbix server daemon process is the core component of Zabbix software, and Zabbix Agent reports availability, system integrity information and statistical information to it.
Zabbix Server is also the core repository for all configuration, statistics and operational information.
Zabbix Server is also the alarm center of the Zabbix monitoring system. Any anomalies in the monitored systems will be notified to the administrator.

The functionality of the basic Zabbix Server is broken down into three distinct components. They are: Zabbix server, Web frontend, database.

All configuration information of Zabbix is ​​stored in the database where the Server interacts with the Web front end. For example, when you add a monitoring item through the web front end (or API), it will be added to the monitoring item table in the database. Then, Zabbix server queries the valid item in the monitoring item table once per minute, and then stores it in the cache in Zabbix server. That's why it takes about two minutes for any changes made by the Zabbix frontend to show up in the latest data section.

●Database
All configuration information and data collected by Zabbix are persistently stored in the database.
Can support MySQL, PostgreSQL, Oracle, DB2, TimescaleDB and other databases.

●Web interface
The Web interface is a part of Zabbix Server, which is used to realize the display and configuration interface. Usually (but not necessarily) on the same physical machine as the Zabbix server.
Based on Apache/Nginx + PHP implementation, it only supports LAMP architecture in the early stage, and supports LNMP since Zabbix5.0.

●Zabbix Agent
client daemon process, deployed on the monitored target, used to actively monitor local resources and applications, and send the collected data to Zabbix Server. Zabbix Agent2 is supported from Zabbix5.0.

●Zabbix Proxy
The zabbix distributed proxy daemon process can replace Zabbix Server to collect performance and availability data. The deployment of Zabbix Proxy in Zabbix is ​​an optional part.
The deployment of Zabbix Proxy can well share the load of a single Zabbix Server.
It is usually used when monitoring more than 500 hosts, and a distributed monitoring architecture deployment is required.

●Java Gateway
Zabbix needs to use Java Gateway as an agent to obtain data from JAVA programs if it wants to monitor Tomcat service or other JAVA programs (such as Elasticsearch and ZooKeeper).

-------------------- Zabbix 6.0 Deployment--------------------
●System: CentOS 7 does not support Install Zabbix 6.0 server in yum mode

●Installation method: The Zabbix server adopts the method of compiling and installing, and the zabbix client adopts the method of yum installation


---------- Deploy zabbix server----------
//Close selinux and firewall
systemctl disable --now firewalld
setenforce 0
hostnamectl set-hostname zbx-server

1 Deploy Nginx + PHP environment and test
#Install nginx
cat > /etc/yum.repos.d/nginx.repo << 'EOF'
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos /$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF

yum clean all && yum makecache

yum install -y nginx

#安装 php
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install -y epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache php72w-ldap php72w-bcmath

#Modify nginx configuration


vim /etc/nginx/conf.d/zbx.conf
server {
  listen 80;
  server_name zbx.kgc.com;
  root /var/www/zbx;
  
  location / {
    index index.php;
  }
  
  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/zbx$fastcgi_script_name;
    include fastcgi_params;
  }
}

#Modify php configuration
vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx

vim /etc/php.ini
max_execution_time = 300 # 368 lines
max_input_time = 600 # 378 lines
post_max_size = 80M # 656 lines
date.timezone = Asia/Shanghai # 877 lines

#Create directory and test file
mkdir -p /var/www/zbx

vim /var/www/zbx/index.php
<?php
phpinfo();
?>

#Start service
systemctl enable --now nginx php-fpm

#Test access (hosts analysis)
Modify C:\Windows\System32\drivers\etc\hosts
192.168.50.25 zbx.kgc.com

Browser access: http://zbx.kgc.com/index.php

2. Deploying the database requires MySQL 5.7 or Mariadb 10.5 and above
#Configure Mariadb yum source
cat > /etc/yum.repos.d/mariadb.repo << EOF
[mariadb]
name = MariaDB
baseurl = http://mirrors.aliyun .com/mariadb/yum/10.5/centos7-amd64/
gpgkey = http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
enabled=1
EOF

Download and start the service

yum install -y mariadb-server mariadb

systemctl enable --now mariadb
 

#Initialize the database
mysql_secure_installation
Enter Enter -> n -> Y (set the root password, such as abc123) -> followed by Y all the way

mysql -u root -pabc123

#Create a database and specify a character
set CREATE DATABASE zabbix character set utf8 collate utf8_bin;

#Create zabbix database user and authorize
GRANT all ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix';
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
flush privileges;

#Import zabbix data to the database
Upload the source package zabbix-6.0.13.tar.gz to the /opt directory
cd /opt
tar xf zabbix-6.0.13.tar.gz

ls /opt/zabbix-6.0.13/database/mysql
data.sql  double.sql  history_pk_prepare.sql  images.sql  Makefile.am  Makefile.in  schema.sql

#Follow the smooth import database
cd /opt/zabbix-6.0.13/database/mysql
mysql -uroot -pabc123 zabbix < schema.sql
mysql -uroot -pabc123 zabbix < images.sql
mysql -uroot -pabc123 zabbix < data.sql
mysql - uroot -pabc123 zabbix < double.sql
mysql -uroot -pabc123 zabbix < history_pk_prepare.sql

/Compile and install zabbix Server server
#Install dependency packages, create zabbix users
yum install -y mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent- devel openldap-devel libcurl-devel fping gcc gcc-c++ make

useradd -s /sbin/nologin -M zabbix

#Compile and install
cd /opt/zabbix-6.0.13/

./configure \
--sysconfdir=/etc/zabbix/ \
--enable-server \
--with-mysql \
--with-net-snmp \
--with-libxml2 \
--with-ssh2 \
--with-openipmi \
--with-zlib \
--with-libpthread \
--with-libevent \
--with-openssl \
--with-ldap \
--with-libcurl \
--with-libpcre

make install

Check version
zabbix_server --version

#Modify the zabbix server configuration file, modify the database password
vim /etc/zabbix/zabbix_server.conf 
......
LogFile=/var/log/zabbix_server.log # 38 lines, specify the zabbix log path
DBPassword=zabbix # 123 lines , specify the password for the zabbix database

#Prepare systemctl service management file
cat > /usr/lib/systemd/system/zabbix-server.service << EOF
[Unit]
Description=Zabbix Server with MySQL DB
After=syslog.target network.target mysqld.service

[Service]
Type=simple
ExecStart=/usr/local/sbin/zabbix_server -f
User=zabbix

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable --now zabbix-server

netstat -lntp | grep 10051 #zabbix_server listens on port 10051 by default
 

//Deploy the Web front end and access
cp -r /opt/zabbix-6.0.13/ui/* /var/www/zbx

chown -R nginx.nginx /var/www/zbx

Browser access: http://zbx.kgc.com/ 

[Default language] Select Chinese (zh_CN), click Next
[Password] enter zabbix, click Next
[Zabbix host name] enter Zabbix-monitoring; [Default Time Zone] select Asia/Shanghai, click Next

After the installation is complete, the default login account and password are: Admin/zabbix

//Install zabbix client to realize zabbix server self-monitoring
rpm -ivh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
sed -i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

#zabbix 5.0 version starts to adopt the new version client agent2 developed by golang language
yum install -y zabbix-agent2

systemctl enable --now zabbix-agent2

netstat -lntp | grep 10050 #Client zabbix_agent2 listens to port 10050 by default

//Solve zabbix-server Web page Chinese garbled problem
yum install -y wqy-microhei-fonts

\cp -f /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /var/www/zbx/assets/fonts/DejaVuSans.ttf

Refresh the browser page
 

 Add zabbix client host - (client configuration)
systemctl disable --now firewalld
setenforce 0
hostnamectl set-hostname zbx-agent01


//Both server and client configure time synchronization
yum install -y ntpdate
ntpdate -u ntp.aliyun.com


//Both server and client set hosts parsing
cat > /etc/hosts << EOF
192.168.80.20 zbx-server
192.168.80.30 zbx-agent01
EOF

//Set the download source of zabbix, install zabbix-agent2
rpm -ivh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
sed - i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

yum install -y zabbix-agent2

//Modify the agent2 configuration file
vim /etc/zabbix/zabbix_agent2.conf
......
Server=192.168.50.25 #80 line, specify the IP address of the zabbix server
ServerActive=192.168.50.25 #133 line, specify the IP of the zabbix server Address
Hostname=zbx-agent01 #144 line, specify the hostname of the current zabbix client

//启动 zabbix-agent2
systemctl start zabbix-agent2
systemctl enable zabbix-agent2

netstat -natp | grep zabbix
tcp6       0      0 :::10050                :::*                    LISTEN      43654/zabbix_agent2 


//Verify the connectivity of zabbix-agent2 on the server side (operate on the server side)
yum install -y zabbix-get #Install the command for zabbix to actively obtain data

zabbix_get -s '192.168.80.30' -p 10050 -k 'agent.ping'
1

zabbix_get -s '192.168.80.30' -p 10050 -k 'system.hostname'
zbx-agent01
 

#Common key value
agent.ping #Whether the server and client are connected, return 1 means reachable, return non means unreachable
system.hostname #system host name
agent.hostname #client host name
net.if.in[if ,<mode>] #Network interface incoming traffic statistics, if indicates the name of the network card, and the parameter with <> indicates that it can be omitted net.if.out
[if,<mode>] #Network interface outgoing traffic statistics
proc.num[< name>,<user>,<state>,<cmdline>,<zone>] #process number
net.tcp.port[<ip>,port] #Check whether a tcp connection can be established to the specified port, return 0 means it cannot connect , return 1 means can connect
 

//Add the agent host to the web page

Click [Host] in [Configuration] on the left menu bar, click [Create Host]
[Host Name] enter zbx-agent01
[Visible Name] enter zbx-agent01-192.168.50.26
[Template] search for Linux, select Linux by Zabbix agent
[Group] Select Linux servers
[Interfaces] Click to add client, [IP address] enter 192.168.50.26

#Monitoring template download address
https://share.zabbix.com/
https://monitoringartist.github.io/zabbix-searcher/
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates

 Three custom monitoring content
zabbix monitoring template Daquan:

www.zabbix.com/integration…

Monitoring case 1: Number of login detection 
requirements: A company has confirmed that the zabbix monitoring system has been installed, and the number of logins of a certain server is limited to no more than 3, and an alarm message will be sent if more than 3. The server (192.168.50.26) has been added to the zabbix monitoring system

Specific steps 
Step 1: Create a custom key on the client
//Create a custom key on the client 1. Specify the linux command who | wc -l
to be executed 2. Create a zabbix monitoring item configuration file for custom key vim /etc/zabbix/zabbix_agent2.conf #You can create a custom monitoring item configuration file in the zabbix_agent2.d directory 281 Include=/etc/zabbix/zabbix_agent2.d/*.conf #The format of the custom monitoring item is as follows 321 # Format: UserParameter=<key>,<shell command> cd /etc/zabbix/zabbix_agent2.d/ vim UserParameter_login.conf UserParameter=login.user,who|wc -l systemctl restart zabbix-agent2 3. Verify the new one on the server side Monitoring item zabbix_get -s '192.168.50.26' -p 10050 -k 'login.user'

 






 

 


 

 

 //Create a custom monitoring item template on the Web page

1. Create a template
Click [Template] in [Configuration] on the left menu bar, click [Create Template]
[Template Name] set to Template Login User
[Visible Name] set to Template Login User
[Group] select Template
[Description] Customizable
Click [Add], and you can search for Template Login User in [Name]

2. Create monitoring items

Click the Template Login User template to enter
Click the upper menu bar [Monitoring Item], click [Create Monitoring Item] [
Name] set to Number of login users
[Key Value] set to login.user #The key value must be consistent with the custom monitoring item The settings in the configuration file are consistent
[Update interval] is set to 10s
[Historical data retention time] Storage period 30d #Retention time can be customized and set
Click [Add]

 
3. Create a trigger (when the monitoring item obtains the monitored value, compare it with the preset value of the trigger to determine whether it is an alarm)
Click [Trigger] on the upper menu bar, click [Create Trigger]


[Name] is set to Number of login users is greater than 3
[Severity] is set to general serious #According to the severity, you can customize the setting
[Expression] click Add, [Monitoring Item] click to select Number of login users, [Function] Select last(), [Result] select > 3, click [Insert]
and click [Add]

5. Create graphics

Click [Graphics] on the upper menu bar, click [Create Graphics]
[Name] set to Number of login users
[Width], [Height] can directly use the default value
[Monitoring Items] Click Add to check the relevant monitoring item Number of login users, 【Function】Choose the largest, others can keep the default value
Click【Add】

6. Associate the host with the template (a host can be associated with multiple templates)


Click [Host] in the left menu bar [Configuration], click the host you want to associate
[Template] to search for login, select Template Login User, and click [Update]

At this time, click [Host] in [Monitoring], click the [Graph] of your associated host, and you can view the relevant monitoring item indicators
 

5. Set email alarm

Click [Alarm Media Type] in [Management] on the left menu bar, click [Create Media Type] [
Name] set to qq_Email
[SMTP Server] set to smtp.qq.com
[SMTP Server Port] set to 25
[SMTP HELO] Set to qq.com
【SMTP email】Set to your own email address, for example [email protected]
【Authentication】Select username and password
【User name】Set to your own email address, for example [email protected]
【Password】You can Log in to the QQ mailbox page, click [Settings] --> [Generate Authorization Code] in [Account], and get the authorization code via SMS. [
Description] can be customized.
Click [Message templates] on the upper menu bar, click [Add], [Message type] select the question, click [Update]
click [Add], and test the function

 test

Click [User settings]-->[Profile]-->[Alarm Media] on the left menu bar, click [Add] [
Type] select qq_Email
[Recipient] and set it to [email protected]
[When enabled] set it to 1-7, 00:00-24:00
[Use if severity exists] Check the required severity
and click [Add]
and then click [Update]

Click [Configuration]->[Action]->[Trigger actions] on the left menu bar,
select the corresponding action name and click to enter, click [Add] [
Type] to select trigger, [Operator] to select equal to, [Trigger] click Select Number of login users is greater than 3
Click [Add]
Check [Enabled]
Click [Update]
 

//Test email alarm
Increase the number of user logins of the test client to exceed the preset value of the trigger, check [Monitoring] --> [Dashboard], and confirm the alarm

 zabbix automatic discovery and automatic registration -
//zabbix automatic discovery (passive mode for agent2)
zabbix server actively discovers all clients, and then registers the client information on the server.
The disadvantage is that if the number of hosts in the defined network segment is large, the registration of zabbix server will take a long time and the pressure will be high.

(1) Make sure that the zabbix-agent2 service status on the client is normal
systemctl is-active zabbix-agent2.service 

 (2) Delete the original client host on the web page
Click [Host] in [Configuration] on the left menu bar, check the original client host, and click Delete

(3) Configure hosts on the server and client to resolve
vim /etc/hosts
192.168.50.25 zbx-server
192.168.50.26 zbx-agent01

 (4) Configure automatic discovery on the web page
1) Click [Automatic discovery] in [Configuration] on the left menu bar, and click [Create discovery rule]:

[Name] is set to mynetwork
[IP Range] is set to 192.168.50.1-254
[Update Interval] is set to 30s
[Check] Click [Add], [Check Type] select Zabbix client, [Port Range] is set to 10050, [ Key value] set to system.uname
[Device uniqueness criteria] Select IP address
[Host name] Select DNS name
[Visible name] Select host name
Check [Enabled], click [Update]

Click [Action] in [Configuration] in the left menu bar, select [Discovery Action] in the upper menu,
check [Auto discovery. Linux servers.], click [Enable],
click [Host] in [Configuration] in the left menu bar to refresh, and wait After a period of time, the automatically discovered client host can be refreshed

 4) You can view the zabbix log on the server side:
tail -f /var/log/zabbix_server.log

 zabbix automatically registers 
  zabbix agent2 will actively report its own information and send it to zabbix server.
The disadvantage is that zabbix agent2 may not be able to find the zabbix server due to incorrect configuration of the configuration file or network failure.

1. Environment preparation

Click [Discovery Action] in [Configuration] on the left menu bar, check the discovery rule, click Disable, click
[Host] in [Configuration] on the left menu bar, check the original client host, and click Delete

vim /etc/hosts
192.168.50.25 zbx-server
192.168.50.26 zbx-agent01
 

2. Modify the zabbix-agent2 configuration file (client configuration)
vim /etc/zabbix/zabbix_agent2.conf
......
HostnameItem=system.hostname #152 line, uncomment
 

egrep -v "^#|^$" /etc/zabbix/zabbix_agent2.conf

3. Configure automatic registration on the web page
Click [Action] in [Configuration] on the left menu bar, select [Auto Registration Action] in the upper menu, click [Create Action] [Name]
set to Auto registration
click [Add], [Type] Select the host name, [Operator] select Include, [Value] set to zbx-agent,
click [Operation] on the upper menu bar, click [Add], [Operation Type] select Add Host, click [Add]
and then click [Add], [Operation Type] Select Add to host group, [Host Group] select Linux servers, click [Add]
and then click [Add], [Operation Type] select Associate with template, [Template] search for Linux, select Linux by Zabbix agent , click [Add]
and click [Add] below

After waiting for a period of time, click [Host] in the left menu bar [Configuration] to refresh, and the automatically discovered client host can be refreshed

The role of deploying zabbix proxy server 
distributed monitoring:
Share the centralized pressure of the server
Solve the network delay problem between multiple computer rooms

(1) Installation of zabbix proxy server
//Set the download source of zabbix, install zabbix-proxy
rpm -ivh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4 .el7.noarch.rpm
sed -i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

yum install -y zabbix-proxy-mysql zabbix-sql-scripts zabbix-selinux-policy


//Deploy the database, MySQL 5.7 or Mariadb 10.5 and above are required
#Configure Mariadb yum source
cat > /etc/yum.repos.d/mariadb.repo << EOF
[mariadb]
name = MariaDB
baseurl = http://mirrors. aliyun.com/mariadb/yum/10.5/centos7-amd64/
gpgkey = http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
enabled=1
EOF

yum install -y mariadb-server mariadb

systemctl enable --now mariadb

#Initialize the database
mysql_secure_installation
Enter Enter -> n -> Y (set the root password, such as abc123) -> followed by Y all the way

mysql -u root -pabc123


#Create a database and specify a character set
CREATE DATABASE zabbix_proxy character set utf8 collate utf8_bin;


#Create zabbix database user and authorize
GRANT all ON zabbix_proxy.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix';
GRANT all ON zabbix_proxy.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
FLUSH PRIVILEGES;


//Import database information
rpm -ql zabbix-sql-scripts #Query the location of the sql file

cat /usr/share/zabbix-sql-scripts/mysql/proxy.sql | mysql -uroot -pabc123 zabbix_proxy

//Modify the zabbix-proxy configuration file
vim /etc/zabbix/zabbix_proxy.conf
Server=192.168.80.20 #32 line, specify the IP address of the zabbix server
Hostname=zbx-proxy #42 line, specify the host name of the current zabbix proxy server
DBPassword =zabbix #194 line, specify the password of the current database zabbix user

//启动 zabbix-proxy
systemctl start zabbix-proxy
systemctl enable zabbix-proxy


//Configure hosts on all hosts to resolve
vim /etc/hosts
192.168.80.20 zbx-server
192.168.80.30 zbx-agent01
192.168.80.13 zbx-proxy

//Configure the agent proxy (server) on the Web page

Click [Action] in [Configuration] on the left menu bar, check the automatic registration rule, click Disable, click
[Host] in [Configuration] in the left menu bar, check the original client host, and click Delete

Click [agent agent] in [Management] on the left menu bar, click [Create agent]
[agent agent name] enter zbx-proxy
[system agent mode] select active
[agent address] enter 192.168.50.24
and click [Add] 】


//Configure agent to use proxy (client)

1. Modify the agent2 configuration file
vim /etc/zabbix/zabbix_agent2.conf on the client side
......
Server=192.168.50.24 #80 line, specify the IP address of the zabbix proxy server
ServerActive=192.168.50.24 #120 line, specify IP address of zabbix proxy server

2. Configure on the Web page

Click [Host] in [Configuration] on the left menu bar, click [Create Host]
[Host Name] enter zbx-agent01
[Visible Name] enter zbx-agent01
[Template] search for Linux, select Linux by Zabbix agent
[Group] Select Linux server
[Interfaces] select client, [IP address] enter 192.168.50.26, [port] enter 10050
[monitored by agent] select zbx-proxy
and click [Add]

3. Restart the service on the client and proxy server respectively

systemctl restart zabbix-agent2

systemctl restart zabbix-proxy

After waiting for a period of time, click [Host] in the left menu bar [Configuration] to refresh, and check that the monitoring status of the client host is normal

View the log on the server
tail -f /var/log/zabbix/zabbix_proxy.log

-------------------- Deploy Zabbix high availability cluster --------------------
The official high availability is only For the Zabbix Server part, the database part and the front-end part need to adopt high-availability solutions in their respective fields.
 

//server configuration

By default, HA is off. The configuration of the HA part is at the bottom of the configuration file: High availability cluster parameters part.

#Master node Zabbix Server configuration
vim /etc/zabbix/zabbix_server.conf
......
DBHost=192.168.50.25
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
......
HANodeName=zbx-server01 #Set to current Node host name
NodeAddress=192.168.50.25:10051 #Set as node IP

 systemctl restart zabbix-server

#The master node authorizes remote login permissions to the database
mysql -uroot -pabc123
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
FLUSH PRIVILEGES;

#Standby node Zabbix Server configuration

vim /etc/zabbix/zabbix_server.conf
......
DBHost=192.168.50.24
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
......
HANodeName=zbx-server02
NodeAddress=192.168.50.24:10051


systemctl restart zabbix-server

//client configuration

vim /etc/zabbix/zabbix_agent2.conf 
......
Server=192.168.80.20,192.168.80.30
ServerActive=192.168.80.20;192.168.80.30        

    #Note, the connector of ServerActive is ';', not ',

Guess you like

Origin blog.csdn.net/zl965230/article/details/131043279