当前位置: 首页 > 工具软件 > zabbix-backup > 使用案例 >

docker-compose 部署 zabbix-server

陆昂然
2023-12-01

docker-compose 部署 zabbix-server

根据官方修改:
https://github.com/zabbix/zabbix-docker

docker-compose_v3_centos_mysql_local.yaml <<<本地bulid镜像运行
docker-compose_v3_centos_mysql_latest.yaml <<<pull镜像运行

运行文件

目录结构

docker-compose.yaml  #compose 编排文件
.env_db_mysql    #数据库配置
.env_srv    #zabbix 配置
.env_web    #httpd(web)配置
.MYSQL_PASSWORD    #mysql 用户密码
.MYSQL_ROOT_PASSWORD    #mysql root密码
.MYSQL_USER   #mysql 用户
zbx_env  # 运行后自动生成 存储配置目录

docker-compose.yaml

version: '3.5'
services:
 zabbix-server:
  image: zabbix/zabbix-server-mysql:centos-4.4-latest
  hostname: zabbix-server
  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
  ulimits:
   nproc: 65535
   nofile:
    soft: 20000
    hard: 40000
  env_file:
   - .env_db_mysql
   - .env_srv
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
   - MYSQL_ROOT_PASSWORD
  user: root
  depends_on:
   - mysql-server
  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

 zabbix-web-apache-mysql:
  image: zabbix/zabbix-web-apache-mysql:centos-4.4-latest
  hostname: zabbix-web-apache
  ports:
   - "80:80"
   - "443: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
  env_file:
   - .env_db_mysql
   - .env_web
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
  user: root
  depends_on:
   - mysql-server
   - zabbix-server
  healthcheck:
   test: ["CMD", "curl", "-f", "http://localhost"]
   interval: 10s
   timeout: 5s
   retries: 3
   start_period: 30s
  sysctls:
   - net.core.somaxconn=65535

 mysql-server:
  image: mysql:8.0
  command: [mysqld, --character-set-server=utf8, --collation-server=utf8_bin, --default-authentication-plugin=mysql_native_password]
  volumes:
   - ./zbx_env/var/lib/mysql:/var/lib/mysql:rw
  env_file:
   - .env_db_mysql
  secrets:
   - MYSQL_USER
   - MYSQL_PASSWORD
   - MYSQL_ROOT_PASSWORD
  user: root
  stop_grace_period: 1m

secrets:
  MYSQL_USER:
    file: ./.MYSQL_USER
  MYSQL_PASSWORD:
    file: ./.MYSQL_PASSWORD
  MYSQL_ROOT_PASSWORD:
    file: ./.MYSQL_ROOT_PASSWORD

.env_db_mysql

# DB_SERVER_HOST=mysql-server
# DB_SERVER_PORT=3306
# MYSQL_USER=zabbix
MYSQL_USER_FILE=/run/secrets/MYSQL_USER
# MYSQL_PASSWORD=zabbix
MYSQL_PASSWORD_FILE=/run/secrets/MYSQL_PASSWORD
# MYSQL_ROOT_PASSWORD=
MYSQL_ROOT_PASSWORD_FILE=/run/secrets/MYSQL_ROOT_PASSWORD
# MYSQL_ALLOW_EMPTY_PASSWORD=false
# MYSQL_DATABASE=zabbix
MYSQL_DATABASE=zabbix

.env_srv

# ZBX_LISTENIP=
# ZBX_HISTORYSTORAGEURL=http://elasticsearch:9200/ # Available since 3.4.5
# ZBX_HISTORYSTORAGETYPES=uint,dbl,str,log,text # Available since 3.4.5
# ZBX_DEBUGLEVEL=3
# ZBX_STARTPOLLERS=5
# ZBX_IPMIPOLLERS=0
# ZBX_STARTPREPROCESSORS=3 # Available since 3.4.0
# ZBX_STARTPOLLERSUNREACHABLE=1
# ZBX_STARTTRAPPERS=5
# ZBX_STARTPINGERS=1
# ZBX_STARTDISCOVERERS=1
# ZBX_STARTHTTPPOLLERS=1
# ZBX_STARTTIMERS=1
# ZBX_STARTESCALATORS=1
# ZBX_STARTALERTERS=3 # Available since 3.4.0
ZBX_JAVAGATEWAY_ENABLE=true
# ZBX_JAVAGATEWAY=zabbix-java-gateway
# ZBX_JAVAGATEWAYPORT=10052
ZBX_STARTJAVAPOLLERS=5
# ZBX_STARTVMWARECOLLECTORS=0
# ZBX_VMWAREFREQUENCY=60
# ZBX_VMWAREPERFFREQUENCY=60
# ZBX_VMWARECACHESIZE=8M
# ZBX_VMWARETIMEOUT=10
ZBX_ENABLE_SNMP_TRAPS=true
# ZBX_SOURCEIP=
# ZBX_HOUSEKEEPINGFREQUENCY=1
# ZBX_MAXHOUSEKEEPERDELETE=5000
# ZBX_SENDERFREQUENCY=30
# ZBX_CACHESIZE=8M
# ZBX_CACHEUPDATEFREQUENCY=60
# ZBX_STARTDBSYNCERS=4
# ZBX_HISTORYCACHESIZE=16M
# ZBX_HISTORYINDEXCACHESIZE=4M
# ZBX_TRENDCACHESIZE=4M
# ZBX_VALUECACHESIZE=8M
# ZBX_TIMEOUT=4
# ZBX_TRAPPERIMEOUT=300
# ZBX_UNREACHABLEPERIOD=45
# ZBX_UNAVAILABLEDELAY=60
# ZBX_UNREACHABLEDELAY=15
# ZBX_LOGSLOWQUERIES=3000
# ZBX_STARTPROXYPOLLERS=1
# ZBX_PROXYCONFIGFREQUENCY=3600
# ZBX_PROXYDATAFREQUENCY=1
# ZBX_LOADMODULE="dummy1.so,dummy2.so,dummy10.so"
# ZBX_TLSCAFILE=
# ZBX_TLSCRLFILE=
# ZBX_TLSCERTFILE=
# ZBX_TLSKEYFILE=

.env_web

# ZBX_SERVER_HOST=zabbix-server
# ZBX_SERVER_PORT=10051
ZBX_SERVER_NAME=Composed installation
# ZBX_HISTORYSTORAGEURL=http://elasticsearch:9200/ # Available since 3.4.5
# ZBX_HISTORYSTORAGETYPES=['uint', 'dbl', 'str', 'text', 'log'] # Available since 3.4.5
# ZBX_MAXEXECUTIONTIME=600
# ZBX_MEMORYLIMIT=128M
# ZBX_POSTMAXSIZE=16M
# ZBX_UPLOADMAXFILESIZE=2M
# ZBX_MAXINPUTTIME=300
# ZBX_SESSION_NAME=zbx_sessionid
# Timezone one of: http://php.net/manual/en/timezones.php
# PHP_TZ=Europe/Riga
PHP_TZ=Asia/Shanghai

.MYSQL_PASSWORD

zabbix

.MYSQL_ROOT_PASSWORD

root_pwd

.MYSQL_USER

zabbix

环境安装

yum install wget telnet -y
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
systemctl enable docker
systemctl start docker


yum install -y docker-compose

systemctl stop firewall

运行

docker-compose -f docker-compose.yaml up -d

查看

http://your ip/
账号:Admin (A大写) 密码:zabbix

zabbix-agent 安装

安装包地址:

http://repo.zabbix.com/zabbix/4.4/

centos7 示例:

rpm -ivh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.3-1.el7.x86_64.rpm

修改配置文件:

#vi /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.4.4
Hostname=centos7 
Include=/etc/zabbix/zabbix_agentd.d/*.conf

问题处理

zabbix_get 测试 zabbix-agent

rpm -ivh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-get-4.4.3-1.el7.x86_64.rpm

zabbix_get -s 192.168.4.4 -p 10050 -k "system.cpu.load[all,avg1]"

Zabbix agent is not available

Get value from agent failed: cannot connect to [[127.0.0.1]:10050]: [111] Connection refused
处理

#查看日志
[root@zabbix zabbix]# tail /var/log/zabbix/zabbix_agentd.log 
 24098:20191206:163347.757 failed to accept an incoming connection: connection from "172.25.0.2" rejected, allowed hosts: "192.168.4.4"
 
#修改 agent 配置文件
vi /etc/zabbix/zabbix_agentd.conf

# 添加一个容器地址。
Server=192.168.4.4,172.25.0.2

# 重启服务
systemctl restart zabbix-agent
在web 界面修改

配置 -->主机–> Zabbix server --> agent代理程序的接口 --> 127.0.0.1 改为实际server地址。这里改为 192.168.4.4 --> 更新

字体

#字体替换:
docker cp ./simkai.ttf zabbix_zabbix-web-apache-mysql_1:/usr/share/zabbix/assets/fonts/
docker exec -it zabbix_zabbix-web-apache-mysql_1 mv -f /usr/share/zabbix/assets/fonts/simkai.ttf /usr/share/zabbix/assets/fonts/DejaVuSans.ttf

时间

方法1.(永久解决)
修改 .env_web文件

修改 PHP_TZ=Europe/Riga 行为  PHP_TZ=Asia/Shanghai  (我的配置文件已经修改!)

方法2.

#编辑/etc/httpd/conf.d/zabbix.conf文件,在 VirtualHost 这一层,加上了php_value date.timezone Asia/Shanghai配置.
docker exec -it zabbix_zabbix-web-apache-mysql_1 sed -i '/phps/a\    php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf

#重启容器
docker restart zabbix_zabbix-web-apache-mysql_1
 类似资料: