Zabbix5.0分布式监控平台搭建

一、简介
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种方式
binzabbix_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文件,只保留一个。
 

原文地址:https://www.cnblogs.com/buffercache/p/14055949.html