1. 程式人生 > >Zabbix監控系統的安裝(Docker版)

Zabbix監控系統的安裝(Docker版)

主要包括如下3個部分:

  • Docker元件的安裝(zabbix-server-mysql/zabbix-web-apache-mysql/zabbix-agent)
  • 注意事項
  • 啟動相關log

元件安裝
Zabbix主要包括3個基本組成部分:
zabbix-server-mysql
zabbix-web-apache-mysql
zabbix-agent
分別代表後端、前端和資料採集器。本文主要採用的是mysql資料的形勢,實際上zabbix官方海提供了pgsql的資料庫儲存形式。詳細的見docker hub上的官方介紹:https://hub.docker.com/r/zabbix/

安裝的命令較為簡單,本文采用的docker版本一致為alpine-3.2.5(agent版本和後端版本不一致是否會出現一定的問題目前海不太確定)。

# zabbix-server-mysql
docker run  --add-host=dockerhost:`docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge` --name some-zabbix-server-mysql  -p 10051:10051 -e DB_SERVER_HOST=docker.for.mac.host.internal -e DB_SERVER_PORT=3306 -e MYSQL_USER="root" -e MYSQL_PASSWORD="admin" -d zabbix/zabbix-server-mysql:alpine-3.2.5

#  zabbix-web-apache-mysql

docker run --name some-zabbix-agent --add-host=dockerhost:`docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge` -p 10050:10050 -e ZBX_HOSTNAME="localhost" -e ZBX_SERVER_HOST=`docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge`  -e ZBX_SERVER_PORT=10051 -d zabbix/zabbix-agent:alpine-3.2.5

#  zabbix-agent

docker run --name some-zabbix-web-apache-mysql --add-host=dockerhost:`docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge` -p 8088:80  -e DB_SERVER_HOST=docker.for.mac.host.internal -e DB_SERVER_PORT=3306 -e MYSQL_USER=root -e MYSQL_PASSWORD=admin -e ZBX_SERVER_HOST=`docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge` -e TZ="Asia/Shanghai" -d zabbix/zabbix-web-apache-mysql:alpine-3.2.5

# ps: 上述命令中的--add-host 和 docker.for.mac.host.internal 是為了解決docker訪問本地資料庫而新增的,如果IP地址固定的情況下,更改成相應的IP地址即可。

注意事項
特別注意,上述的SERVER_HOST千萬不要配置127.0.0.1哦,因為這個是docker的虛擬化網路決定的。詳細可以看下我的另一篇文章Docker內如何訪問本機(宿主機)

其二,可以通過docker logs 檢視zabbix啟動時候的日誌。還有,其它的docker引數,可以檢視相應的zabbix-docker 主頁面。https://hub.docker.com/r/zabbix/zabbix-server-mysql/

其三,mysql 連線不上。

sh-3.2# docker logs 9515eb39b8b0
** Deploying Zabbix server with mysql database
** Preparing the system
** Preparing Zabbix server
********************
* DB_SERVER_HOST: dockerhost
* DB_SERVER_PORT: 3306
* DB_SERVER_DBNAME: zabbix
* DB_SERVER_ZBX_USER: root
* DB_SERVER_ZBX_PASS: admin
********************
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...

這個問題是上文的docker訪問了本地的ip:127.0.0.1所導致,具體還是看下docker訪問本機這片文章即可解決上述問題。

其四,docker初始化的資料庫名稱為zabbix, 賬戶和密碼為Admin/zabbix

其五,web連線不上host,肯定是因為apache-web映象啟動的時候沒有配置正確的host地址導致。

啟動相關log

# docker zabbix-mysql
localhost:~ Sean$ docker logs 0aab68a67f1c
** Deploying Zabbix server with mysql database
** Preparing the system
** Preparing Zabbix server
********************
* DB_SERVER_HOST: docker.for.mac.host.internal
* DB_SERVER_PORT: 3306
* DB_SERVER_DBNAME: zabbix
* DB_SERVER_ZBX_USER: root
* DB_SERVER_ZBX_PASS: admin
********************
** Database 'zabbix' already exists. Please be careful with database COLLATE!
** Table 'zabbix.dbversion' already exists.
** Preparing Zabbix server configuration file
** Updating '/etc/zabbix/zabbix_server.conf' parameter "ListenPort": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "SourceIP": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "LogType": 'console'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "LogFile": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "LogFileSize": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "PidFile": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "DebugLevel": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "DBHost": 'docker.for.mac.host.internal'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "DBName": 'zabbix'... updated
** Updating '/etc/zabbix/zabbix_server.conf' parameter "DBUser": 'root'... updated
** Updating '/etc/zabbix/zabbix_server.conf' parameter "DBPort": '3306'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "DBPassword": 'admin'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartPollers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartIPMIPollers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartPollersUnreachable": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartTrappers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartPingers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartDiscoverers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartHTTPPollers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartTimers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartEscalators": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "JavaGateway": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "JavaGatewayPort": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartJavaPollers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartVMwareCollectors": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "VMwareFrequency": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "VMwarePerfFrequency": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "VMwareCacheSize": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "VMwareTimeout": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "SNMPTrapperFile": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartSNMPTrapper": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "HousekeepingFrequency": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "MaxHousekeeperDelete": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "SenderFrequency": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "CacheSize": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "CacheUpdateFrequency": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartDBSyncers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "HistoryCacheSize": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "HistoryIndexCacheSize": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "TrendCacheSize": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "ValueCacheSize": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "Timeout": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "TrapperTimeout": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "UnreachablePeriod": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "UnavailableDelay": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "UnreachableDelay": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "AlertScriptsPath": '/usr/lib/zabbix/alertscripts'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "ExternalScripts": '/usr/lib/zabbix/externalscripts'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "FpingLocation": '/usr/sbin/fping'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "Fping6Location": '/usr/sbin/fping6'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "SSHKeyLocation": '/var/lib/zabbix/ssh_keys'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "LogSlowQueries": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "StartProxyPollers": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "ProxyConfigFrequency": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "ProxyDataFrequency": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "SSLCertLocation": '/var/lib/zabbix/ssl/certs/'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "SSLKeyLocation": '/var/lib/zabbix/ssl/keys/'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "SSLCALocation": '/var/lib/zabbix/ssl/ssl_ca/'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "LoadModulePath": '/var/lib/zabbix/modules/'... added
** Updating '/etc/zabbix/zabbix_server.conf' parameter "TLSCAFile": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "TLSCRLFile": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "TLSCertFile": ''... removed
** Updating '/etc/zabbix/zabbix_server.conf' parameter "TLSKeyFile": ''... removed
** Cleaning the system
########################################################
** Executing supervisord
2018-05-31 14:31:41,095 CRIT Set uid to user 0
2018-05-31 14:31:41,095 CRIT Set uid to user 0
2018-05-31 14:31:41,095 WARN Included extra file "/etc/supervisor/conf.d/supervisord_zabbix.conf" during parsing
2018-05-31 14:31:41,095 WARN Included extra file "/etc/supervisor/conf.d/supervisord_zabbix.conf" during parsing
2018-05-31 14:31:41,103 INFO RPC interface 'supervisor' initialized
2018-05-31 14:31:41,103 INFO RPC interface 'supervisor' initialized
2018-05-31 14:31:41,103 INFO supervisord started with pid 1
2018-05-31 14:31:41,103 INFO supervisord started with pid 1
2018-05-31 14:31:42,108 INFO spawned: 'zabbix-server' with pid 108
2018-05-31 14:31:42,108 INFO spawned: 'zabbix-server' with pid 108
Starting Zabbix Server. Zabbix 3.2.5 (revision 67445).
Press Ctrl+C to exit.

   108:20180531:143142.119 Starting Zabbix Server. Zabbix 3.2.5 (revision 67445).
   108:20180531:143142.120 ****** Enabled features ******
   108:20180531:143142.120 SNMP monitoring:           YES
   108:20180531:143142.120 IPMI monitoring:           YES
   108:20180531:143142.120 Web monitoring:            YES
   108:20180531:143142.121 VMware monitoring:         YES
   108:20180531:143142.121 SMTP authentication:       YES
   108:20180531:143142.121 Jabber notifications:       NO
   108:20180531:143142.121 Ez Texting notifications:  YES
   108:20180531:143142.122 ODBC:                      YES
   108:20180531:143142.122 SSH2 support:              YES
   108:20180531:143142.122 IPv6 support:              YES
   108:20180531:143142.122 TLS support:               YES
   108:20180531:143142.122 ******************************
   108:20180531:143142.123 using configuration file: /etc/zabbix/zabbix_server.conf
   108:20180531:143142.151 current database version (mandatory/optional): 03020000/03020000
   108:20180531:143142.152 required mandatory version: 03020000
   108:20180531:143142.218 server #0 started [main process]
   109:20180531:143142.219 server #1 started [configuration syncer #1]
   110:20180531:143142.220 server #2 started [db watchdog #1]
   111:20180531:143142.220 server #3 started [poller #1]
   125:20180531:143142.226 server #17 started [timer #1]
   120:20180531:143142.227 server #12 started [trapper #4]
   126:20180531:143142.231 server #18 started [http poller #1]
   112:20180531:143142.231 server #4 started [poller #2]
   127:20180531:143142.232 server #19 started [discoverer #1]
   113:20180531:143142.233 server #5 started [poller #3]
   114:20180531:143142.233 server #6 started [poller #4]
   128:20180531:143142.233 server #20 started [history syncer #1]
   115:20180531:143142.237 server #7 started [poller #5]
   129:20180531:143142.237 server #21 started [history syncer #2]
   116:20180531:143142.237 server #8 started [unreachable poller #1]
   130:20180531:143142.238 server #22 started [history syncer #3]
   131:20180531:143142.240 server #23 started [history syncer #4]
   132:20180531:143142.240 server #24 started [escalator #1]
   133:20180531:143142.242 server #25 started [proxy poller #1]
   134:20180531:143142.244 server #26 started [self-monitoring #1]
   135:20180531:143142.248 server #27 started [task manager #1]
   121:20180531:143142.249 server #13 started [trapper #5]
   117:20180531:143142.249 server #9 started [trapper #1]
   122:20180531:143142.250 server #14 started [icmp pinger #1]
   118:20180531:143142.251 server #10 started [trapper #2]
   123:20180531:143142.252 server #15 started [alerter #1]
   119:20180531:143142.253 server #11 started [trapper #3]
   124:20180531:143142.253 server #16 started [housekeeper #1]
2018-05-31 14:31:43,254 INFO success: zabbix-server entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-05-31 14:31:43,254 INFO success: zabbix-server entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
   120:20180531:143405.258 cannot send list of active checks to "172.17.0.1": host [hostname] not found
   121:20180531:143527.483 cannot send list of active checks to "172.17.0.1": host [hostname] not found
   116:20180531:143607.352 enabling Zabbix agent checks on host "Zabbix server": host became available


# web
localhost:~ Sean$ docker logs de277d1fbd25
** Deploying Zabbix frontend (apache) with mysql database
** Preparing the system
** Preparing Zabbix web-interface
********************
* DB_SERVER_HOST: docker.for.mac.host.internal
* DB_SERVER_PORT: 3306
* DB_SERVER_DBNAME: zabbix
* DB_SERVER_ZBX_USER: root
* DB_SERVER_ZBX_PASS: admin
********************
** Disable default site
** Adding Zabbix virtual host (HTTP)
**** Impossible to enable SSL support for Apache2. Certificates are missed.
** Preparing Zabbix frontend configuration file
** Updating '/etc/php5/conf.d/99-zabbix.ini' parameter "max_execution_time": '600'... updated
** Updating '/etc/php5/conf.d/99-zabbix.ini' parameter "memory_limit": '128M'... updated
** Updating '/etc/php5/conf.d/99-zabbix.ini' parameter "post_max_size": '16M'... updated
** Updating '/etc/php5/conf.d/99-zabbix.ini' parameter "upload_max_filesize": '2M'... updated
** Updating '/etc/php5/conf.d/99-zabbix.ini' parameter "max_input_time": '300'... updated
** Updating '/etc/php5/conf.d/99-zabbix.ini' parameter "date.timezone": 'Asia/Shanghai'... added
** Cleaning the system
########################################################
** Executing supervisord
2018-05-31 14:38:07,611 CRIT Set uid to user 0
2018-05-31 14:38:07,611 CRIT Set uid to user 0
2018-05-31 14:38:07,612 WARN Included extra file "/etc/supervisor/conf.d/supervisord_zabbix.conf" during parsing
2018-05-31 14:38:07,612 WARN Included extra file "/etc/supervisor/conf.d/supervisord_zabbix.conf" during parsing
2018-05-31 14:38:07,621 INFO RPC interface 'supervisor' initialized
2018-05-31 14:38:07,621 INFO RPC interface 'supervisor' initialized
2018-05-31 14:38:07,621 INFO supervisord started with pid 1
2018-05-31 14:38:07,621 INFO supervisord started with pid 1
2018-05-31 14:38:08,628 INFO spawned: 'apache2' with pid 30
2018-05-31 14:38:08,628 INFO spawned: 'apache2' with pid 30
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[Thu May 31 14:38:08.663829 2018] [mpm_prefork:notice] [pid 30] AH00163: Apache/2.4.25 (Unix) PHP/5.6.30 configured -- resuming normal operations
[Thu May 31 14:38:08.664184 2018] [core:notice] [pid 30] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
2018-05-31 14:38:09,666 INFO success: apache2 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-05-31 14:38:09,666 INFO success: apache2 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

#總攬

CONTAINER ID        IMAGE                                         COMMAND                  CREATED             STATUS              PORTS                                        NAMES
1d92829fb478        zabbix/zabbix-agent:alpine-3.2.5              "/bin/bash /run_zabb…"   3 days ago          Up 57 seconds       0.0.0.0:10050->10050/tcp                     some-zabbix-agent
ff3feda84ac1        zabbix/zabbix-web-apache-mysql:alpine-3.2.5   "/bin/bash /run_zabb…"   3 days ago          Up About a minute   443/tcp, 0.0.0.0:8088->80/tcp                some-zabbix-web-apache-mysql
0aab68a67f1c        zabbix/zabbix-server-mysql:alpine-3.2.5       "/bin/bash /run_zabb…"   3 days ago          Up About a minute   162/udp, 0.0.0.0:10051->10051/tcp            some-zabbix-server-mysql

zabbix