一、实验环境
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
IP:192.168.1.109
二、安装docker
安装docker的方式有多种:
1.yum安装
# yum -y install docker
2.用docker的二进制文件安装
http://www.jianshu.com/p/40eb4579222b
三、安装后设置
# systemctl daemon-reload
# systemctl start docker
# systemctl status docker
# systemctl enable docker
# docker info
# docker version
四、命令行依次起如下容器
#docker run --name mysql-server -t \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix_pwd" \
-e MYSQL_ROOT_PASSWORD="root_pwd" \
-d mysql:5.7 \
--character-set-server=utf8 --collation-server=utf8_bin
# docker run --name zabbix-java-gateway -t \
-d zabbix/zabbix-java-gateway:latest
# 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_pwd" \
-e MYSQL_ROOT_PASSWORD="root_pwd" \
-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
# docker run --name zabbix-agent -t \
-e ZBX_HOSTNAME="zabbix-agent" \
-e ZBX_SERVER_HOST="zabbix-server-mysql" \
--link zabbix-server-mysql:zabbix-server \
--link zabbix-java-gateway:zabbix-java-gateway \
-p 10050:10050 \
-d zabbix/zabbix-agent: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_pwd" \
-e MYSQL_ROOT_PASSWORD="root_pwd" \
--link mysql-server:mysql \
--link zabbix-server-mysql:zabbix-server \
-p 80:80 \
-d zabbix/zabbix-web-nginx-mysql:latest
我们也可以写在一个shell里,执行脚本起如上五个容器:
如果要设置docker启动,容器启动,可在每个容器的启动参数里添加
--restart always
四、查看所起容器状态和端口监听
# dokcer ps -a
# ss -tan
五、登录web,enable本机监控
http://192.168.1.109/index.php
Admin/zabbix
注意:
此处IP 不能为 127.0.0.1,应该为zabbix-agent 的容器IP
# docker ps -a
# docker exec -it $(docker ps -a | grep "zabbix-agent" | awk '{print $1}') "ifconfig"
六、参考:
Zabbix Documentation 3.2
https://www.zabbix.com/documentation/3.2/manual/installation/containers
zabbix/zabbix-agent
https://hub.docker.com/r/zabbix/zabbix-agent