Task Objectives#
- Complete the Docker deployment of Zabbix 6.4 on Host One
- Install Zabbix Agent 2 on Host Two
- Use the Zabbix container on Host One to monitor the containers and other services on Host Two
Task Platform#
- Physical Device --
- Operating System: CentOS 7
Deployment Guide#
Task One#
- Install Docker (latest version)
# Download and install Docker files and dependencies
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
# Start Docker and set it to start on boot
systemctl start docker
systemctl enable docker
# Check version
docker -v
- Configure the firewall to open the required ports
# Allow nginx port
firewall-cmd --zone=public --add-port=80/tcp --permanent
# Allow Zabbix agent port
firewall-cmd --zone=public --add-port=10050/tcp --permanent
# Allow Zabbix server port
firewall-cmd --zone=public --add-port=10051/tcp --permanent
# Allow Zabbix Java gateway port
firewall-cmd --zone=public --add-port=10052/tcp --permanent
# Allow MySQL port
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# Allow SNMP traps port
firewall-cmd --zone=public --add-port=162/udp --permanent
# Reload firewall
firewall-cmd --reload
# Check if port 80 is open
firewall-cmd --query-port=80/tcp
# Check all allowed ports
firewall-cmd --zone=public --list-ports
- Pull the required Zabbix image files
# Pull the Docker images needed for Zabbix installation
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
- Create a dedicated network for Zabbix component containers and the required containers
Option One:#
# Create a network dedicated to Zabbix component containers
docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 zabbix-net
# Start an empty MySQL server instance
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
# Start Zabbix Java gateway instance
docker run --name zabbix-java-gateway -t \
--network=zabbix-net \
--restart unless-stopped \
-d zabbix/zabbix-java-gateway:alpine-6.4-latest
# Start Zabbix server instance and link it to the created MySQL server instance
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
# Start Zabbix Web interface and link it to the created MySQL server and Zabbix server instances
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
Option Two: (Recommended)#
# Start an empty MySQL server instance
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
# Start Zabbix Java gateway instance
docker run --name zabbix-java-gateway -t \
--restart unless-stopped \
-d zabbix/zabbix-java-gateway:alpine-6.4-latest
# Start Zabbix server instance and link it to the created MySQL server instance
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
# Start Zabbix Web interface and link it to the created MySQL server and Zabbix server instances
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
- In the /etc/docker/daemon.json file of one of the hosts, add the following content:
# Open daemon.json file
vi /etc/docker/daemon.json
# Content to add
{
"bip": "172.16.200.1/24"
}
# Restart Docker service
systemctl restart docker
Task Two#
Install Zabbix Agent 2 on Host Two
Install Zabbix Agent 2 on the host to be monitored
Step 1: Download Zabbix Agent 2
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
Step 2: Download Zabbix Agent 2
yum install zabbix-agent2 zabbix-agent2-plugin-* -y
Step 3: Start Zabbix Agent 2
Start the Zabbix Agent 2 process and make it start at system boot.
systemctl restart zabbix-agent2
systemctl enable zabbix-agent2
The successful running interface is as follows
Installation Error Summary#
- Enter the MySQL container and enter the following command.
# Enter SQL interface
mysql -u root -p
# Enter this command to solve the problem
create database zabbix character set utf8 collate utf8_bin;
SET GLOBAL log_bin_trust_function_creators = 1;
- Solution for the situation shown in the installation of Zabbix
https://blog.csdn.net/ly4983/article/details/111029506
Extension - Docker Compose Deployment of 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