docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > docker安装部署zabbix

docker安装部署zabbix的全过程

作者:chengxuyonghu

zabbix由2部分构成,zabbix server与可选组件zabbix agent,要想搭建一个Zabbix的工作环境,主要有三个方面(界面、服务器和数据库)可以安装在同一台服务器上,也可以不在同一个服务器,本次使用Docker开源的应用容器来快速搭建zabbix,需要的朋友可以参考下

zabbix由2部分构成,zabbix server与可选组件zabbix agent,要想搭建一个Zabbix的工作环境,主要有三个方面(界面、服务器和数据库)可以安装在同一台服务器上,也可以不在同一个服务器。本次使用Docker开源的应用容器来快速搭建zabbix 。

安装

成功版本:mysql5.7+zabbix4.4.3+nginx1.16
不成功版本:mysql8.0+zabbix4.4.3+nginx1.16

01 docker镜像下载

搭建ZABBIX所需的软件列表为:RHEL8.0+Nginx+MySQL+ZABBIX。所以需要分别下载相应的镜像.

1、先下载mysql镜像,docker查看mysql镜像,下载STARS比较多的镜像

[root@localhost ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   8930                [OK]                
mariadb                           MariaDB is a community-developed fork of MyS…   3140                [OK]                
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   659                                     [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   66                                      
centurylink/mysql                 Image containing mysql. Optimized to be link…   61                                      [OK]
mysql/mysql-cluster               Experimental MySQL Cluster Docker images. Cr…   59                                      
deitch/mysql-backup               REPLACED! Please use http://hub.docker.com/r…   41                                      [OK]
bitnami/mysql                     Bitnami MySQL Docker Image                      35                                      [OK]
tutum/mysql                       Base docker image to run a MySQL database se…   34                                      
schickling/mysql-backup-s3        Backup MySQL to S3 (supports periodic backup…   28                                      [OK]
prom/mysqld-exporter                                                              23                                      [OK]
linuxserver/mysql                 A Mysql container, brought to you by LinuxSe…   22                                      
centos/mysql-56-centos7           MySQL 5.6 SQL database server                   17                                      
circleci/mysql                    MySQL is a widely used, open-source relation…   16                                      
mysql/mysql-router                MySQL Router provides transparent routing be…   14                                      
arey/mysql-client                 Run a MySQL client from a docker container      13                                      [OK]
openshift/mysql-55-centos7        DEPRECATED: A Centos7 based MySQL v5.5 image…   6                                       
yloeffler/mysql-backup            This image runs mysqldump to backup data usi…   6                                       [OK]
fradelg/mysql-cron-backup         MySQL/MariaDB database backup using cron tas…   4                                       [OK]
genschsa/mysql-employees          MySQL Employee Sample Database                  3                                       [OK]
devilbox/mysql                    Retagged MySQL, MariaDB and PerconaDB offici…   2                                       
ansibleplaybookbundle/mysql-apb   An APB which deploys RHSCL MySQL                2                                       [OK]
jelastic/mysql                    An image of the MySQL database server mainta…   1                                       
monasca/mysql-init                A minimal decoupled init container for mysql    0                                       
widdpim/mysql-client              Dockerized MySQL Client (5.7) including Curl…   0                                       [OK]
[root@localhost ~]# <strong>docker pull mysql</strong>
Using default tag: latest
latest: Pulling from library/mysql
d599a449871e: Pull complete 
f287049d3170: Pull complete 
08947732a1b0: Pull complete 
96f3056887f2: Pull complete 
871f7f65f017: Pull complete 
1dd50c4b99cb: Pull complete 
5bcbdf508448: Pull complete 
a59dcbc3daa2: Pull complete 
13e6809ab808: Pull complete 
2148d51b084d: Pull complete 
93982f7293d7: Pull complete 
e736330a6d9c: Pull complete 
Digest: sha256:c93ba1bafd65888947f5cd8bd45deb7b996885ec2a16c574c530c389335e9169
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@localhost ~]# <strong>docker images</strong>
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
kali                latest              953ce62dfa5a        45 hours ago        9.97GB
tomcat              latest              6408fdc94212        2 weeks ago         507MB
mysql               latest              d435eee2caa5        2 weeks ago         456MB

2、下载zabbix-server镜像,可以看到zabbix-server有MySQL版和postgresql版本,我们选择第一个mysql的版本。

[root@localhost ~]# docker search zabbix
NAME                                        DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
zabbix/zabbix-server-mysql                  Zabbix Server with MySQL database support       213                                     [OK]
zabbix/zabbix-agent                         Zabbix agent with TLS encryption support        126                                     [OK]
zabbix/zabbix-web-nginx-mysql               Zabbix frontend based on Nginx web-server wi…   118                                     [OK]
monitoringartist/zabbix-3.0-xxl             Please use our better compatible Zabbix imag…   77                                      [OK]
monitoringartist/zabbix-xxl                 Zabbix 3.x - server, web, proxy, java gatewa…   72                                      [OK]
zabbix/zabbix-server-pgsql                  Zabbix server with PostgreSQL database suppo…   55                                      [OK]
zabbix/zabbix-appliance                     Zabbix appliance with MySQL database support…   50                                      [OK]
zabbix/zabbix-web-nginx-pgsql               Zabbix frontend based on Nginx with PostgreS…   40                                      [OK]
zabbix/zabbix-web-apache-mysql              Zabbix frontend based on Apache web-server w…   37                                      [OK]
monitoringartist/zabbix-agent-xxl-limited   Please use better agent image https://hub.do…   31                                      
zabbix/zabbix-proxy-sqlite3                 Zabbix proxy with SQLite3 database support      23                                      [OK]
zabbix/zabbix-proxy-mysql                   Zabbix proxy with MySQL database support        23                                      [OK]
zabbix/zabbix-java-gateway                  Zabbix Java Gateway                             19                                      [OK]
zabbix/zabbix-snmptraps                     Receiving SNMP traps to Zabbix server or Zab…   12                                      [OK]
monitoringartist/zabbix-db-mariadb          Docker image of MariaDB optimized for Zabbix    12                                      [OK]
j90w/zabbix-server                          Automatically install Zabbix-server             9                                       
million12/zabbix-agent                      Zabbix Agent - running in foreground.           7                                       [OK]
zabbix/zabbix-web-apache-pgsql              Zabbix frontend based on Apache web-server w…   7                                       [OK]
blackcobra1973/zabbix-db-postgresql         PostgreSQL on CentOS 7.x with Zabbix 3.0 dat…   2                                       [OK]
dsteinkopf/zabbix-proxy-mysql-no-fping6     Zabbix proxy avoiding problems without ipv6.    1                                       [OK]
monitoringartist/zabbix-2.4                 Dockerized Zabbix 2.4 - server, web UI - dep…   1                                       [OK]
jetbrainsinfra/zabbix-proxy                 zabbix-proxy                                    0                                       [OK]
signnow/zabbix-proxy-mysql                  Zabbix Proxy (MySQL version) with Python 3.5…   0                                       
qk4l/zabbix-cachet                          Python script for Zabbix to Cachet integrati…   0                                       [OK]
pdffiller/zabbix-proxy-mysql                Zabbix Proxy (MySQL version) with Python 3.5…   0 
[root@localhost ~]# docker pull zabbix/zabbix-server-mysql
Using default tag: latest
latest: Pulling from zabbix/zabbix-server-mysql
89d9c30c1d48: Pull complete 
8a9f13524790: Pull complete 
42606b325a19: Pull complete 
11fa53e6b556: Pull complete 
Digest: sha256:608b21422412b1e28f3af83f2109a48c18b9de721a8ea91258bcdc586eb00d60
Status: Downloaded newer image for zabbix/zabbix-server-mysql:latest
docker.io/zabbix/zabbix-server-mysql:latest
[root@localhost ~]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
kali                         latest              953ce62dfa5a        46 hours ago        9.97GB
zabbix/zabbix-server-mysql   latest              6da679c2a6c6        2 weeks ago         65.8MB
tomcat                       latest              6408fdc94212        2 weeks ago         507MB
mysql                        latest              d435eee2caa5        2 weeks ago         456MB

3、下载Zabbix web镜像,这里使用的是基于Nginx web服务器mysql版。

[root@localhost ~]# docker search zabbix-web
NAME                                            DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
zabbix/zabbix-web-nginx-mysql                   Zabbix frontend based on Nginx web-server wi…   118                                     [OK]
zabbix/zabbix-web-nginx-pgsql                   Zabbix frontend based on Nginx with PostgreS…   40                                      [OK]
zabbix/zabbix-web-apache-mysql                  Zabbix frontend based on Apache web-server w…   37                                      [OK]
zabbix/zabbix-web-apache-pgsql                  Zabbix frontend based on Apache web-server w…   7                                       [OK]
fablaporta/zabbix-web-nginx-mysql                                                               0                                       
fabrizio2210/zabbix-web-nginx-mysql-alpine                                                      0                                       
westerus/zabbix-web-nginx-mysql                 Container de Zabbix Web Mysql con algunas mo…   0                                       [OK]
epicmorg/zabbix-web-apache-mysql                zabbix/zabbix-web-apache-mysql                  0                                       
aispcf/zabbix-web-apache-mysql                                                                  0                                       
yakumosaki/zabbix-web-nginx-mysql               zabbix-web-nginx-mysql aarch64                  0                                       
wildsurfer/zabbix-web-monitoring                Automated creation of web scenarios in Zabbix   0                                       [OK]
pschmitt/zabbix-web-nginx-pgsql-alpine-armhf                                                    0                                       
flelli/zabbix-web-nginx-pgsql                   My own customization of the official Zabbix …   0                                       [OK]
fablaporta/zabbix-web-apache-mysql                                                              0                                       
pschmitt/zabbix-web-apache-mysql-alpine-armhf                                                   0                                       
pschmitt/zabbix-web-apache-pgsql-alpine-armhf                                                   0                                       
secopstech/zabbix-web-nginx-mysql               zabbix-web-nginx-mysql image forked from the…   0                                       [OK]
pashaf/zabbix-web                                                                               0                                       
pschmitt/zabbix-web-nginx-mysql-alpine-armhf                                                    0                                       
taishin/zabbix-web-apache                                                                       0                                       
inasawa/zabbix-web-nginx-mysql-alpine-armhf                                                     0                                       
megbeguk/zabbix-web-nginx                       docker image for Zabbix frontend                0                                       [OK]
simonswine/zabbix-web                           Zabbix 3.0 web interface for MySQL in Docker    0                                       [OK]
leandromoreirajfa/zabbix-web                                                                    0                                       
lborguetti/zabbix-web-mysql                                                                     0                                       [OK]
[root@localhost ~]# docker pull zabbix/zabbix-web-nginx-mysql
Using default tag: latest
latest: Pulling from zabbix/zabbix-web-nginx-mysql
89d9c30c1d48: Already exists 
b3f3215cd8c3: Pull complete 
86046fdb7d4c: Pull complete 
66f3a1290072: Pull complete 
b165e28a2796: Pull complete 
d14d6643cc7b: Pull complete 
6256bb44df04: Pull complete 
73de7fe24caf: Pull complete 
1dc24a05f660: Pull complete 
355fe8da0f0f: Pull complete 
f5ba1b77be8a: Pull complete 
Digest: sha256:f9ff844ebb1ef0e0f1baa0f64ed3cb5b410854674e3a8d62fffd6ed388266a64
Status: Downloaded newer image for zabbix/zabbix-web-nginx-mysql:latest
docker.io/zabbix/zabbix-web-nginx-mysql:latest
[root@localhost ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
kali                            latest              953ce62dfa5a        46 hours ago        9.97GB
zabbix/zabbix-web-nginx-mysql   latest              9102571b2fef        2 weeks ago         155MB
zabbix/zabbix-server-mysql      latest              6da679c2a6c6        2 weeks ago         65.8MB
tomcat                          latest              6408fdc94212        2 weeks ago         507MB
mysql                           latest              d435eee2caa5        2 weeks ago         456MB

4、下载zabbix-java-gateway镜像, Zabbix本身不支持直接监控Java,而是使用zabbix-java-gateway监控jvm/tomcat性能

[root@localhost ~]# docker search zabbix-java-gateway
NAME                                        DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
zabbix/zabbix-java-gateway                  Zabbix Java Gateway                             19                                      [OK]
supermap/zabbix-java-gateway                                                                0                                       
epicmorg/zabbix-java-gateway                zabbix/zabbix-java-gateway                      0                                       
fabrizio2210/zabbix-java-gateway-alpine                                                     0                                       
varsy/zabbix-java-gateway                   This is docker image with Zabbix 3.0 java ga…   0                                       [OK]
lborguetti/zabbix-java-gateway                                                              0                                       [OK]
qiyestore/zabbix-java-gateway               Zabbix JAVA Gateway docker container            0                                       [OK]
digiapulssi/zabbix-java-gateway             A forked zabbix-java-gateway including ZBXNE…   0                                       [OK]
doubek/zabbix-java-gateway                                                                  0                                       
cmp1234/zabbix-java-gateway                 Zabbix Java Gateway performs native support …   0                                       [OK]
xqq521/zabbix-java-gateway                                                                  0                                       
scrapinghub/zabbix-java-gateway                                                             0                                       [OK]
pschmitt/zabbix-java-gateway-alpine                                                         0                                       
suiyuewuheng/zabbix-java-gateway                                                            0                                       
wang049718/zabbix-java-gateway                                                              0                                       
andytran/zabbix-java-gateway                                                                0                                       
prashanth19/zabbix-java-gateway                                                             0                                       
moyuanhui/zabbix-java-gateway                                                               0                                       
pschmitt/zabbix-java-gateway-ubuntu                                                         0                                       
miyabis7th/zabbix-java-gateway                                                              0                                       
fablaporta/zabbix-java-gateway                                                              0                                       
pschmitt/zabbix-java-gateway-alpine-armhf                                                   0                                       
ninjacat/zabbix-java-gateway                                                                0                                       
[root@localhost ~]# docker pull zabbix/zabbix-java-gateway
Using default tag: latest
latest: Pulling from zabbix/zabbix-java-gateway
89d9c30c1d48: Already exists 
4b173bc0a8f0: Pull complete 
c05439022597: Pull complete 
f2f722f308cd: Pull complete 
38bfd1253bb8: Pull complete 
0f4354c81b03: Pull complete 
Digest: sha256:54683dd3e642804b2a8f594443c5102bc8e1b402b235677385e2970c12202113
Status: Downloaded newer image for zabbix/zabbix-java-gateway:latest
docker.io/zabbix/zabbix-java-gateway:latest
[root@localhost ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
kali                            latest              953ce62dfa5a        2 days ago          9.97GB
zabbix/zabbix-web-nginx-mysql   latest              9102571b2fef        2 weeks ago         155MB
zabbix/zabbix-server-mysql      latest              6da679c2a6c6        2 weeks ago         65.8MB
zabbix/zabbix-java-gateway      latest              e175083b2981        2 weeks ago         83.4MB
tomcat                          latest              6408fdc94212        2 weeks ago         507MB
mysql                           latest              d435eee2caa5        2 weeks ago         456MB

02 运行镜像

1、 运行mysql 镜像,创建mysql容器

[root@localhost ~]# docker run -dit -p 3306:3306 --name zabbix-mysql --restart always -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix_pwd" -e MYSQL_ROOT_PASSWORD="root_pwd" mysql
c245a233b8979b833f7bc10f0e6aec62921981ebeea1a787ff3b973aa623bccb

2、运行zabbix-java-gateway镜像,创建zabbix-java-gateway容器

[root@localhost ~]# docker run -dit -p 10052:10052 --restart=always --name=zabbix-java-gateway zabbix/zabbix-java-gateway
9006bd35d41a98c0c03f068c1b5c9edb0f5ff2f28235e97d95f5043e088fffb8

3、运行zabbix-server-mysql镜像,创建zabbix-server-mysql容器。

[root@localhost ~]# docker run -dit -p 10051:10051 --name=zabbix-server-mysql --restart=always -e DB_SERVER_HOST="zabbix-mysql" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix_pwd" -e MYSQL_ROOT_PASSWORD="root_pwd" -e ZBX_JAVAGATEWAY="zabbix-java-gateway" zabbix/zabbix-server-mysql
db986b0a3cdca4bc028ef9de4eb0a2d528f37d87a648cc6f1fc0327559f52fc3

4、运行zabbix-web-nginx-mysql镜像,创建zabbix-web-nginx-mysql容器

[root@localhost ~]# docker run -dit -p 80:80 --name zabbix-web-nginx-mysql --restart=always -e DB_SERVER_HOST="zabbix-mysql" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix_pwd" -e MYSQL_ROOT_PASSWORD="root_pwd" -e ZBX_SERVER_HOST="zabbix-server-mysql" zabbix/zabbix-web-nginx-mysql
7d7040dbbafd8cc6680424f50008e82f0e1bd18864853f5304a32dca681e6cf1
[root@localhost ~]# 
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED              STATUS              PORTS                               NAMES
7d7040dbbafd        zabbix/zabbix-web-nginx-mysql   "docker-entrypoint.sh"   3 seconds ago        Up 2 seconds        0.0.0.0:80->80/tcp, 443/tcp         zabbix-web-nginx-mysql
9006bd35d41a        zabbix/zabbix-java-gateway      "docker-entrypoint.s…"   33 seconds ago       Up 32 seconds       0.0.0.0:10052->10052/tcp            zabbix-java-gateway
db986b0a3cdc        zabbix/zabbix-server-mysql      "/sbin/tini -- /usr/…"   About a minute ago   Up About a minute   0.0.0.0:10051->10051/tcp            zabbix-server-mysql
c245a233b897        mysql                           "docker-entrypoint.s…"   3 minutes ago        Up 3 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   zabbix-mysql
c5557254c6d9        tomcat                          "catalina.sh run"        2 hours ago          Up 2 hours          8080/tcp                            fervent_goldstine
[root@localhost ~]#

zabbix所需容器已经全部启动完成。

03 登陆zabbix

1、浏览器访问zabbix地址http://192.168.14.121/zabbix发现打不开,检查docker运行都是正常的,检查容器日志发现是zabbix没有连上mysql数据库,MySQL server is not available。

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                               NAMES
05d81a993d77        zabbix/zabbix-web-nginx-mysql   "docker-entrypoint.sh"   3 hours ago         Up 3 hours          0.0.0.0:80->80/tcp, 443/tcp         zabbix-web-nginx-mysql
7bfe08ab5990        mysql:latest                    "docker-entrypoint.s…"   3 hours ago         Up 3 hours          0.0.0.0:3306->3306/tcp, 33060/tcp   zabbix-mysql
9006bd35d41a        zabbix/zabbix-java-gateway      "docker-entrypoint.s…"   2 days ago          Up 2 days           0.0.0.0:10052->10052/tcp            zabbix-java-gateway
db986b0a3cdc        zabbix/zabbix-server-mysql      "/sbin/tini -- /usr/…"   2 days ago          Up 2 days           0.0.0.0:10051->10051/tcp            zabbix-server-mysql
c5557254c6d9        tomcat                          "catalina.sh run"        2 days ago          Up 2 days           8080/tcp                            fervent_goldstine
[root@localhost ~]# 
** Deploying Zabbix frontend (nginx) with mysql database
** Preparing the system
** Preparing Zabbix web-interface
** Using MYSQL_USER variable from ENV
** Using MYSQL_PASSWORD variable from ENV
********************
* DB_SERVER_HOST: zabbix-mysql
* DB_SERVER_PORT: 3306
* DB_SERVER_DBNAME: zabbix
********************
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...

3、没有找到问题所在,在论坛找到一个贴子是关于zabbix连接mysql8有bug,说要是zabbix4之后才支持mysql8,但是我的zabbix是4.4.3,应该没有 个问题才对,找不到原因,就只能换成mysq5.7试了一下。

[root@localhost ~]#docker pull mysql:5.7
[root@localhost ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
kali                            latest              953ce62dfa5a        4 days ago          9.97GB
zabbix/zabbix-web-nginx-mysql   latest              9102571b2fef        2 weeks ago         155MB
zabbix/zabbix-server-mysql      latest              6da679c2a6c6        2 weeks ago         65.8MB
zabbix/zabbix-java-gateway      latest              e175083b2981        2 weeks ago         83.4MB
tomcat                          latest              6408fdc94212        3 weeks ago         507MB
mysql                           5.7                 1e4405fe1ea9        3 weeks ago         437MB
mysql                           latest              d435eee2caa5        3 weeks ago         456MB
[root@localhost ~]# docker run -dit -p 3306:3306 --name mysql --restart always -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix_pwd" -e MYSQL_ROOT_PASSWORD="root_pwd" mysql:5.7
9a7616f431d898fb2c4a4c0db632366ac8c8daaf20d56d2a405cc748a9080090
[root@localhost ~]# docker run -dit -p 10052:10052 --restart=always --name=zabbix-java-gateway zabbix/zabbix-java-gateway
0fe2025927e91da1b1dc0c0735a6d7511b3a788365a98157ce82dba4f490cc99
[root@localhost ~]# docker run -dit -p 10051:10051  -v /etc/hosts:/etc/hosts --name=zabbix-server-mysql --restart=always -e DB_SERVER_HOST="mysql" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix_pwd" -e MYSQL_ROOT_PASSWORD="root_pwd" -e ZBX_JAVAGATEWAY="zabbix-java-gateway" zabbix/zabbix-server-mysql
3dc55a164c4a48ed4dcfd80a2a582e6c4cfac8eda857a46f0db2393ffe3b8b93
[root@localhost ~]# 
[root@localhost ~]# docker run -dit -p 80:80  -v /etc/hosts:/etc/hosts --name zabbix-web-nginx-mysql --restart=always -e DB_SERVER_HOST="mysql" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix_pwd" -e MYSQL_ROOT_PASSWORD="root_pwd" -e ZBX_SERVER_HOST="zabbix-server-mysql" zabbix/zabbix-web-nginx-mysql
a57b5a32873b41a5d61a3c4b45993a00b58700ae942ddf7bcff921e7998f1d08
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                               NAMES
a57b5a32873b        zabbix/zabbix-web-nginx-mysql   "docker-entrypoint.sh"   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp, 443/tcp         zabbix-web-nginx-mysql
3dc55a164c4a        zabbix/zabbix-server-mysql      "/sbin/tini -- /usr/…"   3 minutes ago       Up 3 minutes        0.0.0.0:10051->10051/tcp            zabbix-server-mysql
0fe2025927e9        zabbix/zabbix-java-gateway      "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:10052->10052/tcp            zabbix-java-gateway
9a7616f431d8        mysql:5.7                       "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   mysql
c5557254c6d9        tomcat                          "catalina.sh run"        2 days ago          Up 2 days           8080/tcp                            fervent_goldstine
[root@localhost ~]# docker logs 3dc55a164c4a
** Preparing Zabbix server
** Using MYSQL_USER variable from ENV
** Using MYSQL_PASSWORD variable from ENV
** Using MYSQL_ROOT_PASSWORD variable from ENV
********************
* DB_SERVER_HOST: mysql
* DB_SERVER_PORT: 3306
* DB_SERVER_DBNAME: zabbix
********************
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...

看日志还是报错,是因为前面启动容器的时候指定的DB_SERVER_HOST是容器名称,不是容器的IP,所认还需修改容器的hosts文件,(使用mysql8的时候通过IP和修改hosts文件都试过访问不行)。

4、通过[root@localhost ~]#docker inspect 9a7616f431d8获取到各个容器的IP地址,然后修改容器本机的hosts文件,因为之前我们运行容器的时候指定了将容器的hosts文件挂载本机的/etc/hosts

[root@localhost docker]# vi /etc/hosts
[root@localhost docker]# more /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.17.0.3 mysql
172.17.0.4 zabbix-java-gateway
172.17.0.5 zabbix-server-mysql
172.17.0.6 zabbix-web-nginx-mysql

5、修改完容器缩主机的hosts文件之后,需要重启容器,再检查容器的日志发现已经正常启动。

[root@localhost docker]# docker stop a57b5a32873b
a57b5a32873b
[root@localhost docker]# docker start a57b5a32873b
a57b5a32873b
[root@localhost docker]# docker stop 3dc55a164c4a
3dc55a164c4a
[root@localhost docker]# docker start 3dc55a164c4a
3dc55a164c4a

到此这篇关于docker安装部署zabbix的文章就介绍到这了,更多相关docker安装部署zabbix内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文