一、背景介绍

前不久,zabbix6.0 LTS版本已经正式发布,由于之前环境还是采用zabbix4.0版本,故打算直接安装新版本,并对数据库从mysql切换到Timesacledb时序数据库。

zabbix6.0下载地址

zabbix6.0官方文档

为什么需要升级zabbix6.0

  • 对数据库更好的支持,引入了postgresql+timescaledb时序数据库,加快数据存储查询

  • 更多的webhook集成:对于外部IT系统,可直接配置相关参数即可完成系统集成,例如与内部itop系统,配置自动生成工单,非常方便

  • kubernetes支持:对kubernetes 节点、集群、API、控制器、调度、kubelet均内置监控模板

  • 物联网监控:zabbix agent2 插件,内置物联网参数,支持MQTT、Modebus协议的监控,可集成机房动环系统

  • 高可用方案,两台zabbix只需要修改配置文件参数,即可实现HA

二、关闭防火墙

setenforce 0        #临时关闭SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config  #永久关闭SELinux(重启生效)
systemctl stop firewalld.service    #临时关闭防火墙
systemctl disable firewalld.service    #永久关闭防火墙

安装需要centos8以上,需要更新yum源,下载地址centos8 yum源文件

#清空
rm -f /etc/yum.repos.d/*
#更新yum源
yum clean all
yum makecache

三、安装postgresql数据库

1.下载启动postgresql

#安装RPM仓库
dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm
#查看postgresql列表
yum list | grep postgresql
#禁止系统内置postgresql模块
dnf -qy module disable postgresql
# Install PostgreSQL:
sudo dnf install -y postgresql14-server
#初始化数据库
/usr/pgsql-14/bin/postgresql-14-setup initdb
#启动数据库
systemctl enable postgresql-14
systemctl start postgresql-14

2.设置postgres密码

passwd postgres

3.切换postgres用户

su postgres

4.修改postgres用户密码

bash-4.4$ psql
postgres=# ALTER USER postgres WITH PASSWORD 'PASSWORD';
ALTER ROLE
postgres=# \q

5.开放登录端口

vim /var/lib/pgsql/14/data/postgresql.conf

listen_addresses = '*'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                            # (change requires restart)
max_connections = 200

6.添加远程访问权限

vim /var/lib/pgsql/14/data/pg_hba.conf

host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host all all 0.0.0.0/0 md5

image-20220322143441748

7.重启数据库

systemctl restart postgresql-14

四、安装timesacledb

1.添加timescaled数据源

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

2.安装timescaledb数据库

dnf install timescaledb-2-postgresql-14-2.9.3 timescaledb-2-loader-postgresql-14-2.9.3

3.使用工具timescaledb-tune配置timescalesql

timescaledb-tune --pg-config=/usr/pgsql-14/bin/pg_config
#一直按Y即可

4.重启postgressql

systemctl restart postgresql-14

5.登录测试

psql -U postgres -h localhost
postgres=# CREATE EXTENSION timescaledb;

image-20220322153122589

postgres=#\dx

image-20220322153325976

出现该提示则安装成功

五、安装zabbix6.0

1.安装zabbix仓库

rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
dnf clean all

2.安装zabbix server ,web前端,agent

dnf install zabbix-server-pgsql zabbix-web-pgsql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent -y

六、配置postgresql

1.创建zabbix用户

sudo -u postgres createuser --pwprompt zabbix

2.创建zabbix数据库

sudo -u postgres createdb -O zabbix -E Unicode -T template0 zabbix

3.导入数据库结构

zcat /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz | sudo -u zabbix psql zabbix

4.编辑配置文件

vim /etc/zabbix/zabbix_server.conf

DBPassword=password

5.开启timesscaledb插件

echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix
cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb.sql | sudo -u zabbix psql zabbix

七、zabbix 前端配置

1.修改nginx配置

vim /etc/nginx/conf.d/zabbix.conf

#取消注释
server {
        listen          80;
        server_name     192.168.0.155;

image-20220322161157730

2.启动zabbix 进程

systemctl restart zabbix-server zabbix-agent nginx php-fpm

3.设置开机自启动

systemctl enable zabbix-server zabbix-agent nginx php-fpm

4.配置zabbix UI前端

打开网址 http://ip

image-20220322161607029

image-20220322161617782

image-20220322161915560

image-20220322162131766

image-20220322162139592

image-20220322162149495

5.登录zabbix

默认账号密码 Admin/zabbix

image-20220322162256520

image-20220322162319528

以上安装完成

八、zabbix6.0 初始化配置

1.中文设置

image-20220322162725851

dnf install -y langpacks-zh_CN.noarch
dnf reinstall glibc-common

刷新页面,选择中文

image-20220322163200296

image-20220322163214187

2.解决中文乱码

image-20220322163659966

找到电脑C:\Windows\Fonts中的中文字体,以黑体为例

image-20220322163932649

上传至/usr/share/zabbix/assets/fonts/目录下

image-20220322164208472

编辑配置文件

vim /usr/share/zabbix/include/defines.inc.php

define('ZBX_GRAPH_FONT_NAME',           'simhei'); // font file name
//define('ZBX_GRAPH_FONT_NAME',           'graphfont'); // font file name

ctrl+F5强制刷新

image-20220322165030385

3.修改缓存大小

vim /etc/zabbix/zabbix.server.conf

#CacheSiza=32M
CacheSiza=2048M

否则当监控项目过多,会导致zabbix server无法启动

故障处理

server无法运行,提示timescaledb版本不支持

image-20230316100726099

原因:由于dnf下载默认下载较新的timescale插件版本,对于centos8.2以下的不支持

解决方案:更换系统为8.5 或者 手动指定timescale插件版本

dnf install timescaledb-2-postgresql-14-2.9.3 timescaledb-2-loader-postgresql-14-2.9.3