1. 启动一个空的MySQL服务器实例,映射端口到本地3306,映射db数据到本地磁盘 docker run --name mysql-server -p 3306:3306 -v /data/mysql_data:/var/lib/mysql -t -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbixpass" -e MYSQL_ROOT_PASSWORD="mysqlpass" -d mysql:5.7 2. 启动Zabbix Java gateway实例 # docker run --name zabbix-java-gateway -t -d zabbix/zabbix-java-gateway:latest 3. 启动Zabbix server实例,并关联这个实例到已创建的MySQL服务器实例,Zabbix server实例暴露10051/TCP端口(Zabbix trapper)给主机的110051 # docker run --name zabbix-server-mysql -t -e DB_SERVER_HOST="mysql-server" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbixpass" -e MYSQL_ROOT_PASSWORD="root" -e ZBX_JAVAGATEWAY="zabbix-java-gateway" --link mysql-server:mysql --link zabbix-java-gateway:zabbix-java-gateway -p 10051:10051 -d zabbix/zabbix-server-mysql:latest 4. 启动Zabbix web 接口,并将它与MySQL服务器实例和Zabbix server实例关联,Zabbix web 接口暴露80/TCP端口(HTTP)给主机,映射到主机的80端口,是否要映射文件到本地 -v 映射配置文件到本地,可以方便修改zabbix配置 mkdir -p /data/www/vhosts mkdir -p /usr/local/zabbix # 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="zabbixpass" -e MYSQL_ROOT_PASSWORD="root" --link mysql-server:mysql --link zabbix-server-mysql:zabbix-server -p 80:80 -p 443:443 -d zabbix/zabbix-web-nginx-mysql:latest 问题解决: zabbix服务端的agent报错: Received empty response from Zabbix Agent at [10.11.0.215]. Assuming that agent dropped connection because of access permissions. # 不是监听地址的问题 [root@node5 zabbix]# ss -tnlp|grep 10050 LISTEN 0 128 *:10050 *:* users:(("zabbix_agentd",pid=19407,fd=4),("zabbix_agentd",pid=19406,fd=4),("zabbix_agentd",pid=19405,fd=4),("zabbix_agentd",pid=19404,fd=4),("zabbix_agentd",pid=19403,fd=4),("zabbix_agentd",pid=19402,fd=4)) LISTEN 0 128 :::10050 :::* users:(("zabbix_agentd",pid=19407,fd=5),("zabbix_agentd",pid=19406,fd=5),("zabbix_agentd",pid=19405,fd=5),("zabbix_agentd",pid=19404,fd=5),("zabbix_agentd",pid=19403,fd=5),("zabbix_agentd",pid=19402,fd=5)) [root@node5 zabbix]# # 通过查看日志可以看到agetn拒绝了172.17.0.4这个ip地址的连接,很奇怪网段中没有172.17.x.x这样的地址,可能来自docker容器 [root@node5 zabbix]# tail -f /var/log/zabbix/zabbix_agentd.log 19464:20180612:211925.951 ************************** 19464:20180612:211925.951 using configuration file: /etc/zabbix/zabbix_agentd.conf 19464:20180612:211925.952 agent #0 started [main process] 19465:20180612:211925.952 agent #1 started [collector] 19466:20180612:211925.952 agent #2 started [listener #1] 19468:20180612:211925.952 agent #4 started [listener #3] 19469:20180612:211925.952 agent #5 started [active checks #1] 19467:20180612:211925.953 agent #3 started [listener #2] 19466:20180612:212011.434 failed to accept an incoming connection: connection from "172.17.0.4" rejected, allowed hosts: "10.11.0.215" 19467:20180612:212111.483 failed to accept an incoming connection: connection from "172.17.0.4" rejected, allowed hosts: "10.11.0.215" # 通过对docker网络的信息查看可以看到172.17.0.4就是zabbix-server所在容器的ip地址 [root@node5 zabbix]# docker network ls NETWORK ID NAME DRIVER SCOPE 414b22ea9ee1 bridge bridge local 777ac9c2b746 host host local 17346e7a7b0d none null local [root@node5 zabbix]# docker network inspect 414b22ea9ee1 [ { "Name": "bridge", "Id": "414b22ea9ee1ab01076caa9200d4737105a9c17a72c9b92cd82fd2b638710201", "Created": "2018-06-12T16:52:11.734025148+08:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, # zabbix-server的web容器nginx所在网络IP地址 "Containers": { "3456bfd64ee48c89daf2c2272b712a70fff82782f3ea109a5b7f67cb53ddbd36": { "Name": "zabbix-web-nginx-mysql", "EndpointID": "e6e4e129e6731fb454ab16da613de93c47bc27ac0d8e4981b9ae458a76fe17e0", "MacAddress": "02:42:ac:11:00:05", "IPv4Address": "172.17.0.5/16", "IPv6Address": "" }, # zabbix的数据库mysql所在网络IP地址 "581fb2eadf8f6edb4455dd17dc5f87f6ae047df17c016c0761f8aa0a7d025495": { "Name": "mysql-server", "EndpointID": "0b7153e0c38f48dbd86cb71fa4d6007ef95331537fa59f9abad602b968991e36", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" }, # zabbix-server所在网络IP地址 "595a03961b34527e453e457901306f1f821e7a263984a8c583456b7986820a57": { "Name": "zabbix-server-mysql", "EndpointID": "ab031f607b16793cd63e79ae1f7ccbfd91aabb963f02ffef5f10ccd684319cd2", "MacAddress": "02:42:ac:11:00:04", "IPv4Address": "172.17.0.4/16", "IPv6Address": "" }, "ab647c9f319178f010b02c3d919169cdea8337bcafb20515d17e7eef650e5a00": { "Name": "zabbix-java-gateway", "EndpointID": "e8466e1751cca4e0a7e9f35483c8bdb10036de6c1572883f7f2a0c07a65d2923", "MacAddress": "02:42:ac:11:00:03", "IPv4Address": "172.17.0.3/16", "IPv6Address": "" } }, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } 解决办法: 在客户端配置中添加zabbix-server所在容器的ip地址172.17.0.4即可 [root@node5 zabbix]# vim /etc/zabbix/zabbix_agentd.conf Server=10.11.0.215,172.17.0.4
zabbix服务端一般安装成功以后就不需要再做大的改动,使用docker会增加网络复杂度,不太建议用docker