This deployment document applies to CentOS 8.X/RHEL 8.X/Anolis OS 8.X/AlmaLinux 8.X/Rockey Linux 8.X.
The native HA solution has finally arrived, and compared to the previous Keepalived solution, the native solution configuration is much simpler.
Zabbix HA requires at least two Zabbix Server nodes to achieve high availability and failover of HA clusters. In the same Zabbix HA cluster, only one instance or node is active, and the standby node does not perform data collection, processing, or other tasks, does not listen on ports, and maintains a minimal database connection.
HA nodes are divided into the following states:
- Active
- Standby (Standby)
- Unavailable (not available)
- Stopped
Chinese version of the interface translates Active into active, which is not very accurate.
About TimescaleDB
It's fine when the data is kept in Zabbix server memory, but when the data needs to be written to (or read from) the database, no matter how good the caches and algorithms, if the database performance is significantly slower than the speed of collecting metrics, these algorithms are not helpful.
Data in the monitoring system is often inserted and then, in most cases, accessed in an aggregated manner (for example, displaying charts or calculating summary items), deleted periodically, and almost never updated. In addition, the values of the metrics that are typically monitored are sorted by time. This type of data is often referred to as time series data.
From a database perspective, time series data has the following characteristics:
- Time series data can be arranged on disk in a time-ordered block sequence.
- Time series data has at least one column of indexes that consist of time
- Most SQL select queries will use the WHERE, GROUP BY, or ORDER BY clauses with a time column.
- The retention policy for time series data is typically to delete in bulk, rather than deleting individual records.
So, is there a way to leverage time series databases without losing the flexibility of SQL? Not surprisingly, there is no one-size-fits-all answer, but there is one time series solution that achieves very close results – TimescaleDB.
TimescaleDB is a time series database based on postgreSQL database, which is deployed in the form of plug-in and upgraded with the version of PostgreSQL, with the following characteristics:
- Time series-based optimization;
- Automatic sharding (automatic sharding by time and space (chunk));
- Full SQL interface;
- Support vertical and horizontal expansion;
- Support time dimension and spatial dimension automatic partitioning. Spatial dimension refers to attribute fields (e.g. sensor ID, user ID, etc.);
- Support multiple SERVER, multiple CHUNK parallel query. Partitions are called chunks in TimescaleDB;
- Automatic adjustment of chunk size;
- Internal write optimization (batch commit, memory indexing, transaction support, data backfill);
- Complex query optimization (automatic selection of chunk based on query criteria, optimization of the most recent value get (minimized scan, similar to recursive convergence), limit clause pushdown to different; server, chunks, parallel aggregation operations);
- Use the existing PostgreSQL features (support GIS, JOIN, etc.) for convenient management (stream replication, PITR);
- Support for automatic time-based retention policies (automatic deletion of old data);
Zabbix fully supports TimescaleDB from version 5.0 and is optimized for its features. Automatically compresses historical data storage, saving 50-70% of storage space and automatic partitioning. When cleaning historical data through Zabbix Housekeeper, the corresponding partitions are directly cleaned, which greatly improves the cleaning efficiency of historical data. It is recommended that the timescaleDB scheme be used for new systems.
Tips: After the zabbix version 6.0 is installed, 7 days of historical data compression is enabled by default.
environment
- System: Rockey Linux 8.5
- Databases: PostgreSQL13.6, TimescaleDB 2
host name | IP | illustrate |
test-zbx-1 | 192.168.70.52 | server |
test-zbx-2 | 192.168.70.53 | |
test-zbx-3 | 192.168.70.54 | |
test-zbx-db | 192.168.70.55 | PostgreSQL、TimescaleDB |
Database deployment
Install PostgreSQL
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf clean all && dnf make cache
dnf -qy module disable postgresql
dnf install -y postgresql13-server
Install TimescaleDB
tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
[timescale_timescaledb]
name=timescale_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/$(rpm -E %{rhel})/\$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOL
dnf install timescaledb-2-postgresql-13 -y
Initialize PostgreSQL
/usr/pgsql-13/bin/postgresql-13-setup initdb
Start the PostgreSQL server
systemctl enable --now postgresql-13
Add TimescaleDB and configure the parameters
timescaledb-tune --pg-config=/usr/pgsql-13/bin/pg_config
The interactive screen will appear, all the way y, this step will adjust the PostgreSQL configuration parameters according to the current machine configuration, and load the Timescaledb plugin library.
Restart PostgreSQL to take effect.
systemctl restart postgresql-13
To create a Zabbix user:
sudo -u postgres createuser --pwprompt zabbix
Create a zabbix database:
sudo -u postgres createdb -O zabbix zabbix
To enable the TimescleDB plugin for a Zabbix database:
echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix
systemctl restart postgresql-13
Download the source code and import it into the database:
cd /opt
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.0.tar.gz
tar zxf zabbix-6.0.0.tar.gz
cd zabbix-6.0.0/database/postgresql/
useradd zabbix
# 导入数据
cat schema.sql |sudo -u zabbix psql zabbix
cat images.sql |sudo -u zabbix psql zabbix
cat data.sql |sudo -u zabbix psql zabbix
# 导入TimescleDB表配置sql
cat timescaledb.sql |sudo -u zabbix psql zabbix
Modify the configuration to allow remote connections:
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /var/lib/pgsql/13/data/postgresql.conf
sed -i 's/#port = 5432/port = 5432/g' /var/lib/pgsql/13/data/postgresql.conf
sed -i 's/max_connections = 100/max_connections = 500/g' /var/lib/pgsql/13/data/postgresql.conf
Configure to use md5 authentication, modify /var/lib/pgsql/13/data/pg_hba.conf, and add the following information to #IPv4 local connections
host all all 0.0.0.0/0 md5
Restart pgsql:
systemctl restart postgresql-13
Server deployment
All three nodes execute
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
dnf clean all
dnf install zabbix-server-pgsql zabbix-web-pgsql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent2
Modify the configuration file /etc/zabbix/zabbix_server.conf:
DBPassword=password
DBHost=192.168.70.55
# 配置当前节点主机名
HANodeName=test-zbx-1
# 配置当前节点ip:端口
NodeAddress=192.168.70.52:10051
Edit the configuration file /etc/nginx/conf.d/zabbix.conf:
listen 80;
Tips: You also need to delete the port 80 related configuration in /etc/nginx/nginx.conf, otherwise the Zabbix frontend will not be opened.
Start the Zabbix server and agent processes
Start the Zabbix server and agent processes and set up boot-on for them:
systemctl restart zabbix-server zabbix-agent2 nginx php-fpm
systemctl enable zabbix-server zabbix-agent2 nginx php-fpm
Configure the front end
Resolve garbled code issues. Manually upload local Windows fonts (such as Microsoft Yahei) to zabbix server's /usr/share/zabbix/assets/fonts/, usually Win10 font files under the C:\Windows\Fonts path.
cd /usr/share/zabbix/assets/fonts
mv graphfont.ttf graphfont.ttf.backup
ln -s msyh.ttc graphfont.ttf
Start the service:
systemctl restart zabbix-server zabbix-agent2 nginx php-fpm
systemctl enable zabbix-server zabbix-agent2 nginx php-fpm
From the /var/log/zabbix/zabbix_server.log log file, you can see that the test-zbx-1 status is active:
HA manager started in active mode
Test-zbx-2, test-zbx-3 status is standby:
"test-zbx-2" node started in "standby" mode
"test-zbx-3" node started in "standby" mode
Front-end configuration
Connect to the newly installed Zabbix frontend: http://server_ip_or_name
Select Chinese:

Prerequisite detection (the best language in the world):
To configure a DB connection:
Time Zone Select Shanghai:
Installation complete, junior
Default username password: Admin/zabbix:
Can be viewed in Reports - System Information:
Configure Agent
The HA scenario requires all server node addresses to be configured in the Agent configuration file /etc/zabbix/zabbix_agent2.conf to Server and ServerActive:
Server=192.168.70.52,192.168.70.53,192.168.70.54
ServerActive=192.168.70.52,192.168.70.53,192.168.70.54
Restart agent
systemctl restart zabbix-agent2
Verify HA
Currently test-zbx-1 is Active, which is deactivated.
execute:
systemctl stop zabbix-server
It can be seen that the states of test-zbx-1 and test-zbx-3 have changed, the state of test-zbx-1 has become Stopped, and the state of test-zbx-3 has become Active.
At the same time, test-zbx-3 began to work as a server, and data acquisition was normal.
Reprinted in Blog Garden https://www.cnblogs.com/Rohn/p/15927189.html