基于docker部署zabbix
基础环境
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部署阶段
要用docker
跑zabbix-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
端口,指定数据库服务器,连接MySQL
和zabbix-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 为例前面博客有具体操作,这就不再赘述。
邮件设置
点开Administration
→Media types
→Email
编辑,以使qq邮箱为例,163邮箱收不到。
添加收件人
接下来去Configuration
→actions
,选择Triggers
,添加触发条件,可以有多个,我添加的是时间段和触发器。
在Acrion里添加动作—>operations
测试
手动停掉nginx
^<>^
部署完成,有什么错误望指出,谢谢!
参考: https://blog.rj-bai.com/post/144.html
基于docker部署zabbix的更多相关文章
- Docker部署Zabbix+Grafana监控
Docker部署Zabbix+Grafana监控 环境 centos 7 ; Docker 17.12.0-ce ; docker-compose version 1.20.1 2018-4-1 当前 ...
- 基于Docker部署nodejs应用
基于Docker部署nodejs应用 背景 公司基于Vue.js的项目最近需要部署到云端,因此需要先行在公司内部Docker环境下验证相关技术,因而有本文之前提. 本文展示在Docker容器中,应用部 ...
- 基于Docker部署ETCD集群
基于Docker部署ETCD集群 关于ETCD要不要使用TLS? 首先TLS的目的是为了鉴权为了防止别人任意的连接上你的etcd集群.其实意思就是说如果你要放到公网上的ETCD集群,并开放端口,我建议 ...
- docker部署zabbix并设置自动发现规则
docker部署zabbix比源码安装简单一些,特此记录: 机器准备: zabbix-server: 192.168.0.150 homeserver zabbix-agent: 192.168. ...
- docker 部署 zabbix
docker部署zabbix 我相信大家都已经会再物理机上跑zabbix并且监控了,那么有没有想过在docker中跑zabbix?下面咱们来看看如何在docker中搭建zabbix并且监控 部署环 ...
- Docker部署Zabbix监控MariaDB主从同步(Percona Monitoring Plugins for Zabbix)
一.安装Docker并部署Zabbix 建议先配置清华大学的docker-ce yum源,速度有保障:清华大学repo源 1.Zabbix Server节点配置 部署环境: [root@server0 ...
- docker部署zabbix
我相信大家都已经会再物理机上跑zabbix并且监控了,那么有没有想过在docker中跑zabbix?下面咱们来看看如何在docker中搭建zabbix并且监控 部署环境 2台物理机机器: zabbix ...
- Ubuntu系统下基于docker部署Jenkins环境
本文是在ubuntu环境下安装jenkins,jenkins运行在docker容器中, 至于docker如何安装,请参考https://www.cnblogs.com/xingyunqiu/p/115 ...
- 基于docker部署jenkins
1. 拉镜像 和其他的部署的镜像的方式一样,通常是直接使用docker search jenkins 然后直接docker pull jenkins 此时,在安装插件的时候发现插件都安装失败,提示je ...
随机推荐
- Ant环境安装
一:下载安装Ant,配置环境变量 1.进入http://ant.apache.org/bindownload.cgi下载ant 2.配置环境变量 新建ANT_HOME 配置path环境变量 配置cla ...
- Linux 之 压缩解压缩
Linux中常见的压缩格式 .zip .gz .bz2 .tar.gz tar.bz2 zip zip格式的压缩文件和win ...
- Python面向对象之进阶
一.property 内置函数 装饰器的使用:所有的装饰器函数.方法.类的上一行直接@装饰器的名字 装饰器的分类: ① 装饰函数 ② 装饰方法 ③ 装饰类 property 是一个装饰器函数 @pro ...
- Ubuntu:一个部署好的tomcat应用(war包)怎么用Nginx实现动静分离?
今天想把之前的一个demo用Nginx把资源分离开来,在网上看了一天,整整弄了一天,硬是没弄出来. 要么全是同样的内容的,要么就是环境跟我这里不一样的.再加上对Nginx没接触过,给我都整哭了差点. ...
- git命令——git rm、git mv
git rm git rm命令官方解释 删除的本质 在git中删除一个文件,本质上是从tracked files中移除对这些文件的跟踪.更具体地说,就是将这些文件从staging area移除.然后c ...
- Linux VPS搭建蚂蚁笔记Leanote私有云笔记存储平台
一.基础环境LNMP 安装nginx: yum install epel-release -y yum install nginx -y # 启动 nginx systemctl start ngin ...
- Codeforces Round #524 (Div. 2) Masha and two friends矩形
题目 题意: 给一个n*m块大的黑白相间的矩形,在这个举行中操作,要先把第一个矩形(左下角坐标(x1,y2),右上角坐标(x2,y2)) 全部涂成白色,再把第二个矩形(左下角坐标(x3,y3), ...
- SegNet网络的Pytorch实现
1.文章原文地址 SegNet: A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation 2.文章摘要 语义分 ...
- 链表(python)
链表1.为什么需要链表顺序表的构建需要预先知道数据大小来申请连续的存储空间,而在进行扩充时又需要进行数据的搬迁,所以使用起来并不是很灵活.链表结构可以充分利用计算机内存空间,实现灵活的内存动态管理. ...
- mybatis3.1-[topic-16-17]-映射文件_增删改查_insert_获取自增主键的值
笔记要点出错分析与总结 /**测试第16章的增,删,改 的内容 * 错误1: <insert id="addEmp" parameterType="com.bean ...