CentOS 7.2 Dockerに基づくMySQLマスター・スレーブ・アーキテクチャの実装
12555 ワード
原文住所:https://blog.csdn.net/sunnyfg/article/details/80655823
1.Dockerのインストール(略)
Centos 7でDockerをインストールします.https://www.cnblogs.com/jiangxiaobo/p/10904002.html
https://www.runoob.com/docker/centos-docker-install.html
2.mysqlミラーのロード
https://www.runoob.com/docker/docker-install-mysql.html
3.プライマリ・スレーブ・データベースのプロファイルの追加
編集/usr/local/mysqlData/master/cnf/mysql.cnf
編集/usr/local/mysqlData/slave/cnf/mysql.cnf
4.masterとslaveコンテナを有効にする
5.データベースがリモートアクセスを開始
6.主従同期の設定
転載先:https://www.cnblogs.com/jiangxiaobo/p/10906260.html
1.Dockerのインストール(略)
Centos 7でDockerをインストールします.https://www.cnblogs.com/jiangxiaobo/p/10904002.html
https://www.runoob.com/docker/centos-docker-install.html
2.mysqlミラーのロード
https://www.runoob.com/docker/docker-install-mysql.html
docker pull mysql:5.6
3.プライマリ・スレーブ・データベースのプロファイルの追加
##
sudo mkdir -p /usr/local/mysqlData/master/cnf
sudo mkdir -p /usr/local/mysqlData/master/data
sudo mkdir -p /usr/local/mysqlData/slave/cnf
sudo mkdir -p /usr/local/mysqlData/slave/data
sudo touch /usr/local/mysqlData/master/cnf/mysql.cnf
sudo touch /usr/local/mysqlData/slave/cnf/mysql.cnf
編集/usr/local/mysqlData/master/cnf/mysql.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
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
編集/usr/local/mysqlData/slave/cnf/mysql.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
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
4.masterとslaveコンテナを有効にする
##master
sudo docker run -itd -p 3307:3306 --name master -v /usr/local/mysqlData/master/cnf:/etc/mysql/conf.d -v /usr/local/mysqlData/master/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
## master
sudo docker exec -it master /bin/bash
root@ebc7017a58ef:/#
##slave
sudo docker run -itd -p 3308:3306 --name slave -v /usr/local/mysqlData/slave/cnf:/etc/mysql/conf.d -v /usr/local/mysqlData/slave/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
root@ee3bb51b4d14:/#
5.データベースがリモートアクセスを開始
##
sudo firewall-cmd --add-port=3307/tcp --permanent
sudo firewall-cdm --add-port=3308/tcp --permanent
sudo firewall-cmd --reload
## master
root@ebc7017a58ef:/# mysql -uroot -p123456
mysql>grant all privileges on *.* to reader@'%' identified by 'readerpwd' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql>flush privileges;
Query OK, 0 rows affected (0.01 sec)
## slave
root@ee3bb51b4d14:/# mysql -uroot -p123456
mysql>grant all privileges on *.* to slave@'%' identified by 'slavepwd' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql>flush privileges;
Query OK, 0 rows affected (0.01 sec)
6.主従同期の設定
## master master
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 204 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
mysql-bin.000002 ,
## slave
mysql> change master to master_host='172.17.0.6',master_user='reader',master_password='readerpwd',master_log_file='mysql-bin.000002',master_log_pos=501;
##
master_host,master ip
master_user, master
master_password,master_user
master_log_file, , ,master status
## slave,slave ,start,stop restart
mysql> start slave;
## slave
mysql> show slave status;
転載先:https://www.cnblogs.com/jiangxiaobo/p/10906260.html