docker部署zabbix 6.0高可用叢集實驗

2023-07-22 15:01:47

0 實驗環境

虛擬機器器,postgresql本地部署,zabbix server及nginx容器部署

1 postgresql

參看前作 《postgresql + timescaledb離線安裝筆記》完成部署,對外埠tcp 15432,賬號zabbix,密碼123

2 zabbix server

2.1 拉取映象

docker pull zabbix/zabbix-server-pgsql:6.0-alpine-latest

2.2 建立網路

docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 zabbix-net

2.3 啟動server容器

啟動兩個容器分別作為主備server節點,分別使用本地tcp 10051和10052埠

2.3.1 server主節點

docker run --name zabbix-server-pgsql-1 -t \
	-e DB_SERVER_HOST="172.17.0.1" -e DB_SERVER_PORT="15432" \
	-e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD='123' -e POSTGRES_DB="zabbix" \
	-e ZBX_CACHESIZE="128M" -e ZBX_HISTORYCACHESIZE="32M" -e ZBX_HISTORYINDEXCACHESIZE="8M" -e ZBX_TRENDCACHESIZE="8M" -e ZBX_VALUECACHESIZE="64M" \
	-e ZBX_LOGSLOWQUERIES="3000" -e ZBX_STARTPOLLERS="5" -e ZBX_STARTPREPROCESSORS="10" -e ZBX_STARTPOLLERSUNREACHABLE="5" -e ZBX_STARTESCALATORS="5" -e ZBX_STARTDBSYNCERS="5" \
	-e ZBX_HANODENAME="server-01" -e ZBX_NODEADDRESS="172.20.240.1" \
	-p 10051:10051 --network=zabbix-net --restart unless-stopped \
	-d zabbix/zabbix-server-pgsql:6.0-alpine-latest

2.3.2 server備節點

docker run --name zabbix-server-pgsql-2 -t \
	-e DB_SERVER_HOST="172.17.0.1" -e DB_SERVER_PORT="15432" \
	-e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD='123' -e POSTGRES_DB="zabbix" \
	-e ZBX_CACHESIZE="128M" -e ZBX_HISTORYCACHESIZE="32M" -e ZBX_HISTORYINDEXCACHESIZE="8M" -e ZBX_TRENDCACHESIZE="8M" -e ZBX_VALUECACHESIZE="64M" \
	-e ZBX_LOGSLOWQUERIES="3000" -e ZBX_STARTPOLLERS="5" -e ZBX_STARTPREPROCESSORS="10" -e ZBX_STARTPOLLERSUNREACHABLE="5" -e ZBX_STARTESCALATORS="5" -e ZBX_STARTDBSYNCERS="5" \
	-e ZBX_HANODENAME="server-02" -e ZBX_NODEADDRESS="172.20.240.2" \
	-p 10052:10051 --network=zabbix-net --restart unless-stopped \
	-d zabbix/zabbix-server-pgsql:6.0-alpine-latest

2.3.3 偵錯命令(進入active容器,即zabbix-server-pgsql-1)

顯示Server叢集狀態:

zabbix_server -R ha_status

結果如下

Failover delay: 60 seconds
Cluster status:
   #  ID                        Name                      Address                        Status      Last Access
   1. clkc8ouam00016nrvjcuugxsr server-01                 172.20.240.1:10051             active      4s
   2. clkc8ozws00016nmr5dyv7qd4 server-02                 172.20.240.2:10051             standby     2s

可刪除備節點

zabbix_server -R ha_remove_node=clkc8ozws00016nmr5dyv7qd4

3 web

3.1 拉取映象

docker pull zabbix/zabbix-web-nginx-pgsql:6.0-alpine-latest

3.1 啟動容器

注意ZBX_SERVER_HOST和ZBX_SERVER_PORT一定要設定為空

docker run --name zabbix-web-nginx-pgsql -t \
    -e ZBX_SERVER_HOST="" -e ZBX_SERVER_PORT="" \
    -e DB_SERVER_HOST="172.17.0.1" -e DB_SERVER_PORT="15433" \
    -e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD="123" -e POSTGRES_DB="zabbix" \
    -e ZBX_SERVER_NAME="zabbix-test" \
    -e PHP_TZ="Asia/Shanghai" \
    -p 10080:8080 --network=zabbix-net --restart unless-stopped \
    -d zabbix/zabbix-web-nginx-pgsql:6.0-alpine-latest

4 測試

4.1 原始狀態

在System information頁面下可以看到,此時server-01是主用節點

4.2 切換

將zabbix-server-pgsql-1容器暫停

docker stop zabbix-server-pgsql-1

此時可以看到server-01變為stopped狀態,server-02成為Active狀態

再次啟動zabbix-server-pgsql-1容器,則server-01變回Standby狀態