零、Zabbix架构设计

一、docker安装mysql

查找Docker Hub上的mysql镜像:
[root@10e131e69e15 ~]# docker search mysql
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/mysql MySQL is a widely used, open-source relati... [OK]
docker.io docker.io/mariadb MariaDB is a community-developed fork of M... [OK]
docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... [OK]
docker.io docker.io/percona Percona Server is a fork of the MySQL rela... [OK]
docker.io docker.io/zabbix/zabbix-server-mysql Zabbix Server with MySQL database support [OK]
docker.io docker.io/hypriot/rpi-mysql RPi-compatible Docker Image with Mysql
docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... [OK]
docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... [OK]
docker.io docker.io/1and1internet/ubuntu--nginx-php-phpmyadmin-mysql- ubuntu--nginx-php-phpmyadmin-mysql- [OK]
docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ...
docker.io docker.io/centos/mysql--centos7 MySQL 5.7 SQL database server
docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ...
docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... [OK]
docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image [OK]
docker.io docker.io/zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support [OK]
docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux...
docker.io docker.io/centos/mysql--centos7 MySQL 5.6 SQL database server
docker.io docker.io/openshift/mysql--centos7 DEPRECATED: A Centos7 based MySQL v5. ima...
docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati...
docker.io docker.io/dsteinkopf/backup-all-mysql backup all DBs in a mysql server [OK]
docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ...
docker.io docker.io/openzipkin/zipkin-mysql Mirror of https://quay.io/repository/openz... 1
docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL [OK]
docker.io docker.io/cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release
docker.io docker.io/cloudposse/mysql Improved `mysql` service with support for ... [OK]

拉取镜像,我们选择docker.io/mariadb :

[root@10e131e69e15 fanzhang]# docker pull docker.io/mariadb
Using default tag: latest
Trying to pull repository docker.io/library/mariadb ...
latest: Pulling from docker.io/library/mariadb
d660b1f15b9b: Pull complete
c31ac90ebb2f: Pull complete
cb961997371e: Pull complete
02bce683987d: Pull complete
5af7bdeee6f7: Pull complete
16ef8af3c61e: Pull complete
1e3f09afcb5a: Pull complete
5aa0d4b7a708: Pull complete
62094a39ba6f: Pull complete
d1a8f0e27318: Pull complete
8dfdb13e87fc: Pull complete
Digest: sha256:dd8dc06353887dc8235ca83701418dcd29e505301db417439205ed67350d61dc
[root@10e131e69e15 fanzhang]# docker images | grep mariadb
docker.io/mariadb latest 13814daf85b2 hours ago 403.3 MB

在目录/root/fanzhang/docker/mysql下创建目录conf/,data/,logs/分别用于映射配置文件、数据和日志,然后运行容器,使用mariadb镜像:

[root@10e131e69e15 fanzhang]# docker run -p : --name f-mysql -v /root/fanzhang/docker/mysql/conf:/etc/mysql/conf.d -v /root/fanzhang/docker/mysql/logs:/logs -v /root/fanzhang/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD= -d mariadb:latest
e7185734f25f0835b73e90fd152b3b158d824c7fa2ef403db163092c23fcd935
[root@10e131e69e15 fanzhang]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e7185734f25f mariadb:latest "docker-entrypoint.sh" About a minute ago Up About a minute 0.0.0.0:->/tcp f-mysql
数据库已经准备就绪,可以继续在8.15上安装zabbix server了。

二、docker安装zabbix server

安装zabbix-server-mysql——
拉取镜像:
[root@10e131e69e15 fanzhang]# docker pull docker.io/zabbix/zabbix-server-mysql
Using default tag: latest
Trying to pull repository docker.io/zabbix/zabbix-server-mysql ...
latest: Pulling from docker.io/zabbix/zabbix-server-mysql
81033e7c1d6a: Pull complete
bccf9f908b27: Pull complete
965ee7bfa719: Pull complete
7deb88b70343: Pull complete
Digest: sha256:a2d540d535592386bed8a80c1843c1c12d09f1fe7a8ddd37bd83186844367a67
使用镜像运行容器:
[root@10e131e69e15 fanzhang]# docker run --name f-zabbix-server -p : --net=host -e DB_SERVER_HOST="172.28.8.15" -e DB_SERVER_PORT= -e MYSQL_USER="root" -e MYSQL_PASSWORD="" -d docker.io/zabbix/zabbix-server-mysql
7b9d1d8d81924c0734821938bc766d3f3e3f2d70440a1e3c3cecced7746f7279
安装zabbix-web-apache-mysql——
拉取镜像:
[root@10e131e69e15 fanzhang]# docker pull docker.io/zabbix/zabbix-web-apache-mysql
Using default tag: latest
Trying to pull repository docker.io/zabbix/zabbix-web-apache-mysql ...
latest: Pulling from docker.io/zabbix/zabbix-web-apache-mysql
ff3a5c916c92: Already exists
a7a4b5e0d00c: Pull complete
d7f46e4857f7: Pull complete
379a306f2512: Pull complete
4581d8b8f55f: Pull complete
fe1fb7155519: Pull complete
3365aba7f13f: Pull complete
e751c6e1609e: Pull complete
1f4b0cab6e61: Pull complete
Digest: sha256:a74698f357945c72f147709bafb9228687ffea5c82ada2486ee96471c7732b18

使用镜像运行容器(注意,-p 将容器的80端口映射到宿主机的8088端口):

[root@10e131e69e15 fanzhang]# docker run --name f-zabbix-web-apache-mysql -p : -e DB_SERVER_HOST="172.28.8.15" -e DB_SERVER_PORT= -e MYSQL_USER="root" -e MYSQL_PASSWORD="" -e ZBX_SERVER_HOST="172.28.8.15" -e TZ="Asia/Shanghai" -d zabbix/zabbix-web-apache-mysql
393df8ea3865a415aedcbcad4163f80f3baae828f0f29f08b3a515e51d382177

在8.15上打开防火墙的8088端口:

iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport  -j ACCEPT
启动报错,可以通过docker logs <container_name>检查。
zabbix-server-mysql、zabbix-web-apache-mysql启动后,尝试:
[root@10e131e69e15 fanzhang]# curl 172.28.8.15:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="Author" content="Zabbix SIA" />
<title>Warning [refreshed every sec.]</title>
<link rel="icon" href="favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="img/apple-touch-icon-76x76-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="img/apple-touch-icon-120x120-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="img/apple-touch-icon-152x152-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="img/apple-touch-icon-180x180-precomposed.png">
<link rel="icon" sizes="192x192" href="img/touch-icon-192x192.png">
<meta name="csrf-token" content=""/>
<meta name="msapplication-TileImage" content="img/ms-tile-144x144.png">
<meta name="msapplication-TileColor" content="#d40000">
<meta name="msapplication-config" content="none"/>
<link rel="stylesheet" type="text/css" href="styles/blue-theme.css" />
</head>
<body><div class="article"><div class="msg-bad msg-global">Database error<div class="msg-details"><ul class="msg-details-border"><li>Error connecting to database: Unknown database 'zabbix'</li></ul></div><div class="msg-buttons"><button type="button" onclick="document.location.reload();">Retry</button></div></div></div><script type="text/javascript">
setTimeout('document.location.reload();', );

手动创建zabbix数据库,尝试curl:

[root@10e131e69e15 fanzhang]# curl 172.28.8.15:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="Author" content="Zabbix SIA" />
<title>Warning [refreshed every sec.]</title>
<link rel="icon" href="favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="img/apple-touch-icon-76x76-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="img/apple-touch-icon-120x120-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="img/apple-touch-icon-152x152-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="img/apple-touch-icon-180x180-precomposed.png">
<link rel="icon" sizes="192x192" href="img/touch-icon-192x192.png">
<meta name="csrf-token" content=""/>
<meta name="msapplication-TileImage" content="img/ms-tile-144x144.png">
<meta name="msapplication-TileColor" content="#d40000">
<meta name="msapplication-config" content="none"/>
<link rel="stylesheet" type="text/css" href="styles/blue-theme.css" />
</head>
<body><div class="article"><div class="msg-bad msg-global">Database error<div class="msg-details"><ul class="msg-details-border"><li>The frontend does not match Zabbix database.</li></ul></div><div class="msg-buttons"><button type="button" onclick="document.location.reload();">Retry</button></div></div></div><script type="text/javascript">
setTimeout('document.location.reload();', );

进入容器检查数据库连接:

[root@10e131e69e15 zabbix]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
393df8ea3865 zabbix/zabbix-web-apache-mysql "docker-entrypoint.sh" minutes ago Up minutes /tcp, 0.0.0.0:->/tcp f-zabbix-web-apache-mysql
4888e711e776 docker.io/zabbix/zabbix-server-mysql "docker-entrypoint.sh" minutes ago Up minutes f-zabbix-server
e7185734f25f mariadb:latest "docker-entrypoint.sh" minutes ago Up minutes 0.0.0.0:->/tcp f-mysql
[root@10e131e69e15 zabbix]# docker exec -it 4888e711e776 /bin/bash
bash-4.3# mysql -uroot -p123456 -h 172.28.8.15 -P
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.3.-MariaDB-:10.3.+maria~jessie mariadb.org binary distribution
Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
rows in set (0.01 sec)
MariaDB [(none)]> quit
Bye
bash-4.3# [root@10e131e69e15 zabbix]# docker exec -it 393df8ea3865 /bin/bash
bash-4.4# mysql -uroot -p123456 -h 172.28.8.15 -P
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.3.-MariaDB-:10.3.+maria~jessie mariadb.org binary distribution
Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
rows in set (0.00 sec)
MariaDB [(none)]>
可以看到,其实是可以连接数据库的,那么问题出在哪里呢?
还是依次检查一下启动的两个zabbix相关的容器,看下其日志:
[root@10e131e69e15 fanzhang]# docker logs f-zabbix-server
** Deploying Zabbix server with mysql database
** Preparing the system
** Preparing Zabbix server
********************
* DB_SERVER_HOST: 172.28.8.15
* DB_SERVER_PORT:
* DB_SERVER_DBNAME: zabbix
* DB_SERVER_ZBX_USER: “root -e MYSQL_PASSWORD=“
* DB_SERVER_ZBX_PASS: zabbix
********************
mysqladmin: unknown option '-e'
**** MySQL server is not available. Waiting seconds…
可以发现,user的配置并不正确,应该是中文字符的锅。删除这个容器,重新启动。
[root@10e131e69e15 fanzhang]# docker run --name f-zabbix-server -p : --net=host -e DB_SERVER_HOST="172.28.8.15" -e DB_SERVER_PORT= -e MYSQL_USER="root" -e MYSQL_PASSWORD="" -d docker.io/zabbix/zabbix-server-mysql
98facac20dd8d37769c0b64718d70d796f58703528f61e053d1cc5dddaffb817
[root@10e131e69e15 fanzhang]# docker logs f-zabbix-server
** Deploying Zabbix server with mysql database
** Preparing the system
** Preparing Zabbix server
********************
* DB_SERVER_HOST: 172.28.8.15
* DB_SERVER_PORT:
* DB_SERVER_DBNAME: zabbix
* DB_SERVER_ZBX_USER: root
* DB_SERVER_ZBX_PASS:
********************
** Creating 'root' user in MySQL database
** Database 'zabbix' already exists. Please be careful with database COLLATE!
** Creating 'zabbix' schema in MySQ
这次应该是没问题了。
我们再看下f-zabbix-web-apache-mysql的日志,一切正常。

三、vm内部安装zabbix agent

尝试使用直接在计算节点和控制节点上安装zabbix-agent的方式:
rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

通过这种方式安装了zabbix-agent还是无法发现主机,因为zabbix-agent上的10050端口和zabbix-server的10051端口并没有打开:

iptables -I INPUT -p tcp --dport  -j ACCEPT
iptables -I INPUT -p tcp --dport -j ACCEPT

防火墙放开后,发现zabbix-agent unreachable,查看日志发现:

[root@f-q-c ~]# iptables -I INPUT -p tcp --dport  -j ACCEPT
[root@f-q-c ~]# tailf /var/log/zabbix/zabbix_agentd.log
::150758.073 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::150858.107 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::150958.144 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::151058.191 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::151158.237 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::151258.351 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::151358.541 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::151458.712 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::151558.906 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: "172.28.8.15"
::151658.952 failed to accept an incoming connection: connection from "192.168.122.1" rejected, allowed hosts: “172.28.8.15"

192.168.122.1是网关地址,在8.15上是这样一个设备:

: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu  qdisc noqueue state UP qlen
link/ether :::d7:: brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/ brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
那么我们调整一下zabbix-agent的配置:
Server=172.28.8.15,192.168.122.1/
然后重启zabbix-agent。
稍等片刻,即可在zabbix页面看到监控的情况(注意增加模板和设置聚合图形):

Docker安装Zabbix全记录的更多相关文章

  1. SAP S4HANA1610/Fiori安装过程全记录

    经历各种坑,从硬件到文件,终于安装成功. 有需要安装或使用S4HANA(含Fiori)的同学可以参考. 安装文件分享给大家 链接:http://pan.baidu.com/s/1mi7LfIS 密码: ...

  2. CentOS7下载与安装错误全记录

    这篇文章记录安装CentOS7过程错误全记录,供大家和自己参考 起因:笔记本用的win10系统,开启热点的时候,总是10分钟就自动关闭.于是折腾linux系统,平时用win10系统,也切换到linux ...

  3. docker安装Zabbix

    1. 先安装数据库mysqldocker run --name zabbix-mysql-server --hostname zabbix-mysql-server \-e MYSQL_ROOT_PA ...

  4. 在CentOS6上编译安装实现LAMP(php-modules)+phpMyAdmin安装过程全记录

    php与apache协作有三种模式:CGI.modules.FastCGI. 在CGI模式下,用户请求php文件时,apache会启动响应进程,调用php处理器处理请求,然后将结果返回给客户端.用户响 ...

  5. docker安装踩坑记录

    .docker安装包安装很顺利, yum安装安装源在官网或镜像网站下载, fedora/centos分别下载不同的, 在/etc/yum.repos.d/doccker-ce.repo, 把网址改为镜 ...

  6. 线上服务器PHP版本编译安装升级全记录

    1.将原来的PHP重命名一下 cd /usr/local/bin/ mv php php.2.9 2.安装依赖 yum install gcc gcc-c++ libxml2 libxml2-deve ...

  7. 源码编译mysql 5.5+ 安装过程全记录

    前言:从mysql 5.5版本开始,mysql源码安装开始使用cmake了,编译安装跟以前的版本有点不一样了. 一,安装步骤: 1.安装前准备工作 a.下载mysql源代码包,到mysql下载页面选择 ...

  8. 在 VMware 中安装 MacOS 全记录

    在 VMware 15 中安装 MacOS Mojave 安装文件 下载:Unlocker v3.0 for VMware 15地址:https://github.com/DrDonk/unlocke ...

  9. docker部署安装zabbix

    安装docker 安装docker需要配置网络yum源,centos7自带的版本太低了 第一步:下载阿里云的docker安装包 在yum仓库的目录之下 [root@localhost yum.repo ...

随机推荐

  1. jquery 跨域获取网页数据

    <script language="javascript" src="http://cbsahhs.blog.163.com/jquery.min.js" ...

  2. wordpress二次开发第一个jquery对比

    $(document).ready(function(){ $("input").focus(function(){ $("input").css(" ...

  3. 跨Vlan通信:单臂路由,三层交换机

    实验涉及命令以及知识补充(涉及Vlan通过的以太网口需要设置为Trunk口) 单臂路由 父接口 no ip address :删除实现单臂路由接口的IP no shutdown 虚拟子接口 R2(co ...

  4. [UNIX]UNIX常用命令总结

    (1)查看服务器IP信息 $netstat -in (2)查看挂载磁盘信息 #sam #需要在root账号下查看

  5. Nacicat for Oracle 绿色版 亲测可用

    参考: http://blog.csdn.net/u013107634/article/details/52741591 https://blog.csdn.net/zhengyikuangge/ar ...

  6. Linux基础 ppt pptx

    引言 以前写过一个讲 Linux 基础的ppt,琢磨着把它分享出来,有需要的请自取. 部分截图如下 下载地址 下载地址1

  7. CF1042C Array Product(贪心,模拟)

    题目描述 You are given an array aa consisting of nn integers. You can perform the following operations w ...

  8. For macOS.百度网盘 破解SVIP、下载速度限制~

    For macOS.百度网盘 破解SVIP.下载速度限制~ 是插件的 https://github.com/CodeTips/BaiduNetdiskPlugin-macOS 2019-01-03 让 ...

  9. 【ssh服务配置】

    根据项目需求,搭建好拓扑图如下: 第一种验证方式:给予密码和用户名登录 Ssh server配置: 首先在服务器上创建一个rsa加密算法的秘钥对: 对ssh服务进行开启: 创建用户的虚拟终端登录界面: ...

  10. WebSocket协议 8 问

    WebSocket是一种比较新的协议,它是伴随着html5规范而生的,虽然还比较年轻,但大多主流浏览器都已经支持.它使用方面.应用广泛,已经渗透到前后端开发的各种场景中. 对http一问一答中二式流程 ...