Mysql单实例编排

1、创建目录

mkdir docker-mysql/{logs,data,conf}
cd docker-mysql/
mkdir logs/{bin-log,err-log,slow-log}
chmod 777 logs/{bin-log,err-log,slow-log}

2、准备配置

vim conf/my.cnf
# init.d
# Default values that applies to all MySQL Servers
[mysqld]
#skip-grant-tables

datadir = /var/lib/mysql
#tmpdir = /tmp/mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
slow_query_log_file = /var/log/mysql/slow-log/slow_warn.log
log-error       = /var/log/mysql/err-log/error.log

server_id = 666
user = mysql
port = 3309
bind-address = 0.0.0.0
character-set-server = utf8
default_storage_engine = InnoDB

open-files-limit =           1048576
local-infile

max_allowed_packet=60000M
max_connections = 10000
#wait_timeout = 120

#character-set-server=      latin1

# Increase default connect_timeout to avoid intermittent
# disconnects when test servers are put under load see BUG#28359
connect-timeout=            60

log-bin-trust-function-creators=1
key_buffer_size=            32M
sort_buffer_size=           256K
tmp_table_size = 64M
max_heap_table_size=        32M

loose-innodb_data_file_path=      ibdata1:10M:autoextend
loose-innodb_buffer_pool_size=    24M
loose-innodb_lru_scan_depth=      100
loose-innodb_write_io_threads=    2
loose-innodb_read_io_threads=     2
loose-innodb_log_buffer_size=     1M
loose-innodb_log_file_size=       5M
loose-innodb_log_files_in_group=  2

slave-net-timeout=120

log-bin = /var/log/mysql/bin-log/mysqld-bin
expire_logs_days=20
relay_log_purge = 1

# MAINTAINER:
# the loose- syntax is to make sure the cnf file is also
# valid when building without the performance schema.

# Run tests with the performance schema instrumentation
loose-enable-performance-schema
# Run tests with a small number of instrumented objects
# to limit memory consumption with MTR
loose-performance-schema-accounts-size=100
loose-performance-schema-digests-size=200
loose-performance-schema-hosts-size=100
loose-performance-schema-users-size=100
loose-performance-schema-max-mutex-instances=5000
loose-performance-schema-max-rwlock-instances=5000
loose-performance-schema-max-cond-instances=1000
loose-performance-schema-max-file-instances=10000
loose-performance-schema-max-socket-instances=1000
loose-performance-schema-max-table-instances=500
loose-performance-schema-max-table-lock-stat=500
loose-performance-schema-max-index-stat=5000
loose-performance-schema-max-table-handles=1000
loose-performance-schema-max-prepared-statements-instances=100
loose-performance-schema-max-program-instances=5000
loose-performance-schema-setup-actors-size=100
loose-performance-schema-setup-objects-size=100

loose-performance-schema-events-waits-history-size=10
loose-performance-schema-events-waits-history-long-size=10000
loose-performance-schema-events-stages-history-size=10
loose-performance-schema-events-stages-history-long-size=1000
loose-performance-schema-events-statements-history-size=10
loose-performance-schema-events-statements-history-long-size=1000
loose-performance-schema-events-transactions-history-size=10
loose-performance-schema-events-transactions-history-long-size=1000
loose-performance-schema-max-thread-instances=200
loose-performance-schema-session-connect-attrs-size=2048
loose-performance-schema-max-metadata-locks=10000

# Enable everything, for maximun code exposure during testing

loose-performance-schema-instrument='%=ON'

loose-performance-schema-consumer-events-stages-current=ON
loose-performance-schema-consumer-events-stages-history=ON
loose-performance-schema-consumer-events-stages-history-long=ON
loose-performance-schema-consumer-events-statements-current=ON
loose-performance-schema-consumer-events-statements-history=ON
loose-performance-schema-consumer-events-statements-history-long=ON
loose-performance-schema-consumer-events-transactions-current=ON
loose-performance-schema-consumer-events-transactions-history=ON
loose-performance-schema-consumer-events-transactions-history-long=ON
loose-performance-schema-consumer-events-waits-current=ON
loose-performance-schema-consumer-events-waits-history=ON
loose-performance-schema-consumer-events-waits-history-long=ON
loose-performance-schema-consumer-global-instrumentation=ON
loose-performance-schema-consumer-thread-instrumentation=ON

binlog-direct-non-transactional-updates

loose-show-compatibility-56=ON

3、定义编排

vim docker-compose.yml
version: '3.1'
services:
  mysql:
    image: daocloud.io/library/mysql:5.7
    container_name: mysql
    hostname: mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=max@2021
    network_mode: "host"
    volumes:
      - ./conf:/etc/mysql
      - ./logs:/var/log/mysql
      - ./data:/var/lib/mysql
    cap_add:
      - SYS_PTRACE
    ulimits:
       memlock:
         soft: -1
         hard: -1
       nofile:
         soft: 655360
         hard: 655360
docker-compose up -d