zabbix基于docker安装Centos7

关闭防火墙和selinux

echo 1 > /proc/sys/net/ipv4/ip_forward   #容器内网络与外网通,在宿主机上要开启网络转换

ps:开启网络转换容器只能ping通宿主机,不能通外网,重启docker就OK

 

centos的版本

# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

安装wget:yum install -y wget

 

docker的安装

配置yum源

 

# 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-ce

# 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

启动docker

#systemctl start docker

使用docker搭建zabbix

1 、先安装数据库mysql

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-server

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-nginx

安装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镜像

# 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)

访问:http://宿主机IP:7000

默认用户名:Admin

默认登陆zabbix

 

进入zabbix-server容器

# 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安装软件包

安装zabbix-agent 并配置

 

#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。

 

 

 

 

 

 

发布了110 篇原创文章 · 获赞 0 · 访问量 2331
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术工厂 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览