不負眾望,Zabbix 6.0 LTS終于更新了,原生支持了HA高可用部署!
TimescaleDB
TimescaleDB基于PostgreSQL數(shù)據(jù)庫打造的一款時序數(shù)據(jù)庫,插件化的形式部署,隨著PostgreSQL的版本升級而升級,具備以下特點:
- 基于時序優(yōu)化;
- 自動分片(按時間、空間自動分片(chunk));
- 全SQL接口;
- 支持垂直于橫向擴展;
- 支持時間維度、空間維度自動分區(qū)。 空間維度指屬性字段(例如傳感器ID,用戶ID等);
- 支持多個SERVER,多個CHUNK的并行查詢。 分區(qū)在TimescaleDB中被稱為chunk;
- 自動調(diào)整CHUNK的大??;
- 內(nèi)部寫優(yōu)化(批量提交、內(nèi)存索引、事務支持、數(shù)據(jù)倒灌);
- 復雜查詢優(yōu)化(根據(jù)查詢條件自動選擇chunk,最近值獲取優(yōu)化(最小化的掃描,類似遞歸收斂),limit子句pushdown到不同的; server,chunks,并行的聚合操作);
- 利用已有的PostgreSQL特性(支持GIS,JOIN等),方便的管理(流復制、PITR);
- 支持自動的按時間保留策略(自動刪除過舊數(shù)據(jù));
Zabbix 從5.0版本開始全面支持TimescaleDB,并針對其特性做了優(yōu)化??勺詣訅嚎s歷史數(shù)據(jù)存儲,節(jié)省50-70%的存儲空間,同時具備自動分區(qū)功能。通過Zabbix Housekeeper清理歷史數(shù)據(jù)時直接清理對應的分區(qū),大大提高了歷史數(shù)據(jù)的清理效率,建議新建系統(tǒng)采用TimescaleDB方案。
環(huán)境準備
角色 | 配置 | 操作系統(tǒng) | IP | 版本 |
Zabbix Server + WEB | 1 CPU + 2GB RAM | Rocky Linux release 8.5 | 192.168.176.190 | PHP 7.2.34 nginx/1.20.2 Zabbix 6.0 LTS |
Zabbix DB | 1 CPU + 2GB RAM | Rocky Linux release 8.5 | 192.168.176.215 | postgresql13 |
安裝完操作系統(tǒng)后,需要做一些初始化配置(記得防火墻放行業(yè)務端口或直接關閉系統(tǒng)防火墻)。
yum update -y
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
dnf install tar wget -y
setenforce 0
rm -rf /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Zabbix DB配置
Zabbix 6.0 LTS目前支持PostgreSQL 13不支持最新的14版本,本次使用PostgreSQL 13 + TimescaleDB。
安裝PostgreSQL
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install -y postgresql13-server
安裝TimescaleDB
添加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
安裝TimescaleDB包;
dnf install timescaledb-2-postgresql-13 -y
初始化PostgreSQL;
/usr/pgsql-13/bin/postgresql-13-setup initdb
啟動PostgreSQL server;
systemctl enable --now postgresql-13
添加TimescaleDB并配置參數(shù),會出現(xiàn)交互畫面,一路y 即可,此步驟會根據(jù)當前機器配置,調(diào)整PostgreSQL配置參數(shù),并加載Timescaledb插件庫;
timescaledb-tune --pg-config=/usr/pgsql-13/bin/pg_config
重啟PostgreSQL生效;
systemctl restart postgresql-13
建立Zabbix用戶及數(shù)據(jù)庫,此處是需要輸入數(shù)據(jù)庫zabbix用戶的密碼,輸入二次后確認。此處配置密碼為: Sword@2021,后續(xù)zabbix server連接數(shù)據(jù)庫使用這個密碼,用戶為zabbix;
sudo -i -u postgres createuser --pwprompt zabbix
創(chuàng)建zabbix數(shù)據(jù)庫;
sudo -i -u postgres createdb -O zabbix zabbix
為Zabbix數(shù)據(jù)庫啟用TimescleDB插件;
echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -i -u postgres psql zabbix
systemctl restart postgresql-13
如果看到以下的內(nèi)容,表示配置成功!
[root@zbx-db1 ~]# echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -i -u postgres psql zabbix
WARNING:
WELCOME TO
_____ _ _ ____________
|_ _(_) | | | _ \ ___ \
| | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ /
| | | | _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \
| | | | | | | | | __/\__ \ (_| (_| | | __/ |/ /| |_/ /
|_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/
Running version 2.6.0
For more information on TimescaleDB, please visit the following links:
1. Getting started: https://docs.timescale.com/timescaledb/latest/getting-started
2. API reference documentation: https://docs.timescale.com/api/latest
3. How TimescaleDB is designed: https://docs.timescale.com/timescaledb/latest/overview/core-concepts
Note: TimescaleDB collects anonymous reports to better understand and assist our users.
For more information and how to disable, please see our docs https://docs.timescale.com/timescaledb/latest/how-to-guides/configuration/telemetry.
CREATE EXTENSION
下載Zabbix 6.0beta1源碼并導入數(shù)據(jù)庫
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.1.tar.gz
tar -zxf zabbix-6.0.1.tar.gz
cd zabbix-6.0.1/database/postgresql
useradd zabbix
依次按照順序?qū)肴齻€Zabbix sql文件;
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
導入成功后會后如下提示;
[root@zbx-db1 postgresql]# cat timescaledb.sql |sudo -u zabbix psql zabbix
could not change directory to "/root/zabbix-6.0.1/database/postgresql": Permission denied
NOTICE: PostgreSQL version 13.6 is valid
NOTICE: TimescaleDB extension is detected
NOTICE: TimescaleDB version 2.6.0 is valid
NOTICE: TimescaleDB is configured successfully
DO
[root@zbx-db1 postgresql]#
修改配置允許遠程連接;
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 = 25/max_connections = 100/g' /var/lib/pgsql/13/data/postgresql.conf
配置使用md5方式認證;
vim /var/lib/pgsql/13/data/pg_hba.conf
添加如下信息到# IPv4 local connections之后
host all all 0.0.0.0/0 md5
重啟pgsql;
systemctl restart postgresql-13
Zabbix Server
dnf --enablerepo=powertools install OpenIPMI-devel -y
dnf install make wget chrony gcc curl-devel net-snmp-devel \
libxml2-devel libevent-devel pcre-devel -y
由于后端采用PostgreSQL數(shù)據(jù)庫,因此需要安裝PostgreSQL的開發(fā)包;
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install -y postgresql13-devel -y
安裝編譯Zabbix-server;
yum -y install net-snmp net-snmp-devel curl curl-devel perl-DBI net-snmp-utils
groupadd zabbix
useradd -g zabbix -s /sbin/nologin zabbix
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.1.tar.gz
tar -zxf zabbix-6.0.1.tar.gz
cd zabbix-6.0.1
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent \
--with-postgresql=/usr/pgsql-13/bin/pg_config --enable-ipv6 --with-net-snmp \
--with-libcurl --with-libxml2 --with-openssl
make install
配置Zabbix-server數(shù)據(jù)庫連接;
sed -i 's/# DBHost=localhost/DBHost=192.168.176.215/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/# DBPassword=/DBPassword=Sword@2021/g' /usr/local/zabbix/etc/zabbix_server.conf
Zabbix 6.0 LTS 增加了二個關于HA的配置參數(shù),建議配置,HANodeName修改為主機名,這里最好配置唯一; NodeAddress為節(jié)點地址,這里配置為實際ip+默認的10050端口;
sed -i 's/# HANodeName=/HANodeName=zbx-node1/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/# NodeAddress=localhost:10051/NodeAddress=192.168.176.190:10051/g' /usr/local/zabbix/etc/zabbix_server.conf
創(chuàng)建Zabbix Server啟動腳本;
tee /lib/systemd/system/zabbix-server.service <<EOL
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c \$CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
EOL
創(chuàng)建Zabbix Agent啟動腳本;
tee /lib/systemd/system/zabbix-agent.service <<EOL
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c \$CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
EOL
以下配置fping用于Zabbix簡單檢查 ;
yum install epel-release.noarch
yum install fping
chown root:zabbix /usr/sbin/fping
chmod 710 /usr/sbin/fping
chmod ug+s /usr/sbin/fping
#修改/usr/local/zabbix/etc/zabbix_server.conf,刪除FpingLocation=/usr/sbin/fping前的注釋。
使用以下命令啟動Zabbix Server及Zabbix Agent。
systemctl enable --now zabbix-server
systemctl enable --now zabbix-agent
Zabbix Web
自Zabbix 5.0 版本開始,Zabbix 前端需 PHP 7.2 及以上版本。 不幸的是,老版本的 Debian 和 Ubuntu 只提供 PHP 低于 7.2 的版本,WEB環(huán)境使用lnmp.org 1.9測試版一鍵包部署。
將Zabbix web UI復制到站點根目錄
需要注意的是需要將php.ini中的max_input_time參數(shù)值調(diào)整為300;
mkdir /home/wwwroot/default/zabbix
cp -r -a ui/* /home/wwwroot/default/zabbix/
chown -R www:www /home/wwwroot/default/zabbix/
由于使用PostgreSQL,因此需要按照php的PostgreSQL擴展組件;
tar -jxvf php-7.2.34.tar.bz2
cd php-7.2.34/ext/pgsql
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pgsql=/usr/pgsql-13/
make && make install
cd ../pdo_pgsql/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-pgsql=/usr/pgsql-13/
make && make install
vim /usr/local/php/etc/php.ini
#刪除注釋
extension=pgsql.so
extension=pdo_pgsql.so
重啟php-fpm;
/etc/init.d/php-fpm restart
安裝中文語言包、檢查PHP模塊,主要注意一定不能在php.ini中禁用proc_open函數(shù),否則會導致pdo_pgsql()函數(shù)不可用;
yum reinstall glibc-common
yum install langpacks-zh_CN.noarch
[root@localhost ui]# locale -a
C
C.utf8
POSIX
zh_CN
zh_CN.gb18030
zh_CN.gbk
zh_CN.utf8
zh_HK
zh_HK.utf8
zh_SG
zh_SG.gbk
zh_SG.utf8
zh_TW
zh_TW.euctw
zh_TW.utf8
[root@zbx-node1 pdo_pgsql]# php -m | grep pgsql
pdo_pgsql
pgsql
接下來就是web界面的安裝,按照提示一步步操作即可。
引用參考
https://cloud.tencent.com/developer/article/1941527
https://codeantenna.com/a/4DtvUXnoi8
https://www.cnblogs.com/AngryMushroom/p/13454939.html
https://lnmp.org/download.html
https://www.zabbix.com/download_sources
https://www.cnblogs.com/omgasw/p/15083049.html