一、簡介 Zabbix的常用組件 Zabbix Web Gui: 提供Web界面。 Zabbix Databases:提供數據庫存儲功能並用於存儲配置信息。以及采集到的數據。 Zabbix Server : 接收來自Agent采集數據的核心組件。 Zabbix Agent :部署在被監控的主機上,用於采集本地的數據。 Zabbix Proxy: 當監控節點較多時,用於減輕Server壓力組件,也可用於分布式。監控系統,由Proxy接收數據后統一發送給Server。 進程 zabbix_agentd:客戶端守護進程,負責收集客戶端數據,例如cpu負載、內存、硬盤使用情況等。 zabbix_get:zabbix數據接收工具,單獨使用的命令,通常在Server或者Proxy端執行獲取遠端客戶信息的命令。通常客戶排錯。例如在Server端獲取不到客戶端的內存數據,我們可以使用zabbix_get獲取客戶端的內容的方式來做故障排查。 zabbix_sender:zabbix數據發送工具,用於發送數據給Server或者Proxy,通常用於耗時比較長的檢查。很多檢查非常耗時間,導致zabbix超時。於是我們在腳本執行完畢之后,使用sender主動提交數據。 zabbix_proxy:zabbix代理守護進程。功能類似Server,唯一不同的是它只是一個中轉站,它需要把收集到的數據提交/被提交到Server里。 zabbix_java_gateway:Java網關,類似agentd,但是只用於Java方面。它只能主動去獲取數據,而不能被動獲取數據。它的數據最終會給到Server或者proxy。 二、Zabbix監控平台搭建 環境介紹: CentOS 7.3 Zabbix-server(監控端)192.168.92.111 Zabbix-agent (被監控端)192.168.92.14 1.基礎環境配置: systemctl disable firewalld systemctl stop firewalld setenforce=0 vim /etc/sysconfig/selinux,修改為SELINUX=disabled getenforce yum install tree net-tool net-snmp vim ntpdate wget #安裝部分基礎軟件包 #修改yum源 更改為阿里雲 cd /etc/yum.repos.d/ mv CentOS-Base.repo CentOS-Base.repo.bak #下載阿里雲鏡像倉庫 wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下載epel倉庫 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum clean all #重新生成緩存 yum makecache 2.安裝Mysql數據庫 wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm ls mysql57-community-release-el7-11.noarch.rpm #安裝Mysql Yum源 rpm -ivh mysql57-community-release-el7-11.noarch.rpm yum -y install mysql-server systemctl start mysqld systemctl enable mysqld #tcp LISTEN 0 80 [::]:3306 [::]:* users:(("mysqld",pid=54086,fd=21)) ss -antulp | grep :3306 #查看初始密碼 grep 'root@localhost:' /var/log/mysqld.log mysql -hlocalhost -uroot -p'hsQ(7(so_cgX' alter user root@"localhost" identified by "123qqq...A"; mysql -uroot -p123qqq...A 3.安裝Zabbix 5.0監控平台 #安裝Zabbix Yum源倉庫 rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm yum clean all #安裝Zabbix Server 與 Zabbix agent yum -y install zabbix-server-mysql zabbix-agent 注意: 1.如果安裝中報錯:Delta RPMs disabled because /usr/bin/applydeltarpm not installed,則安裝 deltarpm軟件。 yum -y install deltarpm 2.安裝zabbixserver,,zabbix-agent的時候,報錯: Error downloading packages: zabbix-server-mysql-5.0.2-1.el7.x86_64: [Errno 256] No more mirrors to try. zabbix-agent-5.0.2-1.el7.x86_64: [Errno 256] No more mirrors to try. 問題分析 一般這樣的問題是因為用的國外源,下載速度慢導致的,可以多下載幾次試試,或者直接換成阿里的源,或者先執行yum -y install zabbix-server-mysql,然后執行yum -y install zabbix-server-mysql zabbix-agent #安裝Zabbix frontend yum -y install centos-release-scl vim /etc/yum.repos.d/zabbix.repo [zabbix-frontend] name=Zabbix Official Repository frontend - $basearch baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend enabled=1 //將0修改為1 #安裝Zabbix前端包 yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl yum -y install zabbix-web #yum下載多次出錯,wget下載,然后rpm方式安裝 wget http://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.5-1.el7.noarch.rpm #查詢noarch包zabbix-web rpm -ivh zabbix-web-5.0.5-1.el7.noarch.rpm rpm -qa | grep zabbix-web #再次執行yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl #[zabbix-non-supported]換成aliyun鏡像報錯: failure: repodata/repomd.xml from zabbix-non-supported: [Errno 256] No more mirrors to try. https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearc/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found Error downloading packages: zabbix-web-5.0.5-1.el7.noarch: [Errno 256] No more mirrors to try. 解決: wget http://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.5-1.el7.noarch.rpm #查詢noarch包zabbix-web rpm -ivh zabbix-web-5.0.5-1.el7.noarch.rpm rpm -qa | grep zabbix-web #將官方yum源的地址改為阿里雲的地址,仍然報錯 vim /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearc/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1 創建和初始化數據庫 mysql -uroot -p123qqq...A create database zabbix character set utf8 collate utf8_bin; create user zabbix@localhost identified by '123qqq...A'; grant all privileges on zabbix.* to zabbix@localhost; show databases; exit #導入Zabbix數據庫結構和數據 zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123qqq...A zabbix #mysql: [Warning] Using a password on the command line interface can be insecure. 4.配置Zabbix server ls /etc/opt/rh/rh-nginx116/nginx ls: cannot access /etc/opt/rh/rh-nginx116/nginx: No such file or directory 解決:單獨安裝 rh-nginx116 yum -y install rh-nginx116 #無此文件 [root@localhost ~]# vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf server { # listen 80; # server_name example.com; 取消以上兩行注釋修改后為以下: server { listen 80; server_name example.com; ... [root@localhost ~]# cat /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf server { listen 80; server_name example.com; root /usr/share/zabbix; index index.php; location = /favicon.ico { log_not_found off; } location / { try_files $uri $uri/ =404; } location /assets { access_log off; expires 10d; } location ~ /\.ht { deny all; } location ~ /(api\/|conf[^\.]|include|locale) { deny all; return 404; } location ~ [^/]\.php(/|$) { fastcgi_pass unix:/var/opt/rh/rh-php72/run/php-fpm/zabbix.sock; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; fastcgi_param DOCUMENT_ROOT /usr/share/zabbix; fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name; fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; } } [root@localhost ~]# vim /etc/zabbix/zabbix_server.conf ... 116 DBUser=zabbix //用戶名要與數據庫中創建的供zabbix訪問的用戶名一致 ... 124 DBPassword=# //去掉注釋,添加創建的zabbix用戶的數據庫密碼 ... #為Zabbix前端配置PHP,不能用#注釋,否則php無法識別 ; php_value[date.timezone] = Europe/Riga --》取消注釋將Europe/Riga時區修改為以下: php_value[date.timezone] = Aisa/Shanghai listen.acl_users = apache,nginx //添加一個nginx vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf [zabbix] user = apache group = apache listen = /var/opt/rh/rh-php72/run/php-fpm/zabbix.sock listen.acl_users = apache,nginx //添加一個nginx listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 php_value[session.save_handler] = files php_value[session.save_path] = /var/opt/rh/rh-php72/lib/php/session/ php_value[max_execution_time] = 300 php_value[memory_limit] = 128M php_value[post_max_size] = 16M php_value[upload_max_filesize] = 2M php_value[max_input_time] = 300 php_value[max_input_vars] = 10000 ; php_value[date.timezone] = Europe/Riga --》取消注釋將Europe/Riga時區修改為以下: php_value[date.timezone] = Asia/Shanghai 6.開啟服務 systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm systemctl status zabbix-server systemctl status zabbix-agent systemctl status httpd systemctl status rh-php72-php-fpm systemctl start rh-php72-php-fpm systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm #rh-php72-php-fpm服務未啟動 [root@node1 ~]# systemctl status rh-php72-php-fpm ● rh-php72-php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/rh-php72-php-fpm.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Sat 2020-11-28 13:44:57 CST; 3min 55s ago Process: 4031 ExecStart=/opt/rh/rh-php72/root/usr/sbin/php-fpm --nodaemonize (code=exited, status=78) Main PID: 4031 (code=exited, status=78) Nov 28 13:44:57 node1 systemd[1]: Starting The PHP FastCGI Process Manager... Nov 28 13:44:57 node1 php-fpm[4031]: [28-Nov-2020 13:44:57] ERROR: [/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf:6] unknown entry '#listen.acl_users' Nov 28 13:44:57 node1 php-fpm[4031]: [28-Nov-2020 13:44:57] ERROR: Unable to include /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf from /etc/opt/rh/rh-php72/php-fpm.conf at line 6 Nov 28 13:44:57 node1 php-fpm[4031]: [28-Nov-2020 13:44:57] ERROR: failed to load configuration file '/etc/opt/rh/rh-php72/php-fpm.conf' Nov 28 13:44:57 node1 php-fpm[4031]: [28-Nov-2020 13:44:57] ERROR: FPM initialization failed Nov 28 13:44:57 node1 systemd[1]: rh-php72-php-fpm.service: main process exited, code=exited, status=78/n/a Nov 28 13:44:57 node1 systemd[1]: Failed to start The PHP FastCGI Process Manager. Nov 28 13:44:57 node1 systemd[1]: Unit rh-php72-php-fpm.service entered failed state. Nov 28 13:44:57 node1 systemd[1]: rh-php72-php-fpm.service failed. [root@localhost ~]# ss -antulp | grep :80 tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=5619,fd=4),("httpd",pid=5618,fd=4),("httpd",pid=5617,fd=4),("httpd",pid=5616,fd=4),("httpd",pid=5614,fd=4),("httpd",pid=5585,fd=4)) [root@localhost ~]# ps -aux | grep zabbix ...... apache 5677 0.0 0.3 336672 7316 ? S 16:36 0:00 php-fpm: pool zabbix root 5809 0.0 0.0 112736 976 pts/0 S+ 16:47 0:00 grep --color=auto zabbix 7.訪問 http://192.168.92.111/zabbix/setup.php The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later. 可以看到已經登錄到zabbix 5.0監控界面了,上面的紅色提示不是報錯,只是提示之前“2次登錄嘗試失敗..”刷新一下提示就消失了。 修改Zabbix 5.0界面語言為中文:
#
zabbix agent5.0部署跳轉到:https://www.cnblogs.com/buffercache/p/14055951.html
------------------------------------------------------------------------------------------------------------------
#如下為dockerce方式部署zabbix
--zabbix dockers方式部署
--zabbix主要側重是io cpu 內存
--部署zabbix
sudo systemctl start docker
unzip zabbix-docker-5.0.zip
cd /home/zhuyongjun/zabbix-docker-5.0
--運行docker-compose前,修改版本為3.2(因為報錯版本不對):version: '3.2'
--注釋(因為報錯不可預料的參數) start_period: 30s172.16.38.5(6)
cd /home/zhuyongjun/zabbix-docker-5.0
--應該加-d后台啟動參數,否則可能會一直報錯(不影響服務):cannot connect to 172.16.38.5(6)
/home/zhuyongjun/zabbix-docker-5.0/docker-compose -f docker-compose_v3_centos_mysql_latest.yaml up -d
--查詢狀態,若有unhealthy狀態則重啟對應的服務
docker-compose -f docker-compose_v3_centos_mysql_latest.yaml ps
--web
默認賬號:Admin/zabbix
--web操作
配置欄目操作
配置-》自動發現規則
docker中的proxy服務為監控jvm
主機-》模板,主機群組
最新數據
zabbix-agent客戶端組件用來上傳性能數據:zabbix_agent.conf的3種方式
bin\zabbix_agent.exe --help
解壓linux版本的zabbix_agent,查看目錄結構
cd zabbix_agent
tree ./
監測欄目操作
------------------------------------------------
docker-compose部署zabbix以及時區問題解決
這邊使用官方的yaml來部署,直接從github克隆
git clone https://github.com/zabbix/zabbix-docker.git
--運行docker-compose時參考:
修改版本為3.2(因為報錯版本不對):version: '3.2'
注釋(因為報錯不可預料的參數) start_period: 30s
我這邊使用的docker-compose_v3_centos_mysql_latest.yaml來部署的,該 compose 文件運行基於 CentOS7 的 Zabbix 4.0 最新版本的組件,支持 MySQL 數據庫。如有必要的話,需要按照實際情況修改一下,比如端口、掛載等等。
如下為包自帶的配置文件docker-compose_v3_centos_mysql_latest.yaml
version: '3.5'
services:
zabbix-server:
image: zabbix/zabbix-server-mysql:centos-4.2-latest
ports:
- "10051:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro
- ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
- ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
- ./zbx_env/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:ro
links:
- mysql-server:mysql-server
- zabbix-java-gateway:zabbix-java-gateway
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
deploy:
resources:
limits:
cpus: '0.70'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M
env_file:
- .env_db_mysql
- .env_srv
user: root
depends_on:
- mysql-server
- zabbix-java-gateway
- zabbix-snmptraps
networks:
zbx_net_backend:
aliases:
- zabbix-server
- zabbix-server-mysql
- zabbix-server-centos-mysql
- zabbix-server-mysql-centos
zbx_net_frontend:
# devices:
# - "/dev/ttyUSB0:/dev/ttyUSB0"
stop_grace_period: 30s
sysctls:
- net.ipv4.ip_local_port_range=1024 65000
- net.ipv4.conf.all.accept_redirects=0
- net.ipv4.conf.all.secure_redirects=0
- net.ipv4.conf.all.send_redirects=0
labels:
com.zabbix.description: "Zabbix server with MySQL database support"
com.zabbix.company: "Zabbix SIA"
com.zabbix.component: "zabbix-server"
com.zabbix.dbtype: "mysql"
com.zabbix.os: "centos"
zabbix-proxy-sqlite3:
image: zabbix/zabbix-proxy-sqlite3:centos-4.2-latest
ports:
- "10061:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
- ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
- ./zbx_env/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:ro
links:
- zabbix-server:zabbix-server
- zabbix-java-gateway:zabbix-java-gateway
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.3'
memory: 256M
env_file:
- .env_prx
- .env_prx_sqlite3
user: root
depends_on:
- zabbix-java-gateway
- zabbix-snmptraps
networks:
zbx_net_backend:
aliases:
- zabbix-proxy-sqlite3
- zabbix-proxy-centos-sqlite3
- zabbix-proxy-sqlite3-centos
zbx_net_frontend:
stop_grace_period: 30s
labels:
com.zabbix.description: "Zabbix proxy with SQLite3 database support"
com.zabbix.company: "Zabbix SIA"
com.zabbix.component: "zabbix-proxy"
com.zabbix.dbtype: "sqlite3"
com.zabbix.os: "centos"
zabbix-proxy-mysql:
image: zabbix/zabbix-proxy-mysql:centos-4.2-latest
ports:
- "10071:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
- ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
- ./zbx_env/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:ro
links:
- zabbix-server:zabbix-server
- zabbix-java-gateway:zabbix-java-gateway
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.3'
memory: 256M
env_file:
- .env_db_mysql_proxy
- .env_prx
- .env_prx_mysql
user: root
depends_on:
- mysql-server
- zabbix-java-gateway
- zabbix-snmptraps
networks:
zbx_net_backend:
aliases:
- zabbix-proxy-mysql
- zabbix-proxy-centos-mysql
- zabbix-proxy-mysql-centos
zbx_net_frontend:
stop_grace_period: 30s
labels:
com.zabbix.description: "Zabbix proxy with MySQL database support"
com.zabbix.company: "Zabbix SIA"
com.zabbix.component: "zabbix-proxy"
com.zabbix.dbtype: "mysql"
com.zabbix.os: "centos"
zabbix-web-apache-mysql:
image: zabbix/zabbix-web-apache-mysql:centos-4.2-latest
ports:
- "18880:80"
- "18443:443"
links:
- mysql-server:mysql-server
- zabbix-server:zabbix-server
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/etc/ssl/apache2:/etc/ssl/apache2:ro
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
env_file:
- .env_db_mysql
- .env_web
user: root
depends_on:
- mysql-server
- zabbix-server
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
zbx_net_backend:
aliases:
- zabbix-web-apache-mysql
- zabbix-web-apache-centos-mysql
- zabbix-web-apache-mysql-centos
zbx_net_frontend:
stop_grace_period: 10s
sysctls:
- net.core.somaxconn=65535
labels:
com.zabbix.description: "Zabbix frontend on Apache web-server with MySQL database support"
com.zabbix.company: "Zabbix SIA"
com.zabbix.component: "zabbix-frontend"
com.zabbix.webserver: "apache2"
com.zabbix.dbtype: "mysql"
com.zabbix.os: "centos"
zabbix-web-nginx-mysql:
image: zabbix/zabbix-web-nginx-mysql:centos-4.2-latest
ports:
- "18081:80"
- "19443:443"
links:
- mysql-server:mysql-server
- zabbix-server:zabbix-server
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
env_file:
- .env_db_mysql
- .env_web
user: root
depends_on:
- mysql-server
- zabbix-server
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
zbx_net_backend:
aliases:
- zabbix-web-nginx-mysql
- zabbix-web-nginx-centos-mysql
- zabbix-web-nginx-mysql-centos
zbx_net_frontend:
stop_grace_period: 10s
sysctls:
- net.core.somaxconn=65535
labels:
com.zabbix.description: "Zabbix frontend on Nginx web-server with MySQL database support"
com.zabbix.company: "Zabbix SIA"
com.zabbix.component: "zabbix-frontend"
com.zabbix.webserver: "nginx"
com.zabbix.dbtype: "mysql"
com.zabbix.os: "centos"
zabbix-agent:
image: zabbix/zabbix-agent:centos-4.2-latest
ports:
- "10050:10050"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/etc/zabbix/zabbix_agentd.d:/etc/zabbix/zabbix_agentd.d:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
links:
- zabbix-server:zabbix-server
deploy:
resources:
limits:
cpus: '0.2'
memory: 128M
reservations:
cpus: '0.1'
memory: 64M
mode: global
env_file:
- .env_agent
user: root
privileged: true
pid: "host"
networks:
zbx_net_backend:
aliases:
- zabbix-agent
- zabbix-agent-passive
- zabbix-agent-centos
stop_grace_period: 5s
labels:
com.zabbix.description: "Zabbix agent"
com.zabbix.company: "Zabbix SIA"
com.zabbix.component: "zabbix-agentd"
com.zabbix.os: "centos"
zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:centos-4.2-latest
ports:
- "10052:10052"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
env_file:
- .env_java
user: root
networks:
zbx_net_backend:
aliases:
- zabbix-java-gateway
- zabbix-java-gateway-centos
stop_grace_period: 5s
labels:
com.zabbix.description: "Zabbix Java Gateway"
com.zabbix.company: "Zabbix SIA"
com.zabbix.component: "java-gateway"
com.zabbix.os: "centos"
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:centos-4.2-latest
ports:
- "162:162/udp"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:rw
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
user: root
networks:
zbx_net_frontend:
aliases:
- zabbix-snmptraps
zbx_net_backend:
stop_grace_period: 5s
labels:
com.zabbix.description: "Zabbix snmptraps"
com.zabbix.company: "Zabbix SIA"
com.zabbix.component: "snmptraps"
com.zabbix.os: "ubuntu"
mysql-server:
image: mysql:8.0
command: [mysqld, --character-set-server=utf8, --collation-server=utf8_bin, --default-authentication-plugin=mysql_native_password]
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/var/lib/mysql:/var/lib/mysql:rw
env_file:
- .env_db_mysql
user: root
stop_grace_period: 1m
networks:
zbx_net_backend:
aliases:
- mysql-server
- zabbix-database
- mysql-database
db_data_mysql:
image: busybox
volumes:
- ./zbx_env/var/lib/mysql:/var/lib/mysql:rw
# elasticsearch:
# image: elasticsearch
# environment:
# - transport.host=0.0.0.0
# - discovery.zen.minimum_master_nodes=1
# networks:
# zbx_net_backend:
# aliases:
# - elasticsearch
networks:
zbx_net_frontend:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: 172.21.0.0/24
zbx_net_backend:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
internal: true
ipam:
driver: default
config:
- subnet: 172.22.0.0/24
--啟動zabbix鏡像服務,注意低版本的docker-compose可能起不來。
docker-compose -f docker-compose_v3_centos_mysql_latest.yaml up -d
問題
問題1:改為中文后graph頁面亂碼
問題現象:在用戶界面把文字改為中文后,雖然界面上變成了中文,但是在graph圖形頁面上有亂碼:
解決方法:把本地字體文件復制到容器中去。
控制面板–>字體–>選擇一種中文字庫例如“楷體”(simkai.ttf),把這個字體拿到運行zabbix容器的宿主機上。
把字體復制到apache和nginx容器中:本地無simkai.ttf文件
docker cp ~/simkai.ttf zabbix-docker_zabbix-web-nginx-mysql_1:/usr/share/zabbix/fonts/
docker cp ~/simkai.ttf zabbix-docker_zabbix-web-apache-mysql_1:/usr/share/zabbix/fonts/
進入docker容器,執行:
cd /usr/share/zabbix/fonts
ln -snf simkai.ttf graphfont.ttf
不需要重啟,再次查看,亂碼已經顯示正常。
問題2:時區問題
問題現象:graph上展示的時間與實際時間不符,因為php時區不對,如圖:
解決方法:
一、對於apache容器
首先進入apache容器:
docker exec -it zabbix-docker_zabbix-web-apache-mysql_1 bash
編輯了/etc/php.ini,將時區設置為Asia/Shanghai
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Shanghai
重啟容器, --貌似沒啥用。。。
再次進入容器
編輯/etc/httpd/conf.d/zabbix.conf文件,在<VirtualHost>這一層,加上了php_value date.timezone Asia/Shanghai配置,如下:
<VirtualHost *:80>
DocumentRoot /usr/share/zabbix/
ServerName zabbix
DirectoryIndex index.php
AddType application/x-httpd-php .php .php3 .php4 .php5 .phtml
AddType application/x-httpd-php-source .phps
php_value date.timezone Asia/Shanghai
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
......
再次重啟容器,OK了。。
二、對於nginx容器:
首先進入nginx容器:
docker exec -it zabbix-docker_zabbix-web-nginx-mysql_1 bash
1
編輯了/etc/php.ini,將時區設置為Asia/Shanghai
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Shanghai
重啟容器, 同樣沒什么用,用phpinfo()查看了確實是這個php.ini,不知為何不生效。
一路找到最后,找到/usr/share/zabbix/include/config.inc.php文件:
[root@eedb7623a802 zabbix]# ps -ef | grep nginx
root 41 1 0 14:56 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon off; -c /etc/nginx/nginx.conf
nginx 43 41 0 14:56 ? 00:00:00 nginx: worker process
nginx 44 41 0 14:56 ? 00:00:00 nginx: worker process
nginx 45 41 0 14:56 ? 00:00:00 nginx: worker process
nginx 46 41 0 14:56 ? 00:00:00 nginx: worker process
nginx 47 41 0 14:56 ? 00:00:00 nginx: worker process
nginx 2254 42 0 15:57 ? 00:00:03 php-fpm: pool www
nginx 2310 42 0 15:58 ? 00:00:02 php-fpm: pool www
nginx 2347 42 0 16:00 ? 00:00:01 php-fpm: pool www
root 2470 2432 0 16:03 pts/0 00:00:00 grep --color=auto nginx
[root@eedb7623a802 zabbix]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes 5;
worker_rlimit_nofile 256000;
error_log /dev/fd/2 warn;
pid /var/run/nginx.pid;
events {
worker_connections 5120;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/fd/1 main;
client_body_timeout 5m;
send_timeout 5m;
connection_pool_size 4096;
client_header_buffer_size 4k;
large_client_header_buffers 4 4k;
request_pool_size 4k;
reset_timedout_connection on;
gzip on;
gzip_min_length 100;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_types text/plain;
gzip_types application/x-javascript;
gzip_types text/css;
output_buffers 128 512k;
postpone_output 1460;
aio on;
directio 512;
sendfile on;
client_max_body_size 8m;
client_body_buffer_size 256k;
fastcgi_intercept_errors on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75 20;
ignore_invalid_headers on;
index index.php;
server_tokens off;
include /etc/nginx/conf.d/*.conf;
}
[root@eedb7623a802 zabbix]# cat /etc/nginx/conf.d/*.conf
server {
listen 80;
server_name zabbix;
index index.php;
access_log /dev/fd/1 main;
error_log /dev/fd/2 notice;
set $webroot '/usr/share/zabbix';
root $webroot;
large_client_header_buffers 8 8k;
client_max_body_size 10M;
location = /favicon.ico {
log_not_found off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# caching of files
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $webroot$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
[root@eedb7623a802 zabbix]# cd /usr/share/zabbix
[root@eedb7623a802 zabbix]# ll
total 1112
-rw-r--r-- 1 root root 31911 Apr 15 20:08 actionconf.php
-rw-r--r-- 1 root root 3565 Jan 7 21:38 adm.gui.php
-rw-r--r-- 1 root root 7018 Jan 7 21:38 adm.housekeeper.php
-rw-r--r-- 1 root root 4331 Jan 7 21:38 adm.iconmapping.php
-rw-r--r-- 1 root root 4451 Jan 7 21:38 adm.images.php
-rw-r--r-- 1 root root 3347 Jan 7 21:38 adm.macros.php
-rw-r--r-- 1 root root 3637 Jan 7 21:38 adm.other.php
-rw-r--r-- 1 root root 8180 Apr 15 20:08 adm.regexps.php
-rw-r--r-- 1 root root 5054 Jan 7 21:38 adm.triggerdisplayoptions.php
-rw-r--r-- 1 root root 5092 Jan 7 21:38 adm.triggerseverities.php
-rw-r--r-- 1 root root 6568 Apr 15 20:08 adm.valuemapping.php
-rw-r--r-- 1 root root 1882 Jan 7 21:38 adm.workingtime.php
-rw-r--r-- 1 root root 2327 Jan 7 21:38 api_jsonrpc.php
drwxr-xr-x 4 root root 4096 Apr 19 19:14 app
-rw-r--r-- 1 root root 10469 Apr 15 20:08 applications.php
drwxr-xr-x 2 root root 4096 Apr 19 19:14 audio
-rw-r--r-- 1 root root 4743 Jan 7 21:38 auditacts.php
-rw-r--r-- 1 root root 6285 Jan 7 21:38 auditlogs.php
-rw-r--r-- 1 root root 1508 Jan 7 21:38 browserwarning.php
-rw-r--r-- 1 root root 4505 Feb 7 14:40 chart.php
-rw-r--r-- 1 root root 5176 Feb 7 14:40 chart2.php
-rw-r--r-- 1 root root 6769 Feb 7 14:40 chart3.php
-rw-r--r-- 1 root root 5595 Jan 7 21:38 chart4.php
-rw-r--r-- 1 root root 5713 Jan 7 21:38 chart5.php
-rw-r--r-- 1 root root 3596 Jan 7 21:38 chart6.php
-rw-r--r-- 1 root root 3638 Jan 7 21:38 chart7.php
-rw-r--r-- 1 root root 3501 Jan 7 21:38 charts.php
drwxr-xr-x 1 root root 4096 May 16 14:56 conf
-rw-r--r-- 1 root root 6963 Mar 15 22:37 conf.import.php
-rw-r--r-- 1 root root 17403 Apr 15 20:08 correlation.php
-rw-r--r-- 1 root root 56368 Apr 16 21:36 disc_prototypes.php
-rw-r--r-- 1 root root 13204 Apr 15 20:08 discoveryconf.php
-rw-r--r-- 1 root root 32988 Oct 15 2015 favicon.ico
drwxr-xr-x 1 root root 4096 May 15 17:29 fonts
-rw-r--r-- 1 root root 22516 Apr 15 20:08 graphs.php
-rw-r--r-- 1 root root 4578 Jan 7 21:38 history.php
-rw-r--r-- 1 root root 28944 Apr 15 20:08 host_discovery.php
-rw-r--r-- 1 root root 15158 Apr 15 20:08 host_prototypes.php
-rw-r--r-- 1 root root 3953 Jan 21 16:49 host_screen.php
-rw-r--r-- 1 root root 9448 Apr 15 20:08 hostgroups.php
-rw-r--r-- 1 root root 8656 Feb 14 02:44 hostinventories.php
-rw-r--r-- 1 root root 5243 Jan 7 21:38 hostinventoriesoverview.php
-rw-r--r-- 1 root root 46057 Apr 15 20:08 hosts.php
-rw-r--r-- 1 root root 27142 Apr 16 21:36 httpconf.php
-rw-r--r-- 1 root root 6592 Jan 7 21:38 httpdetails.php
-rw-r--r-- 1 root root 1857 Jan 7 21:38 image.php
drwxr-xr-x 3 root root 4096 Apr 19 19:14 images
drwxr-xr-x 2 root root 4096 Apr 19 19:14 img
-rw-r--r-- 1 root root 3704 Apr 3 21:58 imgstore.php
drwxr-xr-x 1 root root 4096 May 16 15:13 include
-rw-r--r-- 1 root root 3522 Apr 4 14:34 index.php
-rw-r--r-- 1 root root 2835 Jan 7 21:38 index_http.php
-rw-r--r-- 1 root root 77893 Apr 15 20:08 items.php
drwxr-xr-x 5 root root 4096 Apr 19 19:14 js
-rw-r--r-- 1 root root 13786 Mar 15 20:58 jsLoader.php
-rw-r--r-- 1 root root 17451 Apr 10 17:09 jsrpc.php
-rw-r--r-- 1 root root 25424 Apr 4 16:09 latest.php
drwxr-xr-x 4 root root 4096 Apr 19 19:14 local
drwxr-xr-x 35 root root 4096 Apr 19 19:14 locale
-rw-r--r-- 1 root root 19986 Apr 15 20:08 maintenance.php
-rw-r--r-- 1 root root 6961 Mar 15 22:37 map.import.php
-rw-r--r-- 1 root root 2438 Jan 7 21:38 map.php
-rw-r--r-- 1 root root 8612 Mar 5 23:26 overview.php
-rw-r--r-- 1 root root 90 May 16 15:10 phpinfo.php
-rw-r--r-- 1 root root 6707 Mar 11 22:20 profile.php
-rw-r--r-- 1 root root 8430 Apr 4 13:54 queue.php
-rw-r--r-- 1 root root 15408 Jan 7 21:38 report2.php
-rw-r--r-- 1 root root 8282 Feb 28 21:02 report4.php
-rw-r--r-- 1 root root 974 Apr 21 2016 robots.txt
-rw-r--r-- 1 root root 6965 Mar 15 22:37 screen.import.php
-rw-r--r-- 1 root root 13977 Apr 15 20:08 screenconf.php
-rw-r--r-- 1 root root 10446 Jan 7 21:38 screenedit.php
-rw-r--r-- 1 root root 4401 Jan 7 21:38 screens.php
-rw-r--r-- 1 root root 12271 Apr 8 22:33 services.php
-rw-r--r-- 1 root root 4332 Apr 12 21:37 setup.php
-rw-r--r-- 1 root root 12757 Apr 15 20:08 slideconf.php
-rw-r--r-- 1 root root 6429 Jan 9 19:08 slides.php
-rw-r--r-- 1 root root 5413 Jan 7 21:38 srv_status.php
drwxr-xr-x 2 root root 4096 Apr 19 19:14 styles
-rw-r--r-- 1 root root 9624 Mar 15 22:37 sysmap.php
-rw-r--r-- 1 root root 16791 Apr 15 20:08 sysmaps.php
-rw-r--r-- 1 root root 29323 Apr 15 20:08 templates.php
-rw-r--r-- 1 root root 6671 Feb 14 02:44 toptriggers.php
-rw-r--r-- 1 root root 5579 Mar 6 00:08 tr_events.php
-rw-r--r-- 1 root root 24970 Apr 16 21:36 trigger_prototypes.php
-rw-r--r-- 1 root root 36506 Apr 15 20:08 triggers.php
-rw-r--r-- 1 root root 15537 Apr 15 20:08 usergrps.php
-rw-r--r-- 1 root root 13245 Apr 15 20:08 users.php
-rw-r--r-- 1 root root 841 Jan 7 21:38 zabbix.php
[root@eedb7623a802 zabbix]# cat zabbix.php
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__).'/include/config.inc.php';
修改/usr/share/zabbix/include/config.inc.php文件,加上date_default_timezone_set('Asia/Shanghai');來設置時區:
[root@eedb7623a802 zabbix]# vi include/config.inc.php
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
date_default_timezone_set('Asia/Shanghai');
// reset the LC_CTYPE locale so that case transformation functions would work correctly
// it is also required for PHP to work with the Turkish locale (https://bugs.php.net/bug.php?id=18556)
// WARNING: this must be done before executing any other code, otherwise code execution could fail!
// this will be unnecessary in PHP 5.5
......
不需要重啟,刷新下頁面就能看到時間已經正常了。上面的apache容器也可以這樣改。
其實nginx容器和apache容器只需要一個就行了,可以修改docker-compose_v3_centos_mysql_latest.yaml文件,只保留一個。