centos docker部署zabbix

余生长醉 提交于 2019-11-26 14:26:16

在centos中安装docker

  • 移除旧的版本
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine
  • 安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
  • 添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 更新 yum 缓存
yum makecache fast
  • 安装 Docker-ce
yum -y install docker-ce
  • 启动 Docker 后台服务
systemctl start docker
  • 镜像加速, /etc/docker/daemon.json(Linux)来配置 Daemon请在该配置文件中加入
{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

下载zabbix相关的镜像

在启动docker后:

docker pull mysql:5.7
docker pull zabbix/zabbix-agent:latest
docker pull zabbix/zabbix-server-mysql:latest
docker pull zabbix/zabbix-web-nginx-mysql:latest

启动容器和容器连接

  • 创建网桥
# 创建名字为zabbix的网桥, 默认为bridge
docker network create zabbix
  • 创建mysql容器
# 创建名字为mysql-server的容器,并把容器网络连接到zabbix网桥上
docker  run --name mysql-server --network zabbix -t \
	   -e MYSQL_DATABASE="zabbix" \
	   -e MYSQL_USER="zabbix" \
	   -e MYSQL_PASSWORD="zabbix_pwd" \
	   -e MYSQL_ROOT_PASSWORD="root_pwd" \
	   -d mysql:5.7
  • 创建zabbix-server容器

1.查看mysql容器的IP地址,可知道mysql-server容器的ip为172.18.0.2

docker inspect mysql-server
....
"Networks": {
                "zabbix": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "d6ef93e44af0"
                    ],
                    "NetworkID": "7badc1138f556c566b1baa9cacaa37afaa86904742c7f975574697a9c8ae191d",
                    "EndpointID": "950c6714d41e34cfbe715c327a7b6d0f2a87f0a32bc6c6ff3430bbf11a37b061",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:02",
                    "DriverOpts": null
.....

  1. 创建zabbix容器
# 创建zabbix-server容器名为zabbix-server-mysql , 连接到zabbix网桥
docker run --name zabbix-server-mysql --network zabbix -t \
    -e DB_SERVER_HOST="172.18.0.2" \
    -e MYSQL_DATABASE="zabbix" \
    -e MYSQL_USER="zabbix" \
    -e MYSQL_PASSWORD="zabbix_pwd" \
    -e MYSQL_ROOT_PASSWORD="root_pwd" \
    -d zabbix/zabbix-server-mysql:latest
  • 创建zabbix web容器
  1. 查看zabbix-server容器的IP地址,可知道zabbix-server容器的ip为172.18.0.3
docker inspect mysql-server

"Networks": {
                "zabbix": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "1c3e264b6ca3"
                    ],
                    "NetworkID": "7badc1138f556c566b1baa9cacaa37afaa86904742c7f975574697a9c8ae191d",
                    "EndpointID": "86c1a10a2e39d65860f05819131f9c2469faee7dd0bb1068b279f877d1e4aff3",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:03",
                    "DriverOpts": null

  1. 创建zabbix-web容器
docker run --name zabbix-web-nginx-mysql --network zabbix -t \
	-e DB_SERVER_HOST="172.18.0.2" \
	-e MYSQL_DATABASE="zabbix" \
	-e MYSQL_USER="zabbix" \
	-e MYSQL_PASSWORD="zabbix_pwd" \
	-e MYSQL_ROOT_PASSWORD="root_pwd" \
	-e ZBX_SERVER_HOST="172.18.0.3" \
	-p 80:80 \
	-d zabbix/zabbix-web-nginx-mysql:latest
  • 创建zabbix-agent容器
docker run --name zabbix-agent --network zabbix \
	-e ZBX_HOSTNAME="Zabbix server" \
	-e ZBX_SERVER_HOST="172.18.0.3" \
	-d zabbix/zabbix-agent:latest
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!