Zabbix essays: high availability

This paper realizes high availability through the native HA function of Zabbix (we won't discuss the high availability of database and front-end for the time being, which will be discussed in the next issue). This paper is demonstrated in the LAMP environment, and other environments can refer to the previous articles.

text

Article environment

  • CentOS 8.5
  • Zabbix 6.0 LTS RC1
  • Mariadb 10.6.5 / Postgresql 13
  • Nginx / Apache

Structure diagram of this paper

Physical environment of this paper

  • Zabbix Front 01 192.168.0.228
  • Zabbix Front 02 192.168.0.39
  • Zabbix Server 01 192.168.0.200
  • Zabbix Server 02 192.168.0.125
  • Zabbix DB 192.168.0.103

Premise preparation

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
systemctl stop firewalld  && systemctl disable firewalld

Front end part

cat <<EOF > /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.5/rhel/8/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591


[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
EOF
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
dnf install  zabbix-web-mysql zabbix-apache-conf  zabbix-agent2 -y
systemctl start httpd php-fpm 
systemctl enable httpd php-fpm

effect

Theoretically, it should be accessible, otherwise there will be an error in the installation.

Database part

cat <<EOF > /etc/yum.repos.d/mariadb.repo
# MariaDB 10.6 CentOS repository list - created 2022-01-16 15:10 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://mirrors.cloud.tencent.com/mariadb/yum/10.6/centos8-amd64
module_hotfixes=1
gpgkey=https://mirrors.cloud.tencent.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

mount this database

dnf -y install mariadb-server

Start database

systemctl start mariadb && systemctl enable mariadb

Initialize database

mariadb-secure-installation

Create database and user

create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'xiaoyu123';
grant all privileges on zabbix.* to zabbix@'%' identified by 'xiaoyu123'  with grant option;
quit;

Install Zabbix source

cat <<EOF > /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.5/rhel/8/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591


[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
EOF
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX

Install Zabbix database related packages

dnf -y install zabbix-sql-scripts zabbix-agent2

Import Zabbix database file

zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix

Zabbix Server section

Install Zabbix source

cat <<EOF > /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.5/rhel/8/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591


[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
EOF
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX

Install Zabbix Server

dnf -y install zabbix-server-mysql  zabbix-agent2

Modify Zabbix Server configuration

vim /etc/zabbix/zabbix_server.conf

Since the components used are distributed deployment, the database part needs special settings.

Turn to the last part of the configuration and find the High availability cluster parameters section, which is the native HA configuration. The hanodername part is the cluster node name, and the NodeAddress part must be set to the IP address of the corresponding host, otherwise the host cannot be found during switching

Start Zabbix Server

systemctl start zabbix-server zabbix-agent2 
systemctl enable zabbix-server zabbix-agent2

effect

Front end part

Switching effect

Restart the service at the main

service zabbix-server restart

Simulate sudden power failure

At this time, the performance will not be switched immediately. It will wait for one minute to restart the standby machine. The default is failover_delay is 1 minute, minimum 10S,

HA part configuration description

Adjusting the failover duration is currently available only through zabbix_server command adjustment

zabbix_server -R ha_set_failover_delay=10s

appendix

server configuration

server=127.0.0.1,10.0.0.1

ServerActive configuration

server=127.0.0.1;10.0.0.1

Disable HA

Note the high availability part

Command at startup

zabbix_server -R

  • ha_status
  • ha_remove_node=target
  • ha_set_failover_delay=delay

last The HA function of Zabbix 6.0 is relatively simple to configure, but there are still many deficiencies. For example, it is unable to provide EIP function. When specifying the agent, it is necessary to specify two IPS, which is a little similar to the previous multi write. Secondly, the configuration synchronization cannot be achieved. In the actual test, if the configuration of the standby machine is low or the configuration is not optimized, the server will hang, However, compared with the previous third-party scheme, it is still much stronger. After all, it does not rely on third-party components, and the switching is sensitive. At present, the official release of 6.0 LTS RC1 version can be predicted that there will not be much adjustment. In the subsequent versions, we hope to continuously optimize ha functions and truly realize complete high availability.

Added by Dvector on Wed, 16 Feb 2022 13:47:52 +0200