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内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论