基础环境

cat /etc/redhat-release
CentOS Linux release 7.5. (Core)

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-.el7.noarch.rpm -y
# yum install docker-ce -y

更换源

顺便把docker源也换一下吧,免得一会还的重启

# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}

启动docker,查看版本号

# systemctl start docker.service

# docker version
Client:
Version: 18.09.
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov ::
OS/Arch: linux/amd64
Experimental: false Server: Docker Engine - Community
Engine:
Version: 18.09.
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov ::
OS/Arch: linux/amd64
Experimental: false

docker安装完毕!

开启网络转换

#echo 1 > /proc/sys/net/ipv4/ip_forward   #网络重启会后要重新开启

用Dockerfile部署

zabbix-server部署阶段

要用dockerzabbix-server,需要以下几个组件

组件名称 作用
数据库 MySQL或是PostgreSQL
Zabbix Java gateway Java管理扩展,可以不添加
Zabbix server zabbix 服务端
zabbix-web 与MySQL服务器实例和Zabbix server实例关联
zabbix-agent zabbix客户端

MySQL数据库

数据库我选择MySQL,还是得写Dockerfile,改一下时区,时间不对很麻烦,字符集也改一下吧

# mkdir /data/docker/mysql -p
/data/docker/mysql]# vim Dockerfile
FROM mysql:5.7
ENV LANG en_US.utf8
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo Asia/Shanghai > /etc/timezone \

构建镜像

 #docker build -t debian-mysql5.7 .
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
debian-mysql5.7 latest 3d3c7dc9608c 14 seconds ago 372MB
mysql 5.7 563a026a1511 3 weeks ago 372MB

启动容器

# docker run --hostname mysql --name debian-mysql-5.7 -t \
-e MYSQL_USER="zabbix" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_PASSWORD="passwd" \
-e MYSQL_ROOT_PASSWORD="passwd" \
-v /data/mysql:/var/lib/mysql:rw \
-d debian-mysql5.
9a98a2ba0896a8a146d515764d2d8eef4bc32a9f0dbea445c360fab5668a5cfe
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a98a2ba0896 debian-mysql5. "docker-entrypoint.s…

变量说明

变量  
MYSQL_USER 启动时要添加的用户
MYSQL_DATABASE 启动时要创建的数据库
MYSQL_PASSWORD 指定添加用的的密码
MYSQL_ROOT_PASSWORD root用户的密码

Zabbix Java gateway

这个看个人,如果不监控java应用服务器可以不安装这个,还是得写Dockerfile,改一下时区和编码。

/data/docker/java-gateway]# cat Dockerfile
FROM zabbix/zabbix-java-gateway:latest
ENV LANG en_US.utf8
RUN apk add -U tzdata
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo Asia/Shanghai > /etc/timezone \
/data/docker/java-gateway]# docker build -t zabbix-java-gateway .
/data/docker/java-gateway]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zabbix-java-gateway latest 7948dffa9af0 seconds ago .1MB

启动容器

需要映射一下10052端口

# docker run --hostname zabbix-java-gateway \
-name zabbix-java-gateway -t \
-p : \
-d zabbix-java-gateway
5e2434e7a4c6f3f947e6408ff5a90097e802c6a36282c36ce7e4cd5819474f7a
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e2434e7a4c6 zabbix-java-gateway "docker-entrypoint.sh" seconds ago Up seconds 0.0.0.0:->/tcp zabbix-java-gateway
9a98a2ba0896 debian-mysql5. "docker-entrypoint.s…" minutes ago Up minutes /tcp, /tcp debian-mysql-5.7

Zabbix server

编写Dockerfile

 /data/docker/zabbix-server]# cat Dockerfile
FROM zabbix/zabbix-server-mysql:latest
ENV LANG en_US.utf8
RUN apk add -U tzdata
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo Asia/Shanghai > /etc/timezone \
/data/docker/zabbix-server]# docker build -t zabbix-server .
/data/docker/zabbix-server]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zabbix-server latest 531aa3116f61 About a minute ago .3MB

需要映射10051端口,指定数据库服务器,连接MySQLzabbix-java-gateway容器

10051:10051 \
--hostname zabbix-server \
-e DB_SERVER_HOST="debian-mysql-5.7" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="passwd" \
-e MYSQL_ROOT_PASSWORD="passwd" \
-e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
--link debian-mysql-5.7:mysql \
--link zabbix-java-gateway:zabbix-java-gateway \
-d zabbix-server
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a45ef352cc68 zabbix-server "docker-entrypoint.sh" 9 minutes ago Up 8 minutes 0.0.0.0:10051->10051/tcp zabbix-server

zabbix-web

编写Dockerfile

/data/docker/zabbix-web]# cat Dockerfile
FROM zabbix/zabbix-web-nginx-mysql:latest
ENV LANG en_US.utf8
RUN apk add -U tzdata
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo Asia/Shanghai > /etc/timezone \
/data/docker/zabbix-web]# docker build -t zabbix-web .
/data/docker/zabbix-web]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zabbix-web latest 6ff51e2f0545 About a minute ago 164MB

启动容器

需要映射80端口到宿主机,连接数据库,连接zabbix-server容器

# docker run --name zabbix-web -t \
-p : \
--hostname zabbix-web \
-e PHP_TZ="Asia/Shanghai" \
-e DB_SERVER_HOST="debian-mysql-5.7" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="passwd" \
-e MYSQL_ROOT_PASSWORD="passwd" \
--link debian-mysql-5.7:mysql \
--link zabbix-server:zabbix-server \
-d zabbix-web
f0c33f227992ce220730da9454df2f354565ed0b3d0813513a87797c2b752702
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f0c33f227992 zabbix-web "docker-entrypoint.sh" seconds ago Up seconds 0.0.0.0:->/tcp, /tcp zabbix-web

以上方式安装的是最新版本,因为在指定镜像的时候没有指定版本号,默认的就是laster,也就是最新版本,建议zabbix-agent版本要和服务端一致。

看下安装的容器

# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b4b2524953b4 zabbix-web "docker-entrypoint.sh" About an hour ago Up About an hour 0.0.0.0:->/tcp, /tcp zabbix-web
d5a45e58b69d zabbix-server "docker-entrypoint.sh" hours ago Up hours 0.0.0.0:->/tcp zabbix-server
cd16d62b98c4 zabbix-java-gateway "docker-entrypoint.sh" hours ago Up hours 0.0.0.0:->/tcp zabbix-java-gateway
6a4b9ce12398 debian-mysql5. "docker-entrypoint.s…" hours ago Up hours 3306
/tcp, /tcp debian-mysql-5.

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

zabbix-agent

安装(用官方yum源)

#rpm -i 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
#vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.130.6
UnsafeUserParameters=
Include=/etc/zabbix/zabbix_agentd.d/*.conf
# systemctl start zabbix-agent

注意:如果要对宿主机进行监控,请编辑宿主机的zabbix_agentd.conf,将Server地址,默认127.0.0.1,修改为docker-server容器地址,否则不通;如果是对其他主机的监控则使用docker-zabbix-server宿主机的IP。

查看容器Zabbix-server的地址

# docker exec -it zabbix-server ip addr
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
: eth0@if24: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu qdisc noqueue state UP
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff
inet 172.17.0.4/ brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever

使用docker-compose

docker-compose去做,该镜像版本为4.0.1

安装docker-compose

# curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
# docker-compose --version
docker-compose version 1.23., build b02f1306

编写zabbix.yml

这个已经是写好的,拿过去直接用吧,image不要动,其他的看自己情况自行调整吧

# mkdir /docker-compose
# cd /docker-compose/
/docker-compose]# vim zabbix.yml
version: ''
services:
mysql:
image: swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-mysql
environment:
MYSQL_USER: zabbix
MYSQL_DATABASE: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_ROOT_PASSWORD: Sowhat?
volumes:
- /data/mysql/zabbix:/var/lib/mysql
ports:
- :
restart: always
networks:
- zabbix zabbix-java-gateway:
image: swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-java-gateway
ports:
- :
restart: always
networks:
- zabbix zabbix-server:
image: swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-server
environment:
DB_SERVER_HOST: mysql
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_ROOT_PASSWORD: Sowhat?
links:
- mysql
ports:
- :
depends_on:
- mysql
restart: always
networks:
- zabbix zabbix-web:
image: swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-web
environment:
PHP_TZ: Asia/Shanghai
DB_SERVER_HOST: mysql
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_ROOT_PASSWORD: Sowhat?
links:
- mysql
ports:
- :
depends_on:
- zabbix-server
- mysql
restart: always
networks:
- zabbix networks:
zabbix:
driver: bridge

启动容器组

/docker-compose]# docker-compose -f zabbix.yml up -d --build
Creating network "dockercompose_zabbix" with driver "bridge"
Pulling zabbix-java-gateway (swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-java-gateway:latest)...
latest: Pulling from rj-bai/zabbix-java-gateway
c67f3896b22c: Pull complete
28bd08666da4: Pull complete
21b8ee686afa: Pull complete
824932b5f2bc: Pull complete
8684d0f43c47: Pull complete
e29aa4d7f4bf: Pull complete
b908f38442f8: Pull complete
2384821aec7a: Pull complete
Digest: sha256:fc95fd77ab38768b0d35101b19622c73d1aa7f0fdda0e4c82699f15c4a1dfa8c
Status: Downloaded newer image for swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-java-gateway:latest
Pulling mysql (swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-mysql:latest)...
latest: Pulling from rj-bai/zabbix-mysql
a5a6f2f73cd8: Pull complete
936836019e67: Pull complete
283fa4c95fb4: Pull complete
1f212fb371f9: Pull complete
e2ae0d063e89: Pull complete
5ed0ae805b65: Pull complete
0283dc49ef4e: Pull complete
a7905d9fbbea: Pull complete
cd2a65837235: Pull complete
5f906b8da5fe: Pull complete
e81e51815567: Pull complete
423a0fdeb46c: Pull complete
Digest: sha256:74a62f652e6cc5ba4ac8ec28e55227c781b5b1bf5d8533597e4200353f2c00ed
Status: Downloaded newer image for swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-mysql:latest
Pulling zabbix-server (swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-server:latest)...
latest: Pulling from rj-bai/zabbix-server
d6a5679aa3cf: Pull complete
7a046b910a3c: Pull complete
497545b1664f: Pull complete
58ac09628c71: Pull complete
9e045e3ec3a3: Pull complete
432e63b42dc5: Pull complete
Digest: sha256:69d854834e344bb512d8f70cbeaf2226db5db5b19c926545fc598e04e0d1156c
Status: Downloaded newer image for swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-server:latest
Pulling zabbix-web (swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-web:latest)...
latest: Pulling from rj-bai/zabbix-web
c67f3896b22c: Already exists
90884e24b31c: Pull complete
c9ddded2780e: Pull complete
1fb53af6cb01: Pull complete
fbefe3595fbc: Pull complete
6b4acce82f87: Pull complete
a4bf8619ae81: Pull complete
604f32616982: Pull complete
1bf0ca328b88: Pull complete
913cf2a0cff6: Pull complete
571ab96e2d5b: Pull complete
e6e318768910: Pull complete
ad8b7746cfb4: Pull complete
76a428e15158: Pull complete
Digest: sha256:6435ee08428960c7f8385e783b776c15eb2f5bcc4fc4671fb40eabd95da204d8
Status: Downloaded newer image for swr.cn-north-.myhuaweicloud.com/rj-bai/zabbix-web:late
Creating dockercompose_zabbix-java-gateway_1 ... done
Creating dockercompose_mysql_1 ...
Creating dockercompose_zabbix-server_1 ... done
Creating dockercompose_zabbix-server_1 ...
Creating dockercompose_zabbix-web_1 ... done
/docker-compose]# docker-compose -f docker-compose.yml ps Name Command State Ports
------------------------------------------------------------------------------------------------------
zabbix_mysql_1 docker-entrypoint.sh mysqld Up 0.0.0.0:->/tcp, /tcp
zabbix_zabbix-java-gateway_1 docker-entrypoint.sh Up 0.0.0.0:->/tcp
zabbix_zabbix-server_1 docker-entrypoint.sh Up 0.0.0.0:->/tcp
zabbix_zabbix-web_1 docker-entrypoint.sh Up /tcp, 0.0.0.0:->/tcp
ps:容器启动完毕!

安装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.
#docker exec -it zabbix_zabbix-server_1 ip addr
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
: eth0@if13: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu qdisc noqueue state UP
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff
inet 172.18.0.4/ brd 172.18.255.255 scope global eth0
valid_lft forever preferred_lft forever
# vim /etc/zabbix/zabbix_agentd.conf
Server=172.18.0.4
UnsafeUserParameters=
Include=/etc/zabbix/zabbix_agentd.d/*.conf
# systemctl start zabbix-agent.service

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

网页端操作

直接编辑名为zabbix server的主机,Agent interfaces改为宿主机内网IP,然后update,我顺便又手动加了个主机进来,监控别的主机server地址直接写zabbix server宿主机即可。

邮件报警

以nginx down 为例前面博客有具体操作,这就不再赘述。

邮件设置

点开AdministrationMedia typesEmail编辑,以使qq邮箱为例,163邮箱收不到。

添加收件人

接下来去Configurationactions,选择Triggers,添加触发条件,可以有多个,我添加的是时间段和触发器。

在Acrion里添加动作—>operations

测试

手动停掉nginx

^<>^

部署完成,有什么错误望指出,谢谢!

参考: https://blog.rj-bai.com/post/144.html

基于docker部署zabbix的更多相关文章

  1. Docker部署Zabbix+Grafana监控

    Docker部署Zabbix+Grafana监控 环境 centos 7 ; Docker 17.12.0-ce ; docker-compose version 1.20.1 2018-4-1 当前 ...

  2. 基于Docker部署nodejs应用

    基于Docker部署nodejs应用 背景 公司基于Vue.js的项目最近需要部署到云端,因此需要先行在公司内部Docker环境下验证相关技术,因而有本文之前提. 本文展示在Docker容器中,应用部 ...

  3. 基于Docker部署ETCD集群

    基于Docker部署ETCD集群 关于ETCD要不要使用TLS? 首先TLS的目的是为了鉴权为了防止别人任意的连接上你的etcd集群.其实意思就是说如果你要放到公网上的ETCD集群,并开放端口,我建议 ...

  4. docker部署zabbix并设置自动发现规则

      docker部署zabbix比源码安装简单一些,特此记录: 机器准备: zabbix-server: 192.168.0.150 homeserver zabbix-agent: 192.168. ...

  5. docker 部署 zabbix

    docker部署zabbix   我相信大家都已经会再物理机上跑zabbix并且监控了,那么有没有想过在docker中跑zabbix?下面咱们来看看如何在docker中搭建zabbix并且监控 部署环 ...

  6. Docker部署Zabbix监控MariaDB主从同步(Percona Monitoring Plugins for Zabbix)

    一.安装Docker并部署Zabbix 建议先配置清华大学的docker-ce yum源,速度有保障:清华大学repo源 1.Zabbix Server节点配置 部署环境: [root@server0 ...

  7. docker部署zabbix

    我相信大家都已经会再物理机上跑zabbix并且监控了,那么有没有想过在docker中跑zabbix?下面咱们来看看如何在docker中搭建zabbix并且监控 部署环境 2台物理机机器: zabbix ...

  8. Ubuntu系统下基于docker部署Jenkins环境

    本文是在ubuntu环境下安装jenkins,jenkins运行在docker容器中, 至于docker如何安装,请参考https://www.cnblogs.com/xingyunqiu/p/115 ...

  9. 基于docker部署jenkins

    1. 拉镜像 和其他的部署的镜像的方式一样,通常是直接使用docker search jenkins 然后直接docker pull jenkins 此时,在安装插件的时候发现插件都安装失败,提示je ...

随机推荐

  1. iOS开发-NSString去掉所有换行及空格

    1.去掉字符串两端的空格及回车 - (NSString *)removeSpaceAndNewline:(NSString *)str{ NSString *temp = [str stringByT ...

  2. Linux 之 压缩解压缩

    Linux中常见的压缩格式 .zip            .gz             .bz2           .tar.gz      tar.bz2 zip zip格式的压缩文件和win ...

  3. MySql 安装及实用笔记

    安装 更新 rpm 包 rpm -Uvh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm 安装MySql yum - ...

  4. 基于CentOS设置和使用Yum软件仓库

    参考:How To Set Up and Use Yum Repositories on a CentOS 6 VPS 参考:CentOS yum 源的配置与使用 介绍 Yum仓库是Linux软件仓库 ...

  5. 【迭代博弈+搜索+剪枝】poj-1568--Find the Winning Move

    poj  1568:Find the Winning Move   [迭代博弈+搜索+剪枝] 题面省略... Input The input contains one or more test cas ...

  6. GIS 基础知识简介

    前言 前一段时间,在公司进行了分析 GIS 基础信息的介绍.之所以会有这个介绍以及为什么是我?这个个中缘由说下. 公司不是一个GIS方面的公司,但是由于业务的需要,经常需要用到地图(要和地图打交道), ...

  7. 《少年先疯队》第七次作业:团队项目设计完善&编码

    博文简要信息表: 项目 内容 软件工程 https://www.cnblogs.com/nwnu-daizh/ 本次实验链接地址 https://www.cnblogs.com/nwnu-daizh/ ...

  8. Git----常见工作管理总结

    1.工作流程模式: 首先,可以试图用git push origin branch-name推送自己的修改 如果推送失败,则因为远程分支比你的本地更新,需要先用git pull试图合并 如果合并有冲突, ...

  9. springcloud注册中心Eureka<英 [juəˈri:kə]>的基本搭建

    1.http://start.spring.io搭建基本的springboot环境,版本用的是1.5.10 2.在pom文件中添加注册中心的jar包和springcloud的jar包 <!-- ...

  10. finally关键字执行的底层原理

    1.举例子: 在主方法中调用m1方法,finally中 i 变量自增,但结果却是10 public static void main(String[] args) { int i = m1(); Sy ...