不负众望,Zabbix 6.0 LTS终于更新了,原生支持了HA高可用部署!

TimescaleDB

TimescaleDB基于PostgreSQL数据库打造的一款时序数据库,插件化的形式部署,随着PostgreSQL的版本升级而升级,具备以下特点:

  1. 基于时序优化;
  2. 自动分片(按时间、空间自动分片(chunk));
  3. 全SQL接口;
  4. 支持垂直于横向扩展;
  5. 支持时间维度、空间维度自动分区。 空间维度指属性字段(例如传感器ID,用户ID等);
  6. 支持多个SERVER,多个CHUNK的并行查询。 分区在TimescaleDB中被称为chunk;
  7. 自动调整CHUNK的大小;
  8. 内部写优化(批量提交、内存索引、事务支持、数据倒灌);
  9. 复杂查询优化(根据查询条件自动选择chunk,最近值获取优化(最小化的扫描,类似递归收敛),limit子句pushdown到不同的; server,chunks,并行的聚合操作);
  10. 利用已有的PostgreSQL特性(支持GIS,JOIN等),方便的管理(流复制、PITR);
  11. 支持自动的按时间保留策略(自动删除过旧数据);

Zabbix 从5.0版本开始全面支持TimescaleDB,并针对其特性做了优化。可自动压缩历史数据存储,节省50-70%的存储空间,同时具备自动分区功能。通过Zabbix Housekeeper清理历史数据时直接清理对应的分区,大大提高了历史数据的清理效率,建议新建系统采用TimescaleDB方案。

环境准备

角色配置操作系统IP版本
Zabbix Server + WEB1 CPU + 2GB RAMRocky Linux release 8.5192.168.176.190PHP 7.2.34
nginx/1.20.2
Zabbix 6.0 LTS
Zabbix DB1 CPU + 2GB RAMRocky Linux release 8.5192.168.176.215postgresql13

安装完操作系统后,需要做一些初始化配置(记得防火墙放行业务端口或直接关闭系统防火墙)。

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并配置参数,会出现交互画面,一路y 即可,此步骤会根据当前机器配置,调整PostgreSQL配置参数,并加载Timescaledb插件库;

timescaledb-tune --pg-config=/usr/pgsql-13/bin/pg_config

重启PostgreSQL生效;

systemctl restart postgresql-13

建立Zabbix用户及数据库,此处是需要输入数据库zabbix用户的密码,输入二次后确认。此处配置密码为: Sword@2021,后续zabbix server连接数据库使用这个密码,用户为zabbix;

sudo -i -u postgres createuser --pwprompt zabbix

创建zabbix数据库;

sudo -i -u postgres createdb -O zabbix zabbix

为Zabbix数据库启用TimescleDB插件;

echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -i -u postgres psql zabbix
systemctl restart postgresql-13

如果看到以下的内容,表示配置成功!

[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源码并导入数据库
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

依次按照顺序导入三个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数据库,因此需要安装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-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数据库连接;

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的配置参数,建议配置,HANodeName修改为主机名,这里最好配置唯一; NodeAddress为节点地址,这里配置为实际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

创建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

创建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环境使用lnmp.org 1.9测试版一键包部署。

将Zabbix web UI复制到站点根目录

需要注意的是需要将php.ini中的max_input_time参数值调整为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函数,否则会导致pdo_pgsql()函数不可用;

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

相关新闻

联系我们

联系我们

400-0512-768

邮件:support@sworditsys.com

工作时间:周一至周五 8:00 - 21:00

分享本页
返回顶部