前言
Zabbix是目前最为主流的开源监控方案之一,前面的文章主要介绍了传统的安装方式,在Docker容器出现后我们也拥有更高效的安装方式,这里就主要分享基于Docker安装和配置Zabbix的相关心得。
使用Docker安装Zabbix实践
更新历史
2018年10月30日 - 初稿
阅读原文 - https://wsgzao.github.io/post/zabbix-docker/
扩展阅读
Zabbix - https://www.zabbix.com/
官方文档
https://www.zabbix.com/download
https://www.zabbix.com/documentation
zabbix-server
从容器安装Zabbix Server最简单的方式之一,关于数据卷是否需要映射,看实际需求吧
https://hub.docker.com/r/zabbix/zabbix-server-mysql/tags/
https://hub.docker.com/r/zabbix/zabbix-web-nginx-mysql/tags/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| sudo yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install -y docker-ce sudo systemctl start docker
docker run --name mysql-server -t \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="zabbix" \ -e MYSQL_ROOT_PASSWORD="zabbix" \ -p 127.0.0.1:3306:3306 \ -d mysql:5.7 \ --character-set-server=utf8 --collation-server=utf8_bin
docker run --name zabbix-server-mysql -t \ --link mysql-server:mysql \ -e DB_SERVER_HOST="mysql-server" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="zabbix" \ -e MYSQL_ROOT_PASSWORD="zabbix" \ -p 10051:10051 \ -d \ zabbix/zabbix-server-mysql:centos-4.0-latest
docker run --name zabbix-web-nginx-mysql -t \ --link mysql-server:mysql \ --link zabbix-server-mysql:zabbix-server \ -e DB_SERVER_HOST="mysql-server" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="zabbix" \ -e MYSQL_ROOT_PASSWORD="zabbix" \ -e PHP_TZ="Asia/Singapore" \ -p 80:80 \ -d \ zabbix/zabbix-web-nginx-mysql:centos-4.0-latest
mkdir -p /data/docker/mysql/zabbix/data mkdir -p /data/docker/zabbix/alertscripts mkdir -p /data/docker/zabbix/externalscripts
docker run --name mysql-server -t \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="zabbix" \ -e MYSQL_ROOT_PASSWORD="zabbix" \ -v /data/docker/mysql/zabbix/data:/var/lib/mysql \ -p 127.0.0.1:3306:3306 \ -d mysql:5.7 \ --character-set-server=utf8 --collation-server=utf8_bin
docker run --name zabbix-server-mysql -t \ --link mysql-server:mysql \ -e DB_SERVER_HOST="mysql-server" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="zabbix" \ -e MYSQL_ROOT_PASSWORD="zabbix" \ -v /etc/localtime:/etc/localtime:ro \ -v /data/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \ -v /data/docker/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \ -p 10051:10051 \ -d \ zabbix/zabbix-server-mysql:centos-4.0-latest
docker run --name zabbix-web-nginx-mysql -t \ --link mysql-server:mysql \ --link zabbix-server-mysql:zabbix-server \ -e DB_SERVER_HOST="mysql-server" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="zabbix" \ -e MYSQL_ROOT_PASSWORD="zabbix" \ -e PHP_TZ="Asia/Singapore" \ -p 80:80 \ -d \ zabbix/zabbix-web-nginx-mysql:centos-4.0-latest
|
zabbix-proxy和zabbix-agent也可以用容器安装,不过agent就不推荐容器化了,针对容器本身的监控可以使用zabbix-docker-monitoring,当然Prometheus才是监控容器的利刃。
https://github.com/monitoringartist/zabbix-docker-monitoring
zabbix-docker官方的GitHub站点还包含更详细的docker compose配置
https://github.com/zabbix/zabbix-docker
关于Docker常用命令可以参考Docker从入门到实践
https://wsgzao.github.io/post/docker/
Zabbix容器化后的配置
容器化的配置和传统方式略有不同,尤其是网络防火墙策略
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 PidFile=/var/run/zabbix/zabbix_server.pid SocketDir=/var/run/zabbix DBName=zabbix DBUser=zabbix DBPassword=zabbix StartPollers=500 StartPingers=50 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log CacheSize=8G TrendCacheSize=1G Timeout=15 AlertScriptsPath=/usr/lib/zabbix/alertscripts ExternalScripts=/usr/lib/zabbix/externalscripts LogSlowQueries=3000
LogType=console DBHost=mysql-server DBName=zabbix DBUser=zabbix DBPassword=zabbix DBPort=3306 AlertScriptsPath=/usr/lib/zabbix/alertscripts ExternalScripts=/usr/lib/zabbix/externalscripts FpingLocation=/usr/sbin/fping Fping6Location=/usr/sbin/fping6 SSHKeyLocation=/var/lib/zabbix/ssh_keys SSLCertLocation=/var/lib/zabbix/ssl/certs/ SSLKeyLocation=/var/lib/zabbix/ssl/keys/ SSLCALocation=/var/lib/zabbix/ssl/ssl_ca/ LoadModulePath=/var/lib/zabbix/modules/
-v /data/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \ -v /data/docker/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \
1. disable Housekeeping 2. mysql_partition
https://www.zabbix.org/wiki/Docs/howto/mysql_partition
apt-get update apt-get install lrzsz vim cron -y
mysql -uzabbix -pzabbix zabbix < partition.sql
vim /etc/crontab 01 01 * * * root mysql -uzabbix -pzabbix zabbix -e"CALL partition_maintenance_all('zabbix')"
service cron restart
docker exec $(docker ps -aqf "name=mysql-server") mysql -uzabbix -pzabbix zabbix -e"CALL partition_maintenance_all('zabbix')"
|
升级容器
- 拉取最新镜像
- 停止并删除当前运行容器
- 用最新镜像重新创建容器
- All Done
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| docker images
docker pull zabbix/zabbix-web-nginx-mysql docker pull zabbix/zabbix-server-mysql
docker ps
docker inspect 14fd67405076
docker stop 14fd67405076 docker kill 14fd67405076
docker rm 14fd67405076
docker run --name zabbix-server-mysql -t \ --link mysql-server:mysql \ -e DB_SERVER_HOST="mysql-server" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="zabbix" \ -e MYSQL_ROOT_PASSWORD="zabbix" \ -v /etc/localtime:/etc/localtime:ro \ -v /data/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \ -v /data/docker/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \ -p 10051:10051 \ -d \ zabbix/zabbix-server-mysql
docker run --name zabbix-web-nginx-mysql -t \ --link mysql-server:mysql \ --link zabbix-server-mysql:zabbix-server \ -e DB_SERVER_HOST="mysql-server" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="zabbix" \ -e MYSQL_ROOT_PASSWORD="zabbix" \ -e PHP_TZ="Asia/Singapore" \ -p 80:80 \ -d \ zabbix/zabbix-web-nginx-mysql
|