使用docker搭建zabbix监控
环境:使用的是CentOS Linux release 7.6.1810
使用docker三剑客之一docker-compose,一个命令启动zabbix服务
使用docker三剑客之一docker-compose,一个命令启动zabbix服务
目录挂载说明
本地目录 | docker容器内目录 | 说明 |
---|---|---|
/data/mysql/data | /var/lib/mysql | mysql数据目录 |
/data/mysql/conf | /etc/mysql/conf.d | mysql配置目录 |
/data/zabbix/alertscripts | /usr/lib/zabbix/alertscripts | zabbix 告警脚本目录 |
/data/zabbix/externalscripts | /usr/lib/zabbix/externalscripts | 脚本路径,与编译的datadir有关 |
/data/zabbix/zabbix-server | /var/lib/zabbix | zabbix-server路径 |
docker-compose.yml文件
下面展示同样高亮的 代码片
.
version: '2'
services:
mysql-server:
hostname: mysql-server
container_name: mysql-server
image: mysql:5.7
restart: always
ports:
- 3306:3306
networks:
zabbix:
ipv4_address: 172.18.0.2
volumes:
- /data/mysql/data:/var/lib/mysql
- /data/mysql/conf:/etc/mysql/conf.d
command: --character-set-server=utf8
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
zabbix-server:
hostname: zabbix-server-mysql
image: zabbix/zabbix-server-mysql:latest
restart: always
networks:
zabbix:
ipv4_address: 172.18.0.3
links:
- mysql-server:mysql-server
container_name: zabbix-server
ports:
- 10051:10051
volumes:
- /etc/localtime:/etc/localtime:ro
- /data/zabbix/alertscripts:/usr/lib/zabbix/alertscripts
- /data/zabbix/externalscripts:/usr/lib/zabbix/externalscripts
- /data/zabbix/zabbix-server:/var/lib/zabbix
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_ROOT_PASSWORD: 123456
ZBX_AGENT: zabbix-agent
zabbix-web-nginx-mysql:
hostname: zabbix-web-nginx-mysql
container_name: zabbix-web-nginx-mysql
image: zabbix/zabbix-web-nginx-mysql:latest
restart: always
networks:
zabbix:
ipv4_address: 172.18.0.4
links:
- mysql-server:mysql-server
- zabbix-server:zabbix-server
ports:
- 80:80
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_ROOT_PASSWORD: 123456
ZBX_SERVER_NAME: zabbix master
PHP_TZ: Asia/Shanghai
networks:
zabbix:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.18.0.0/16
gateway: 172.18.0.1
所需docker镜像
mysql:5.7,zabbix-server,zabbix-web-nginx-mysql
[root@VM_0_13_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu latest cf0f3ca922e0 3 days ago 64.2 MB
mysql 5.7 f6509bac4980 3 months ago 373 MB
zabbix/zabbix-agent latest cab999cb921c 3 months ago 16.5 MB
zabbix/zabbix-web-nginx-mysql latest 6ed3c1b978ad 3 months ago 149 MB
zabbix/zabbix-server-mysql latest 6b0a1eb7097a 3 months ago 333 MB
启动docker服务
docker-compose up -d
zabbix配置
解决无法打开登陆界面的问题,执行命令:
docker exec -it zabbix-web-nginx-mysql sed -i 's#DejaVuSans#simkai#g' /usr/share/zabbix/include/defines.inc.php
字库下载simkai.ttf,这是我的CSDN下载连接,下载可能需要5积分。
我也在百度云盘上传了一份 simkai.ttf 提取码:pl7u 不用积分
替换字体,当字体为中文时,解决乱码问题,执行命令:
docker cp simkai.ttf zabbix-web-nginx-mysql:/usr/share/zabbix/assets/fonts
登录
docker-compose.yml中对外提供的端口为80,所以登录zabbix时,使用IP地址就可以登录,例如:http://192.168.65.129,也可以修改相应的端口
使用Google或者Firefox等兼容性比较好的浏览器访问,初始用户名/密码:Admin/zabbix
下一篇zabbix报警