docker-compose.yml:
version: '3'
services:
mysql:
image: mysql:5.7.33
environment:
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_ROOT_PASSWORD: 123456
volumes:
- /home/mysql/data:/var/lib/mysql
- /home/mysql/my.cnf:/etc/my.cnf
ports:
- 3306:3306
restart: always
server:
image: zabbix/zabbix-server-mysql:alpine-5.2-latest
environment:
DB_SERVER_HOST: mysql
MYSQL_USER: zabbix
MYSQL_DATABASE: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_ROOT_PASSWORD: 123456
volumes:
- /home/zabbix/alertscripts:/usr/lib/zabbix/alertscripts
ports:
- 10051:10051
depends_on:
- mysql
restart: always
web:
image: zabbix/zabbix-web-nginx-mysql:alpine-5.2-latest
environment:
PHP_TZ: Asia/Shanghai
DB_SERVER_HOST: mysql
ZBX_SERVER_HOST: server
MYSQL_USER: zabbix
MYSQL_DATABASE: zabbix
MYSQL_PASSWORD: zabbix
MYSQL_ROOT_PASSWORD: 123456
ports:
- 80:8080
depends_on:
- server
- mysql
restart: always
my.cnf推荐配置如下:
[mysqld]
#解决时区问题
default-time-zone = '+8:00'
#解决mysql日志时间与系统时间不一致问题
log_timestamps=SYSTEM
port=3306
datadir=/var/lib/mysql
#log-error=/var/log/mysqld.log
symbolic-links=0
bind-address=0.0.0.0
lower_case_table_names=1
character_set_server=utf8
max_allowed_packet=500M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#InnoDB用于缓存数据、索引、锁、插入缓冲、数据字典等
innodb_buffer_pool_size=1G
#InnoDB的log buffer
innodb_log_buffer_size = 64M
#InnoDB redo log大小
innodb_log_file_size = 256M
#InnoDB redo log文件组
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 2
lower_case_table_names=1
#连接数
max_connections=600
max_connect_errors=1000
max_user_connections=400
#设置临时表最大值
max_heap_table_size = 100M
tmp_table_size = 100M
#每个连接都会分配的一些排序、连接等缓冲
sort_buffer_size = 2M
join_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
#关闭query cache
query_cache_size = 0
#如果是以InnoDB引擎为主的DB,专用于MyISAM引擎的 key_buffer_size 可以设置较小,8MB 已足够,如果是以MyISAM引擎为主,可设置较大,但不能超过4G
key_buffer_size = 8M
#设置慢查询阀值,单位为秒
long_query_time = 60
slow_query_log=1
log_output=table,File #日志输出会写表,也会写日志文件,为了便于程序去统计,所以最好写表
#slow_query_log_file=${MYSQL_HOME}/log/slow.log
#快速预热缓冲池
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1
#打印deadlock日志
innodb_print_all_deadlocks=1
#二进制配置
server-id = 1
#log-bin = ${MYSQL_HOME}/log/mysql-bin.log
#log-bin-index =${MYSQL_HOME}/log/binlog.index
log_bin_trust_function_creators=1
expire_logs_days=15
#timeout
wait_timeout = 3600
interactive_timeout = 3600
net_read_timeout = 3600
net_write_timeout = 3600
#schedule
event_scheduler = on
#兼容5.6
show_compatibility_56=on
#处理TIMESTAMP with implicit DEFAULT value is deprecated
explicit_defaults_for_timestamp=true
1.安装docker运营环境(略)
创建/home/mysql/data用于存放持久化数据
/home/mysql/my.cnf用于mysql配置
/home/zabbix/alertscripts用于存放额外脚本
2.创建/home/zabbix/docker-compose.yml,写入如上内容(密码自行设置,镜像版本可以自己选择,此处以5.2为例)
3.进入/home/zabbix/目录执行docker-compose up -d
4.浏览器访问zabbix服务器ip即可进入web页面,用户名Admin 密码zabbix