# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core)
配置yum源mysql
# vim /etc/yum.repos.d/docker-ce.repo [docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
安裝docker-celinux
# wget https://mirrors.aliyun.com/centos-vault/7.3.1611/extras/x86_64/Packages/container-selinux-2.9-4.el7.noarch.rpm # yum localinstall container-selinux-2.9-4.el7.noarch.rpm -y # yum install docker-ce -y
#systemctl start docker
1 、先安裝數據庫mysqlnginx
docker run --name zabbix-mysql-server --hostname zabbix-mysql-server \ -e MYSQL_ROOT_PASSWORD="123456" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="123456" \ -e MYSQL_DATABASE="zabbix" \ -p 33061:3306 \ -d mysql:5.7 \ --character-set-server=utf8 --collation-server=utf8_bin
2 、建立zabbix-serverweb
docker run --name zabbix-server-mysql --hostname zabbix-server-mysql \ --link zabbix-mysql-server:mysql \ -e DB_SERVER_HOST="mysql" \ -e MYSQL_USER="zabbix" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_PASSWORD="123456" \ -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
3 、安裝web-nginxsql
安裝zabbix-web-nginx docker run --name zabbix-web-nginx-mysql --hostname zabbix-web-nginx-mysql \ --link zabbix-mysql-server:mysql \ --link zabbix-server-mysql:zabbix-server \ -e DB_SERVER_HOST="mysql" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="123456" \ -e MYSQL_DATABASE="zabbix" \ -e ZBX_SERVER_HOST="zabbix-server" \ -e PHP_TZ="Asia/Shanghai" \ -p 7000:80 \ -p 8443:443 \ -d \ zabbix/zabbix-web-nginx-mysql
# docker ps -s CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE d96b4abdd502 zabbix/zabbix-web-nginx-mysql "docker-entrypoint.sh" 3 days ago Up 12 hours 0.0.0.0:7000->80/tcp, 0.0.0.0:8443->443/tcp zabbix-web-nginx-mysql 2.06kB (virtual 163MB) 23cb7c5842d0 zabbix/zabbix-server-mysql "docker-entrypoint.sh" 3 days ago Up 12 hours 0.0.0.0:10051->10051/tcp zabbix-server-mysql 25MB (virtual 87.7MB) b1bea58475f1 mysql:5.7 "docker-entrypoint.s…" 3 days ago Up 12 hours 0.0.0.0:33061->3306/tcp, 33060/tcp zabbix-mysql-server 28B (virtual 372MB)
zabbix-server基於docker安裝完畢!docker
關閉防火牆和selinux數據庫
訪問:http://宿主機IP:7000vim
默認用戶名:Admincentos
默認登錄mingbash
ps:開啓網絡轉換容器只能ping通宿主機,不能通外網,重啓docker就OK
# docker exec -it zabbix-server-mysql /bin/bash bash-4.3# ping 1.1.1.1 PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data. 64 bytes from 1.1.1.1: icmp_seq=1 ttl=127 time=197 ms 64 bytes from 1.1.1.1: icmp_seq=2 ttl=127 time=196 ms ps:網絡通外網 查看ipbash-4.3# ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 278: eth0@if279: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP inet 172.17.0.15/16 scope global eth0 valid_lft forever preferred_lft forever
1、備份配置文件: cp -a /etc/apk/repositories /etc/apk/repositories.bak 2、修改repositories文件,將http://dl-cdn.alpinelinux.org/替換成https://mirrors.huaweicloud.com/,能夠參考以下命令:sed -i s@http://dl-cdn.alpinelinux.org/@https://mirrors.huaweicloud.com/@g /etc/apk/repositories 3、執行apk update更新索引,執行apk search xxx查詢軟件包,執行apk add xxx安裝軟件包
#rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm #yum -y install zabbix-agent-4.0.1 docker exec -it zabbix-server-mysql ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 278: eth0@if279: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:0f brd ff:ff:ff:ff:ff:ff inet 172.17.0.15/16 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::42:acff:fe11:f/64 scope link valid_lft forever preferred_lft forever # vim /etc/zabbix/zabbix_agentd.conf Server=172.17.0.15 UnsafeUserParameters=1 Include=/etc/zabbix/zabbix_agentd.d/*.conf # systemctl start zabbix-agent.service
注意:若是要對宿主機進行監控,請編輯宿主機的zabbix_agentd.conf,將Server地址,默認127.0.0.1,修改成docker-server容器地址,不然不通;若是是對其餘主機的監控則使用docker-zabbix-server宿主機的IP。