Zabbix automatic discovery and automatic registration, deployment of zabbix proxy server and deployment of Zabbix high availability cluster

Table of Contents

  • One, zabbix automatic discovery
  • Two, zabbix automatic registration (active mode for agent2)
  • 3. Deploy zabbix proxy server
  • 4. Deploy Zabbix high availability cluster
  • 5. Zabbix monitors Windows system
  • 6. Zabbix monitors java applications
  • Seven, Zabbix monitoring SNMP

1. zabbix automatic discovery

zabbix auto-discovery (passive mode for agent2)
The 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.

systemctl disable --now firewalld
setenforce 0
hostnamectl set-hostname zbx-agent02
#Set the download source of zabbix, install zabbix-agent2
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
 
yum clean all
yum install zabbix-agent2 zabbix-agent2-plugin-*
systemctl restart zabbix-agent2
systemctl enable zabbix-agent2

#Add dns on the server and zabbix-agent02
vim /etc/hosts

192.168.154.10zbx-server
192.168.154.11 zbx-agent01
192.168.154.12 zbx-agent02

Modify agent2 configuration file

vim /etc/zabbix/zabbix_agent2.conf
?…
Server=192.168.154.10 #80 line, specify the IP address of the zabbix server
ServerActive=192.168.154.10 #133 line, specify the IP address of the zabbix server
Hostname=zbx-agent02 #144 line, specify the hostname of the current zabbix client

Start zabbix-agent2

systemctl restart zabbix-agent2
systemctl enable zabbix-agent2

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

Configuring Autodiscovery on Web Pages
Click [Auto Discovery] in [Configuration] on the left menu bar, and click [Create Discovery Rule]
[Name] set to mynetwork
[IP range] set to 192.168.154.1-254
【Update Interval】Set to 30s
[Check] Click [Add], [Check Type] select Zabbix client, [Port Range] is set to 10050, [Key Value] is set to system.uname
【Equipment Uniqueness Criteria】Choose an IP address
【Host name】Select DNS name
[Visible Name] Select Host Name
Check [Enabled], click [Add]

Click [Action] in [Configuration] on the left menu bar, and select [Discover Action] from the upper menu
Check [Auto discovery. Linux servers.], click [Enable]

Click [Host] in [Configuration] on the left menu bar to refresh, and wait for a period of time to refresh the automatically discovered client host

You can view zabbix logs on the server side

tail -f /var/log/zabbix_server.log

2. zabbix automatic registration (active mode for agent2)

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.

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

Modify zabbix-agent2 configuration file

#Do both clients
vim /etc/zabbix/zabbix_agent2.conf
?…
HostnameItem=system.hostname #152 line, uncomment
...

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



Configure auto-registration on the web page
Click [Action] in [Configuration] on the left menu bar, select [Automatic Registration Action] in the upper menu, and click [Create Action]
【Name】Set to Auto registration
Click [Add], [Type] select host name, [Operator] select include, and [Value] set to zbx-agent
Click [Operation] on the upper menu bar, click [Add], select [Operation Type] to add a host, and click [Add]
Then click [Add], [Operation Type] select Add to Host Group, [Host Group] select Linux servers, and click [Add]
Then click [Add], [Operation Type] select Associate with template, [Template] search for Linux, select Linux by Zabbix agent, and click [Add]
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







3. Deploy zabbix proxy server

The role of distributed monitoring:
●Sharing the centralized pressure of the server
●Solve the network delay problem between multiple computer rooms

Data flow: agent –> proxy –> server

Set zabbix download source, install zabbix-proxy

rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
yum clean all

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

Deployment 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

yum install -y mariadb-server mariadb

systemctl enable --now mariadb

Initialize the database

mysql_secure_installation
Enter respectively Enter -> n -> Y (set the root password, such as abc123) -> followed by Y all the way
mysql -u root -pabc123

#Create the database and specify the 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 zabbix-proxy configuration file

vim /etc/zabbix/zabbix_proxy.conf
Server=192.168.154.10 #32 line, specify the IP address of the zabbix server
Hostname=zbx-proxy #42 line, specify the hostname of the current zabbix proxy server
DBPassword=zabbix #194 line, specify the password of the current database zabbix user

Start zabbix-proxy

systemctl start zabbix-proxy
systemctl enable zabbix-proxy

Configure hosts resolution on all hosts

vim /etc/hosts
192.168.154.10zbx-server
192.168.154.11 zbx-agent01
192.168.154.12 zbx-agent02
192.168.154.13zbx-proxy

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

Click [Agent Agent] in [Management] in the left menu bar, and click [Create Agent]
[agent agent program name] input zbx-proxy
[System Agent Mode] Select Active
【Proxy Address】Enter 192.168.154.13
Click 【Add】

Configure agent to use proxy
1. Modify the agent2 configuration file on the client side

vim /etc/zabbix/zabbix_agent2.conf
?…
Server=192.168.154.13 #80 line, specify the IP address of the zabbix proxy server
ServerActive=192.168.154.13 #120 line, specify the IP address of the zabbix proxy server

2. Configure on the Web page
Click [Host] in [Configuration] on the left menu bar, and 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] input 192.168.154.30, [port] input 10050
[Monitored by agent] Select zbx-proxy
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 logs on the server side

tail -f /var/log/zabbix/zabbix_proxy.log

4. Deploy Zabbix high availability cluster

The official high-availability is only for the Zabbix Server part, and 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.154.10
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
?…
HANodeName=zbx-server01 #Set as the host name of the current node
NodeAddress=192.168.154.10:10051 #Set as node IP


systemctl restart zabbix-server


Client Configuration

vim /etc/zabbix/zabbix_agentd.conf
?…
Server=192.168.154.10,192.168.154.11
ServerActive=192.168.154.10;192.168.154.11
#Note, the connector of ServerActive is ';', not ','

5. Zabbix monitors Windows systems

1. Download the Windows client Zabbix agent 2
https://cdn.zabbix.com/zabbix/binaries/stable/6.0/6.0.13/zabbix_agent2-6.0.13-windows-amd64-openssl.msi

2. Install the client and configure
Double-click the client package to start the installation
【Host name】:WIN10-SERVER
[Zabbix server IP/DNS]: 192.168.154.10
【Agent listen port】: 10050
【Server or Proxy for active checks】: 192.168.154.10
Check【Add agent location to the PATH】

3. Add the host on the server web page and associate the template
Click [Host] in [Configuration] on the left menu bar, and click [Create Host]
【Host Name】Enter win10-agent01
【Visible Name】Enter win10-agent01-192.168.154.30
[Template] Search for windows, select Windows by Zabbix agent
【Group】Enter windows and select windows(new)
[Interfaces] Click to add client, [IP address] input 192.168.154.30, [port] input 10050

6. Zabbix monitors java applications

1. The client enables the java jmxremote remote monitoring function

Upload the tomcat package to the /opt directory
cd /opt
tar zxvf apache-tomcat-9.0.16.tar.gz
mv apache-tomcat-9.0.16 /usr/local/tomcat

Configure java jmxremote remote monitoring function

vim /usr/local/tomcat/bin/catalina.sh
...... #position before cygwin=false
CATALINA_OPTS="$CATALINA_OPTS\
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=12345\
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=192.168.80.30" #tomcat server address

cygwin=false

Start the service, check the port

/usr/local/tomcat/bin/startup.sh

netstat -lntp | grep 12345

2. Install zabbix-java-gateway on the server side

yum install -y zabbix-java-gateway

systemctl enable --now zabbix-java-gateway.service

netstat -lntp | grep 10052 #zabbix-java-gateway listens on port 10052 by default

3. Modify the server zabbix-server configuration

vim /etc/zabbix/zabbix_server.conf
?…
JavaGateway=127.0.0.1 # Line 317, specify the IP address of zabbix-java-gateway
StartJavaPollers=5 # 333 lines, open the number of poller processes used to collect java data

systemctl restart zabbix-server

ps -ef | grep zabbix_server | grep java

4. Add the host on the server web page and associate the template
Click [Host] in [Configuration] on the left menu bar, and click zbx-agent01
[Template] Search JMX, select Generic Java JMX
[Interfaces] click to add JMX, [IP address] input 192.168.154.11, [port] input 12345
Click 【Update】
Added JXM monitoring method for Zabbix server availability after waiting for a while

Monitor other java applications

java -Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=12345 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=192.168.154.10" \
-jar XXX.jar

7. Zabbix monitoring SNMP

SNMP, Simple Network Management Protocol, is often used to monitor network devices, and can also monitor devices that support the SNMP function (windows, linux, printers, etc.).

1. Install the snmp monitoring program on the server

yum install -y net-snmp net-snmp-utils

2. Modify the snmp configuration file and start the service

vim /etc/snmp/snmpd.conf
?…
view systemview included .1 #57 line, add this configuration

systemctl start snmpd

3. Use the snmpwalk command to test

snmpwalk -v 2c -c public 127.0.0.1 sysname
SNMPv2-MIB::sysName.0 = STRING: zbx-server
–v 1|2c|3: Specifies the SNMP protocol version, v2c is authenticated by community name, and v3 is authenticated by user name and password
–c: Specify the community name (password between devices)
sysname: the key of snmp, used to check the system name; SysDesc is used to check the system information

4. Configure snmp monitoring on the web page
Click [Host] in [Configuration] on the left menu bar, and click Zabbix server
[Template] Unlink and clean existing template Linux by Zabbix agent
Search for Generic, select Generic by SNMP
【Group】Search net, select net(new)
[Interfaces] Click [Add] to select SNMP, [IP address] input 127.0.0.1, [Port] input 161
【SNMP version】Select SNMPv2
【SNMP community】Enter {$SNMP_COMMUNITY}

Click [Macro] on the upper menu bar
Select [Host Macro]
[Macro] input {$SNMP_COMMUNITY}, [Value] input public (consistent with the community name set by the network device), [Description] input the team name of the network device snmp
Click 【Update】
After waiting for a period of time, the availability of Zabbix server becomes SNMP monitoring method