前期准备工作
新建必要文件夹
mkdir -p zabbix/{etc,fonts}
准备字体文件
存放在 ./zabbix/fonts/
下就可以
不过名字必须叫DejaVuSans.ttf
可以根据自己的需求,在windows的字体库里找到想要的ttf格式的字体,修改成上面的名字就可以。
准备mysql的配置文件
存放位置: ./zabbix/etc/
名称就是my.cnf
范例配置文件(可以根据实际情况自行优化)
[mysqld]
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
symbolic-links=0
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
max_connections = 4000
max_connect_errors = 6000
max_user_connections=1000
innodb_file_per_table = 1
#5.7版本 单位天
#expire_logs_days=7
#8版本 单位秒
binlog_expire_logs_seconds=604800
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock
!includedir /etc/mysql/conf.d/
docker-compose文件部分
---
version: '3'
services:
mysql:
image: mysql:8.0.31
container_name: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root8943
#MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
volumes:
- ./zabbix/db:/var/lib/mysql
- ./zabbix/etc/my.cnf:/etc/my.cnf
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
ports:
- 3306:3306
networks:
- zabbix-net
command:
- --default-authentication-plugin=mysql_native_password
- --character-set-server=utf8
- --collation-server=utf8_bin
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:centos-6.2.4
container_name: zabbix-snmptraps
restart: always
ports:
- 162:162/udp
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
- snmptraps:/var/lib/zabbix/snmptraps:rw
- mibs:/var/lib/zabbix/mibs
zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:centos-6.2.4
container_name: zabbix-java-gateway
restart: always
networks:
- zabbix-net
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
ports:
- 10052:10052
zabbix-server-mysql:
image: zabbix/zabbix-server-mysql:centos-6.2.4
container_name: zabbix-server-mysql
restart: always
networks:
- zabbix-net
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
- ./zabbix/alertscripts:/usr/lib/zabbix/alertscripts
- snmptraps:/var/lib/zabbix/snmptraps
- zabbix-conf:/etc/zabbix
- mibs:/var/lib/zabbix/mibs
ports:
- 10051:10051
environment:
DB_SERVER_HOST: mysql
DB_SERVER_PORT: 3306
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_DATABASE: zabbix
MYSQL_ROOT_PASSWORD: root8943
ZBX_ENABLE_SNMP_TRAPS: true
ZBX_STARTPOLLERS: 10
ZBX_STARTTRAPPERS: 100
ZBX_STARTDISCOVERERS: 3
ZBX_STARTPINGERS: 10
ZBX_JAVAGATEWAY_ENABLE: true
ZBX_JAVAGATEWAY: zabbix-java-gateway
ZBX_JAVAGATEWAYPORT: 10052
ZBX_CACHESIZE: 1024M
ZBX_VALUECACHESIZE: 1024M
ZBX_VMWARECACHESIZE: 256M
depends_on:
- mysql
- zabbix-java-gateway
zabbix-web-nginx-mysql:
image: zabbix/zabbix-web-nginx-mysql:centos-6.2.4
container_name: zabbix-web-nginx-mysql
restart: always
networks:
- zabbix-net
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
- ./zabbix/fonts/DejaVuSans.ttf:/usr/share/zabbix/assets/fonts/DejaVuSans.ttf
environment:
DB_SERVER_HOST: mysql
DB_SERVER_PORT: 3306
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
ZBX_SERVER_HOST: zabbix-server-mysql
PHP_TZ: Asia/Shanghai
ZBX_SERVER_PORT: 10051
MYSQL_DATABASE: zabbix
ZBX_SERVER_NAME: admin
ports:
- 8080:8080
depends_on:
- mysql
- zabbix-server-mysql
networks:
zabbix-net:
volumes:
snmptraps:
zabbix-conf:
mibs:
zabbix-proxy-conf:
运行文件
这里没有把agent也放在里面,是因为,agent一般是不运行在容器中的,因为还需要监控docker,放在容器中运行反而复杂了,在宿主机上运行agent来监控宿主机,更方便。
监控docker,只需要给zabbix用户加入到docker组就可以了
usermod -aG docker zabbix
然后重启服务就好了
标签:compose,mysql,etc,zabbix,MYSQL,var,docker,ZBX From: https://www.cnblogs.com/guangdelw/p/17052988.html