docker搭建zabbix,持续更新...
前提:公司需要搭建一台监控服务器,不想直接在服务上搭建zabbix,也不想一个一个docker run的去运行zabbix组件,就去github上找了套zabbix的yaml文件,地址https://github.com/zabbix/zabbix-docker,准备美滋滋的使用docker swarm deploy
一劳永逸的直接搭建,这一执行后直接满屏报错,弄得我一脸懵逼,哎,看来饭得一口一口,这偷懒看来是不行了。
1. 首先开始pull zabbix所需要模块的镜像,我自己用的docker版本是20.10.9
docker pull mysql:5.7
docker pull zabbix/zabbix-server-mysql:centos-latest
docker pull zabbix/zabbix-web-nginx-mysql:latest
docker pull zabbix/zabbix-agent:latest
docker pull zabbix/zabbix-java-gateway:latest
mysql:5.7数据服务没啥可说
zabbix-server后端镜像,选择支持MySQL数据库zabbix-server-mysql,选择的是centos-latest版本,后面如果想自己重做镜像的话,需要exec进入容器中,选择centos版本,用着会更简单一点。
Zabbix-web镜像,这里使用的是基于Nginx web服务器及支持MySQL数据库的Zabbix web接口zabbix/zabbix-web-nginx-mysql
zabbix-java-gateway镜像,Zabbix本身不支持直接监控Java,而是使用zabbix-java-gateway监控jvm/tomcat性能
abbix/zabbix-agent镜像, 可以运行在各种支持的平台上,包括 Linux、UNIX 和 Windows,并从设备收集 CPU、内存、磁盘和网络接口使用情况等数据
2.下载完镜像开始搭建容器
docker run --name mysql-server -t -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix" -e MYSQL_ROOT_PASSWORD="zabbixroot" -v /sfapp/docker/mysql:/var/lib/mysql -v /etc/localtime:/etc/localtime -d mysql:5.7 --character-set-server=utf8 --collation-server=utf8_bin
docker run --name zabbix-server-mysql -t -e DB_SERVER_HOST="mysql-server" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix" -e MYSQL_ROOT_PASSWORD="zabbixroot" -v /etc/localtime:/etc/localtime --link mysql-server:mysql -p 10051:10051 -d zabbix/zabbix-server-mysql:centos-latest
docker run --name zabbix-web-nginx-mysql -t -e DB_SERVER_HOST="mysql-server" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix" -e MYSQL_ROOT_PASSWORD="zabbixroot" -v /etc/localtime:/etc/localtime --link mysql-server:mysql --link zabbix-server-mysql:zabbix-server -p 8090:8080 -d zabbix/zabbix-web-nginx-mysql:latest
docker run --name zabbix_agent --link zabbix-server-mysql:zabbix-server -e ZBX_HOSTNAME="zabbix-server-mysql" -e ZBX_SERVER_PORT="10051" -e ZBX_SERVER_HOST="192.168.1.100" -p 10050:10050 -d zabbix/zabbix-agent:latest
docker run -v /etc/localtime:/etc/localtime -dit --restart=always --name=zabbix-java-gateway zabbix/zabbix-java-gateway:latest
3.登录测试
账号:amdin 密码:zabbix
测试没问题了,可以使用了,但我的目录是以后秒搭建,所以接下来准备自己写compoes.yml文件
4、先写个最简单的docker-composes.yml文件
点击查看zabbix1.0.yml
version: '3.7'
services:
mysql-server:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: 123
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_DATABASE: zabbix
ports:
- "13306:3306"
networks:
- zbx_net
zabbix-server:
image: zabbix/zabbix-server-mysql:centos-latest
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
ports:
- "10051:10051"
depends_on:
- "mysql-server"
networks:
- zbx_net
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql:latest
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
PHP_TZ: Asia/Shanghai
ZBX_SERVER_HOST: zabbix-server
ports:
- 80:8080
depends_on:
- mysql-server
- zabbix-server
networks:
- zbx_net
zabbix-agent:
image: zabbix/zabbix-agent:latest
environment:
ZBX_SERVER_HOST: zabbix-server
ports:
- "10050:10050"
depends_on:
- "zabbix-server"
networks:
- zbx_net
networks:
zbx_net:
使用docker-compose进行测试看看有没有报错:
docker-compose -f zabbix.yaml up -d
嗯,看来一切正常
5. 接下来继续修改yaml文件,把挂载的物理路径加上,注意一定要在本机上创建挂载目录,不然服务无法启动
mkdir -p /home/docker/mysql
点击查看zbbix2.0.yml
version: '3.7'
services:
mysql-server:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: 123
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_DATABASE: zabbix
volumes:
- "/etc/localtime:/etc/localtime"
- "/home/docker/mysql:/var/lib/mysql"
ports:
- "13306:3306"
networks:
- zbx_net
zabbix-server:
image: zabbix/zabbix-server-mysql:centos-latest
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
ports:
- "10051:10051"
depends_on:
- "mysql-server"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- "zabbix:/var/lib/zabbix"
networks:
- zbx_net
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql:latest
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
PHP_TZ: Asia/Shanghai
ZBX_SERVER_HOST: zabbix-server
ports:
- 80:8080
depends_on:
- mysql-server
- zabbix-server
networks:
- zbx_net
zabbix-agent:
image: zabbix/zabbix-agent:latest
environment:
ZBX_SERVER_HOST: zabbix-server
ports:
- "10050:10050"
depends_on:
- "zabbix-server"
networks:
- zbx_net
networks:
zbx_net:
volumes:
zabbix: