diff --git a/git/README.md b/git/README.md index cf9a387..d04fb75 100644 --- a/git/README.md +++ b/git/README.md @@ -4,4 +4,10 @@ 详细请参考: https://hub.docker.com/r/alpine/git +## 镜像下载 + +``` +docker pull registry.cn-hangzhou.aliyuncs.com/kennylee/git +``` + diff --git a/mysql/README.md b/mysql/README.md index d95866e..bf643e6 100755 --- a/mysql/README.md +++ b/mysql/README.md @@ -1,23 +1,23 @@ # MySQL -### 说明 +## 说明 官方 https://hub.docker.com/_/mysql/ 修改: 1. 修改默认mysql默认编码为utf-8 -2. 可自行修改my.cnf +2. 可自行修改my.cnf进行构建 3. 去掉默认的 VOLUME /var/lib/mysql 方便备份。 -#### 阿里云构建的镜像 +### 阿里云构建的镜像 ``` docker pull registry.cn-hangzhou.aliyuncs.com/kennylee/mysql ``` -### 构建命令 +## 构建命令 * build @@ -25,14 +25,53 @@ docker pull registry.cn-hangzhou.aliyuncs.com/kennylee/mysql docker build -t kennylee26/mysql ./ ``` -## 主从同步 +## MySQL主从同步(单向同步)实例 + +单向同步实现比较简单,双向就完全不同了,因为会涉及到事务和数据冲突等问题。一些读写分离和轻量级的高可用环境下课考虑使用。 ``` -docker-compose -f docker-compose-replication.yml up --build -d +docker-compose -f : up --build -d ``` 注意由于 `slave` 的数据库中的 `replication/slave-backup/schema.sql` 需要根据 `master` 的情况来修改,所以未必每次可用,可根据实际情况来修改。具体操作是登录 `master` 容器中的mysql控制台内,敲入 `SHOW MASTER STATUS;` 来查看。 提醒下,正式使用时,注意数据分离,`docker-compose-replication.yml` 例子中为了增加logbin准确度,所以没映射log目录出来。 +### 配置说明 + +#### master + +``` +# 服务器IP +bind-address = 172.16.10.1 +# 集群的server id +server-id = 1 +# 同步依赖 log-bin 所以必须配置 +log-bin = /var/log/mysql/mysql-bin.log +# 配置同步的数据库,多个写多行,不写全部都备份 +binlog_do_db = newdatabase +# 自动清理21天的日志 +expire_logs_days = 21 +``` + +配置好之后,还需要建立同步的账号,命令参考如下: + +``` +GRANT REPLICATION SLAVE ON *.* TO 'rep'@'%' IDENTIFIED BY '111111'; +``` + +#### slave + +``` +server-id = 2 +relay-log = /var/log/mysql/mysql-relay-bin.log +``` + +mysql控制台,配置master同步的配置信息注意 `MASTER_LOG_FILE` 和 `MASTER_LOG_POS` + +``` +CHANGE MASTER TO MASTER_HOST='172.16.10.1',MASTER_USER='rep', MASTER_PASSWORD='111111', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS= 154; +``` + +详细见 `replication/slave-backup/schema.sql` 文件 diff --git a/mysql/docker-compose-replication.yml b/mysql/docker-compose-replication.yml index 9c18487..3b90953 100644 --- a/mysql/docker-compose-replication.yml +++ b/mysql/docker-compose-replication.yml @@ -19,7 +19,7 @@ services: restart: on-failure volumes: - ./data/my-master:/var/lib/mysql/:rw - #- ./data/my-master-log:/var/log/mysql/:rw + #- ./data/my-master-logs:/var/log/mysql/:rw networks: *network : ipv4_address: 172.16.10.1 @@ -38,7 +38,7 @@ services: restart: on-failure volumes: - ./data/my-slave-backup:/var/lib/mysql/:rw - #- ./data/my-slave-backup-log:/var/log/mysql/:rw + #- ./data/my-slave-backup-logs:/var/log/mysql/:rw networks: - *network logging: diff --git a/mysql/docker-compose.yml b/mysql/docker-compose.yml index 9bc7fbf..4047eed 100644 --- a/mysql/docker-compose.yml +++ b/mysql/docker-compose.yml @@ -3,6 +3,7 @@ version: '3' services: app: image: registry.cn-hangzhou.aliyuncs.com/kennylee/mysql + #build: ./ ports: - 3306:3306 container_name: mysql @@ -10,7 +11,8 @@ services: environment: - MYSQL_ROOT_PASSWORD=111111 volumes: - - ./data/:/var/lib/mysql/:z + - ./data/standalong:/var/lib/mysql/:z + #- ./data/standalong-logs:/var/log/mysql/:z logging: driver: 'json-file' options: diff --git a/mysql/my.cnf b/mysql/my.cnf index e12ec96..ab116cb 100644 --- a/mysql/my.cnf +++ b/mysql/my.cnf @@ -56,11 +56,29 @@ collation-server = utf8_unicode_ci #log-error = /var/log/mysql/error.log # Recommended in standard MySQL setup -sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES +sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 +# 开启binlog +server-id = 1 +log-bin = /var/log/mysql/mysql-bin.log +binlog_format = MIXED +# 自动删除7天之前的binlog +expire_logs_days = 7 + +# 慢查询配置 +slow_query_log = 1 +slow_query_log_file = /var/log/mysql/mysql-slow-queries.log +# 超过定义为慢查询 +long_query_time = 4 + +# 日志输出方式 +# log_output = FILE,TABLE +# 未使用索引的查询也被记录到慢查询日志中 +log_queries_not_using_indexes = 1 + # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # diff --git a/mysql/replication/master/my.cnf b/mysql/replication/master/my.cnf index 0577ea7..1cadc86 100644 --- a/mysql/replication/master/my.cnf +++ b/mysql/replication/master/my.cnf @@ -55,8 +55,9 @@ bind-address = 172.16.10.1 server-id = 1 log-bin = /var/log/mysql/mysql-bin.log +binlog_format = MIXED -# need to replication +# 配置同步的数据库,多个写多行,不写全部都备份 binlog-do-db = test #binlog-ignore-db = mysql @@ -68,6 +69,8 @@ sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 +# 自动删除21天之前的日志 +expire_logs_days = 21 # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # diff --git a/mysql/replication/slave-backup/my.cnf b/mysql/replication/slave-backup/my.cnf index 24d8e11..834737b 100644 --- a/mysql/replication/slave-backup/my.cnf +++ b/mysql/replication/slave-backup/my.cnf @@ -55,6 +55,7 @@ collation-server=utf8_unicode_ci server-id = 2 relay-log = /var/log/mysql/mysql-relay-bin.log +slave-skip-errors = 1007,1008,1053,1062,1213,1158,1159 #log-error = /var/log/mysql/error.log @@ -64,6 +65,9 @@ sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 +# 自动删除21天之前的日志 +expire_logs_days = 21 + # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. #