美文网首页
Docker mysql主从复制

Docker mysql主从复制

作者: soane1983 | 来源:发表于2018-12-11 20:02 被阅读0次

1.下载镜像

docker pull mysql:5.7

2.主节点创建/opt/mysql/master/conf,/opt/mysql/master/data;主节点创建/opt/mysql/slave/conf,/opt/mysql/slave/data

3. 主节点/opt/mysql/master/conf新建my.cnf

[mysqld]

symbolic-links=0

character-set-server = utf8 

#skip-networking 

innodb_print_all_deadlocks = 1

max_connections = 2000 

max_connect_errors = 6000 

open_files_limit = 65535 

table_open_cache = 128 

max_allowed_packet = 4M 

binlog_cache_size = 1M 

max_heap_table_size = 8M 

tmp_table_size = 16M 

read_buffer_size = 2M 

read_rnd_buffer_size = 8M 

sort_buffer_size = 8M 

join_buffer_size = 28M 

key_buffer_size = 4M 

thread_cache_size = 8 

query_cache_type = 1 

query_cache_size = 8M 

query_cache_limit = 2M 

ft_min_word_len = 4 

log-bin = mysql-bin

server-id = 1

binlog_format = mixed 

performance_schema = 0 

explicit_defaults_for_timestamp 

#lower_case_table_names = 1 

interactive_timeout = 28800 

wait_timeout = 28800 

# Recommended in standard MySQL setup 

sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES 

[mysqldump] 

quick 

max_allowed_packet = 16M 

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

4. 从节点/opt/mysql/slave/conf新建my.cnf

[mysqld]

symbolic-links=0

character-set-server = utf8 

#skip-networking 

innodb_print_all_deadlocks = 1

max_connections = 2000 

max_connect_errors = 6000 

open_files_limit = 65535 

table_open_cache = 128 

max_allowed_packet = 4M 

binlog_cache_size = 1M 

max_heap_table_size = 8M 

tmp_table_size = 16M 

read_buffer_size = 2M 

read_rnd_buffer_size = 8M 

sort_buffer_size = 8M 

join_buffer_size = 28M 

key_buffer_size = 4M 

thread_cache_size = 8 

query_cache_type = 1 

query_cache_size = 8M 

query_cache_limit = 2M 

ft_min_word_len = 4 

log-bin = mysql-bin

server-id = 2

binlog_format = mixed 

performance_schema = 0 

explicit_defaults_for_timestamp 

#lower_case_table_names = 1 

interactive_timeout = 28800 

wait_timeout = 28800 

# Recommended in standard MySQL setup 

sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES 

[mysqldump] 

quick 

max_allowed_packet = 16M 

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

5. 启动主节点  

docker run -p 3306:3306 --name mysql -v /opt/mysql/master/conf/my.cnf:/etc/mysql/my.cnf -v /opt/mysql/master/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

6. 启动从节点

docker run -p 3306:3306 --name mysql -v /opt/mysql/slave/conf/my.cnf:/etc/mysql/my.cnf -v /opt/mysql/slave/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

7. 主节点:

docker exec -it mysql /bin/bash

mysql -uroot -p123456

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

GRANT REPLICATION SLAVE ON *.* to 'reader'@'%' identified by '123456';

FLUSH PRIVILEGES;

8. 从节点

docker exec -it mysql /bin/bash

mysql -uroot -p123456

grant SHOW DATABASES,SELECT on *.* to 'slave'@'%' identified by '123456';

FLUSH PRIVILEGES;

9. 主机点:

show master status;

10. 从节点:

change master to master_host='10.11.17.248',master_user='reader',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=889;

start slave;

相关文章

网友评论

      本文标题:Docker mysql主从复制

      本文链接:https://www.haomeiwen.com/subject/ezoehqtx.html