任务目标#
- 在主机一上完成 docker 部署 zabbix6.4
- 在主机二上安装 zabbix-agent2
- 使用主机一上的 zabbix 容器监控主机二的容器等业务
任务平台#
- 物理设备 --
- 操作系统:CentOS 7
部署指南#
任务 一#
- 安装 docker(最新版)
#下载并安装docker文件及依赖
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
#启动docker并设置开机自启
systemctl start docker
systemctl enable docker
#查看版本
docker -v
- 配置防火墙所需的开放端口
# 放行nginx端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 放行zabbix agent端口
firewall-cmd --zone=public --add-port=10050/tcp --permanent
# 放行zabbix server端口
firewall-cmd --zone=public --add-port=10051/tcp --permanent
# 放行zabbix java gateway端口
firewall-cmd --zone=public --add-port=10052/tcp --permanent
# 放行mysql端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 放行snmptraps端口
firewall-cmd --zone=public --add-port=162/udp --permanent
# 重载防火墙
firewall-cmd --reload
#查看80端口是否开放
firewall-cmd --query-port=80/tcp
#查看所有放行的端口
firewall-cmd --zone=public --list-ports
- 拉取 zabbix 所需镜像文件
#拉取安装zabbix需要的docker镜像
docker pull mysql:8.0
docker pull zabbix/zabbix-java-gateway:alpine-6.4-latest
docker pull zabbix/zabbix-server-mysql:alpine-6.4-latest
docker pull zabbix/zabbix-web-nginx-mysql:alpine-6.4-latest
- 创建专用于 Zabbix 组件容器网络与所需容器
方案一:#
#创建专用于Zabbix组件容器的网络
docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 zabbix-net
#启动空的MySQ服务器实例
docker run --name mysql-server -t \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="123456" \
-e MYSQL_ROOT_PASSWORD="123456" \
--network=zabbix-net \
--restart=always \
-d mysql:8.0 \
--character-set-server=UTF8MB4 --collation-server=UTF8MB4_bin \
--authentication_policy=mysql_native_password
#启动Zabbix Java网关实例
docker run --name zabbix-java-gateway -t \
--network=zabbix-net \
--restart unless-stopped \
-d zabbix/zabbix-java-gateway:alpine-6.4-latest
#启动Zabbix服务器实例并将实例与创建的MySQL服务器实例链接
docker run --name zabbix-server-mysql -t \
-e DB_SERVER_HOST="mysql-server" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="123456" \
-e MYSQL_ROOT_PASSWORD="123456" \
-e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
--network=zabbix-net \
-p 10051:10051 \
--restart unless-stopped \
-d zabbix/zabbix-server-mysql:alpine-6.4-latest
#启动Zabbix Web界面,并将实例与创建的MySQL服务器和Zabbix服务器实例链接
docker run --name zabbix-web-nginx-mysql -t \
-e ZBX_SERVER_HOST="zabbix-server-mysql" \
-e DB_SERVER_HOST="mysql-server" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="123456" \
-e MYSQL_ROOT_PASSWORD="123456" \
--network=zabbix-net \
-p 80:8080 \
--restart unless-stopped \
-d zabbix/zabbix-web-nginx-mysql:alpine-6.4-latest
方案二:(推荐使用)#
#启动空的MySQ服务器实例
docker run --name mysql-server -t \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="123456" \
-e MYSQL_ROOT_PASSWORD="123456" \
--restart=always \
-d mysql:8.0 \
--character-set-server=UTF8MB4 --collation-server=UTF8MB4_bin \
--authentication_policy=mysql_native_password
#启动Zabbix Java网关实例
docker run --name zabbix-java-gateway -t \
--restart unless-stopped \
-d zabbix/zabbix-java-gateway:alpine-6.4-latest
#启动Zabbix服务器实例并将实例与创建的MySQL服务器实例链接
docker run --name zabbix-server-mysql -t \
-e DB_SERVER_HOST="mysql-server" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="123456" \
-e MYSQL_ROOT_PASSWORD="123456" \
-e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
--link mysql-server:mysql \
--link zabbix-java-gateway:zabbix-java-gateway \
-p 10051:10051 \
--restart unless-stopped \
-d zabbix/zabbix-server-mysql:alpine-6.4-latest
#启动Zabbix Web界面,并将实例与创建的MySQL服务器和Zabbix服务器实例链接
docker run --name zabbix-web-nginx-mysql -t \
-e ZBX_SERVER_HOST="zabbix-server-mysql" \
-e DB_SERVER_HOST="mysql-server" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="123456" \
-e MYSQL_ROOT_PASSWORD="123456" \
--link mysql-server:mysql \
--link zabbix-server-mysql:zabbix-server \
-p 80:8080 \
--restart unless-stopped \
-d zabbix/zabbix-web-nginx-mysql:alpine-6.4-latest
- 在其中一台的主机的 /etc/docker/daemon.json 文件中,加入如下内容:
#打开daemon.json文件
vi /etc/docker/daemon.json
#添加的内容
{
"bip": "172.16.200.1/24"
}
#重启docker服务
systemctl restart docker
任务二#
在主机二上安装 zabbix-agent2
在要监控的主机上安装 zabbix agent2
步骤 1:Zabbix agent2 下载
https://www.zabbix.com/documentation/6.4/manual/installation/install_from_packages
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/7/x86_64/zabbix-release-6.4-1.el7.noarch.rpm
yum clean all
步骤 2:b. 下载 Zabbix agent2
yum install zabbix-agent2 zabbix-agent2-plugin-* -y
步骤 3:启动 Zabbix agent2
Start Zabbix agent2 process and make it start at system boot.
systemctl restart zabbix-agent2
systemctl enable zabbix-agent2
运行成功界面如下
安装报错总结#
- 进入 mysql 容器,输入以下命令.
#进入sql界面
mysql -u root -p
#输入该命令,解决问题
create database zabbix character set utf8 collate utf8_bin;
SET GLOBAL log_bin_trust_function_creators = 1;
- 安装 zabbix 出现下图情况解决方法
https://blog.csdn.net/ly4983/article/details/111029506
扩展 - docker-compose 部署 zabbix#
services:
zabbix-db-mysql:
image: mysql:9.0.1
container_name: zabbix-db-mysql
restart: always
environment:
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix@123
- MYSQL_ROOT_PASSWORD=zabbix@123
- TZ=Asia/Shanghai
command: ["--character_set_server=utf8mb4", "--collation_server=utf8mb4_bin"]
volumes:
- /data/database/zabbix-mysql:/var/lib/mysql
user: "0"
ports:
- 3306:3306
networks:
zabbix:
ipv4_address: 172.20.20.10
zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:latest
container_name: zabbix-java-gateway
restart: always
environment:
- TZ=Asia/Shanghai
user: "0"
networks:
zabbix:
ipv4_address: 172.20.20.11
zabbix-server-mysql:
image: zabbix/zabbix-server-mysql:latest
container_name: zabbix-server-mysql
restart: always
environment:
- DB_SERVER_HOST=zabbix-db-mysql
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix@123
- MYSQL_ROOT_PASSWORD=zabbix@123
- ZBX_JAVAGATEWAY=zabbix-java-gateway
- TZ=Asia/Shanghai
user: "0"
ports:
- 10051:10051
networks:
zabbix:
ipv4_address: 172.20.20.12
zabbix-web-nginx-mysql:
image: zabbix/zabbix-web-nginx-mysql:latest
container_name: zabbix-web-nginx-mysql
restart: always
environment:
- ZBX_SERVER_HOST=zabbix-server-mysql
- DB_SERVER_HOST=zabbix-db-mysql
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix@123
- MYSQL_ROOT_PASSWORD=zabbix@123
- ZBX_JAVAGATEWAY_ENABLE=true
- ZBX_JAVAGATEWAYPORT=10052
- PHP_TZ=Asia/Shanghai
user: "0"
ports:
- 80:8080
networks:
zabbix:
ipv4_address: 172.20.20.13
zabbix-agent:
image: zabbix/zabbix-agent:latest
container_name: zabbix-agent
restart: always
environment:
- TZ=Asia/Shanghai
- ZBX_SERVER_HOST=172.20.20.12
- ZBX_HOSTNAME=Zabbix server
user: "0"
ports:
- 10050:10050
networks:
zabbix:
ipv4_address: 172.20.20.14
networks:
zabbix:
driver: bridge
ipam:
config:
- subnet: 172.20.20.0/24