mirror of
https://gitee.com/kennylee/docker.git
synced 2024-11-29 18:38:34 +08:00
1、优化mysql的初始化配置。2、优化mysql的README
This commit is contained in:
parent
b9f7f54c2d
commit
ddfe223d64
@ -4,4 +4,10 @@
|
|||||||
|
|
||||||
详细请参考: https://hub.docker.com/r/alpine/git
|
详细请参考: https://hub.docker.com/r/alpine/git
|
||||||
|
|
||||||
|
## 镜像下载
|
||||||
|
|
||||||
|
```
|
||||||
|
docker pull registry.cn-hangzhou.aliyuncs.com/kennylee/git
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
# MySQL
|
# MySQL
|
||||||
|
|
||||||
### 说明
|
## 说明
|
||||||
|
|
||||||
官方 https://hub.docker.com/_/mysql/
|
官方 https://hub.docker.com/_/mysql/
|
||||||
|
|
||||||
修改:
|
修改:
|
||||||
|
|
||||||
1. 修改默认mysql默认编码为utf-8
|
1. 修改默认mysql默认编码为utf-8
|
||||||
2. 可自行修改my.cnf
|
2. 可自行修改my.cnf进行构建
|
||||||
3. 去掉默认的 VOLUME /var/lib/mysql 方便备份。
|
3. 去掉默认的 VOLUME /var/lib/mysql 方便备份。
|
||||||
|
|
||||||
|
|
||||||
#### 阿里云构建的镜像
|
### 阿里云构建的镜像
|
||||||
|
|
||||||
```
|
```
|
||||||
docker pull registry.cn-hangzhou.aliyuncs.com/kennylee/mysql
|
docker pull registry.cn-hangzhou.aliyuncs.com/kennylee/mysql
|
||||||
```
|
```
|
||||||
|
|
||||||
### 构建命令
|
## 构建命令
|
||||||
|
|
||||||
* build
|
* build
|
||||||
|
|
||||||
@ -25,14 +25,53 @@ docker pull registry.cn-hangzhou.aliyuncs.com/kennylee/mysql
|
|||||||
docker build -t kennylee26/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;` 来查看。
|
注意由于 `slave` 的数据库中的 `replication/slave-backup/schema.sql` 需要根据 `master` 的情况来修改,所以未必每次可用,可根据实际情况来修改。具体操作是登录 `master` 容器中的mysql控制台内,敲入 `SHOW MASTER STATUS;` 来查看。
|
||||||
|
|
||||||
提醒下,正式使用时,注意数据分离,`docker-compose-replication.yml` 例子中为了增加logbin准确度,所以没映射log目录出来。
|
提醒下,正式使用时,注意数据分离,`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` 文件
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ services:
|
|||||||
restart: on-failure
|
restart: on-failure
|
||||||
volumes:
|
volumes:
|
||||||
- ./data/my-master:/var/lib/mysql/:rw
|
- ./data/my-master:/var/lib/mysql/:rw
|
||||||
#- ./data/my-master-log:/var/log/mysql/:rw
|
#- ./data/my-master-logs:/var/log/mysql/:rw
|
||||||
networks:
|
networks:
|
||||||
*network :
|
*network :
|
||||||
ipv4_address: 172.16.10.1
|
ipv4_address: 172.16.10.1
|
||||||
@ -38,7 +38,7 @@ services:
|
|||||||
restart: on-failure
|
restart: on-failure
|
||||||
volumes:
|
volumes:
|
||||||
- ./data/my-slave-backup:/var/lib/mysql/:rw
|
- ./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:
|
networks:
|
||||||
- *network
|
- *network
|
||||||
logging:
|
logging:
|
||||||
|
@ -3,6 +3,7 @@ version: '3'
|
|||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: registry.cn-hangzhou.aliyuncs.com/kennylee/mysql
|
image: registry.cn-hangzhou.aliyuncs.com/kennylee/mysql
|
||||||
|
#build: ./
|
||||||
ports:
|
ports:
|
||||||
- 3306:3306
|
- 3306:3306
|
||||||
container_name: mysql
|
container_name: mysql
|
||||||
@ -10,7 +11,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- MYSQL_ROOT_PASSWORD=111111
|
- MYSQL_ROOT_PASSWORD=111111
|
||||||
volumes:
|
volumes:
|
||||||
- ./data/:/var/lib/mysql/:z
|
- ./data/standalong:/var/lib/mysql/:z
|
||||||
|
#- ./data/standalong-logs:/var/log/mysql/:z
|
||||||
logging:
|
logging:
|
||||||
driver: 'json-file'
|
driver: 'json-file'
|
||||||
options:
|
options:
|
||||||
|
20
mysql/my.cnf
20
mysql/my.cnf
@ -56,11 +56,29 @@ collation-server = utf8_unicode_ci
|
|||||||
#log-error = /var/log/mysql/error.log
|
#log-error = /var/log/mysql/error.log
|
||||||
|
|
||||||
# Recommended in standard MySQL setup
|
# 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
|
# Disabling symbolic-links is recommended to prevent assorted security risks
|
||||||
symbolic-links=0
|
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!
|
# * IMPORTANT: Additional settings that can override those from this file!
|
||||||
# The files must end with '.cnf', otherwise they'll be ignored.
|
# The files must end with '.cnf', otherwise they'll be ignored.
|
||||||
#
|
#
|
||||||
|
@ -55,8 +55,9 @@ bind-address = 172.16.10.1
|
|||||||
|
|
||||||
server-id = 1
|
server-id = 1
|
||||||
log-bin = /var/log/mysql/mysql-bin.log
|
log-bin = /var/log/mysql/mysql-bin.log
|
||||||
|
binlog_format = MIXED
|
||||||
|
|
||||||
# need to replication
|
# 配置同步的数据库,多个写多行,不写全部都备份
|
||||||
binlog-do-db = test
|
binlog-do-db = test
|
||||||
#binlog-ignore-db = mysql
|
#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
|
# Disabling symbolic-links is recommended to prevent assorted security risks
|
||||||
symbolic-links=0
|
symbolic-links=0
|
||||||
|
|
||||||
|
# 自动删除21天之前的日志
|
||||||
|
expire_logs_days = 21
|
||||||
# * IMPORTANT: Additional settings that can override those from this file!
|
# * IMPORTANT: Additional settings that can override those from this file!
|
||||||
# The files must end with '.cnf', otherwise they'll be ignored.
|
# The files must end with '.cnf', otherwise they'll be ignored.
|
||||||
#
|
#
|
||||||
|
@ -55,6 +55,7 @@ collation-server=utf8_unicode_ci
|
|||||||
|
|
||||||
server-id = 2
|
server-id = 2
|
||||||
relay-log = /var/log/mysql/mysql-relay-bin.log
|
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
|
#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
|
# Disabling symbolic-links is recommended to prevent assorted security risks
|
||||||
symbolic-links=0
|
symbolic-links=0
|
||||||
|
|
||||||
|
# 自动删除21天之前的日志
|
||||||
|
expire_logs_days = 21
|
||||||
|
|
||||||
# * IMPORTANT: Additional settings that can override those from this file!
|
# * IMPORTANT: Additional settings that can override those from this file!
|
||||||
# The files must end with '.cnf', otherwise they'll be ignored.
|
# The files must end with '.cnf', otherwise they'll be ignored.
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user