环境准备:一台server端,两台agent端
server端部署zabbix-server和mariadb服务
agent端部署zabbix-agent服务
一、docker容器里下载zabbix和mariadb
docker pull mariadb
docker pull zabbix
[root@localhost cmp_mariadb]# docker pull mariadb Using default tag: latest latest: Pulling from library/mariadb 。。。 Digest: sha256:31cf9574e8e4043022e7f6260d77a08ab33bba1ab04a074ccaa077f3cf50b9e3 Status: Downloaded newer image for mariadb:latest
二、cd到/opt目录下,上传cmp_mariadb.zip 和 cmp_zabbix_server.zip压缩包,并分别解压
[root@localhost opt]# ls
cmp_mariadb cmp_mariadb.zip cmp_zabbix_server cmp_zabbix_server.zip
三、进入cmp_mariadb的目录
[root@localhost cmp_mariadb]# ls
docker-compose.yml mysqlconf mysqllib mysqllog
编辑一个docker-compose.yml的文件,并写入必要的信息
注意此文件名是不可变动的。
四、编辑此文件
[root@localhost cmp_mariadb]# cat docker-compose.yml mysql: image: mariadb:latest ports: - "3306:3306" #端口映射 volumes: #编辑宿主机与容器的数据卷映射 - ./mysqllib:/var/lib/mysql - ./mysqlconf:/etc/mysql - ./mysqllog:/var/log/mysql environment: #数据库的密码,库名等 - MYSQL_USER=zabbix - MYSQL_DATABASE=zabbix - MYSQL_PASSWORD=zabbix - MYSQL_ROOT_PASSWORD=123321 - LANG=en_US.utf8 - TZ=Asia/Shanghai restart: always
五、同理进入cmp_zabbix_server目录
[root@localhost cmp_zabbix_server]# ls
docker-compose.yml zabbixconfig zabbix-scripts
六、编辑一个名为docker-compose.yml的文件,写入必要的脚本命令
[root@localhost cmp_zabbix_server]# cat docker-compose.yml
version: '3'
services:
zabbix-server:
container_name: zabbix-server #容器名
image: zabbix/zabbix-server-mysql:latest #建立容器的镜像
restart: always
network_mode: host #建立容器的网络模式
# ports:
# - "10051:10051"
environment:
- DB_SERVER_HOST=192.168.253.9 #数据库地址
- MYSQL_USER=zabbix
- MYSQL_DATABASE=zabbix
- MYSQL_PASSWORD=zabbix
- DB_SERVER_ROOT_USER=root
- DB_SERVER_ROOT_PASS=123321
- TZ='Asia/Shanghai'
volumes:
- /etc/localtime:/etc/localtime:ro
- ./zabbix-scripts:/usr/lib/zabbix
- ./zabbixconfig:/etc/zabbix
zabbix-web-nginx:
image: zabbix/zabbix-web-nginx-mysql:latest
restart: always
network_mode: bridge
ports:
- "8081:80" #端口映射
- "8444:443"
environment:
- DB_SERVER_HOST=192.168.253.9
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
- MYSQL_ROOT_PASSWORD=123321
- ZBX_SERVER_HOST=192.168.253.9
- PHP_TZ="Asia/Shanghai"
- TZ='Asia/Shanghai'
zabbix-agent:
image: zabbix/zabbix-agent:latest
environment:
- ZBX_HOSTNAME=Zabbix server
- ZBX_SERVER_HOST=127.0.0.1
- ZBX_SERVER_PORT=10051
- TZ='Asia/Shanghai'
network_mode: host
# ports:
# - "10050:10050"
restart: always
privileged: true
# links:
# - zabbix-server:zabbixhost
七、编辑完后,在各自目录下执行以下命令启动容器。
docker-compose up -d
执行以下命令查看容器状态。
docker-compose ps
[root@localhost cmp_zabbix_server]# docker-compose up -d [root@localhost cmp_zabbix_server]# docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------------------ cmpzabbixserver_zabbix-agent_1 /sbin/tini -- /usr/bin/doc ... up cmpzabbixserver_zabbix-web-nginx_1 docker-entrypoint.sh Up 0.0.0.0:8444->443/tcp, 0.0.0.0:8081->80/tcp zabbix-server /sbin/tini -- /usr/bin/doc ... Up
八、再另外的节点部署zabbix-agent.
[root@compute opt]# ls docker-compose.yml [root@compute opt]# cat docker-compose.yml version: '3' services: zabbix-agent: image: zabbix/zabbix-agent:latest container_name: zabbix-agent #容器名 environment: - ZBX_HOSTNAME=node2 - ZBX_SERVER_HOST=192.168.253.9 #server服务端ip - ZBX_SERVER_PORT=10051 #server服务的端口 - TZ='Asia/Shanghai' network_mode: bridge ports: - "10050:10050" #端口映射 restart: always privileged: true
九、在此目录下执行以下命令启动容器。
docker-compose up -d
执行以下命令查看容器状态。
docker-compose ps
[root@compute opt]# docker-compose ps Name Command State Ports -------------------------------------------------------------------------------- zabbix-agent /sbin/tini -- /usr/bin/doc ... Up 0.0.0.0:10050->10050/tcp
如果需要停止容易或者删除容器,执行以下命令
docker-compose stop 容器名
docker-comopse rm 容器名
十、到web页面输入ip地址:端口访问zabbix。
然后把node1和node2节点主机添加进入。
如果报错:
这是因为数据库版本导致,进入容器数据库更新版本到所需的3040000。
mysql> show databases; mysql> use zabbix; mysql> update dbversion set mandatory=3040000; mysql> flush privileges;
然后输入登陆用户与密码。