Docker build a master-slave MySQL Cluster, based GTID

Written on the front

MySQL to build separate read and write from the main cluster, there is not used binlogthe way, using the GTIDway of
the sour My Github https://github.com/hellxz/mysql-cluster-docker.git

Master-slave directory structure

.
├── bin
│   ├── add-slave-account-to-master.sh
│   ├── reset-slave.sh
│   ├── slave-replias-master-start.sh
│   └── stop-replicas.sh
├── config
│   ├── master.cnf
│   └── slave.cnf
├── docker-compose.yml
├── .env
├── master-data
├── show-slave-status.sh
└── slave-data

Directory / File Description:

  • bin/add-slave-account-to-master.sh : Add a backup account script Master node
  • config/master.cnf : MySQL Master node configuration file
  • config/slave.cnf : MySQL Slave node configuration file
  • docker-compose.yml : Construction docker-compose the main configuration file from the node data directory mount
  • master-data : The master node position data, of course, linked to the production environment to another location
  • slave-data : Data from the node positions, of course, linked to the production environment to another location
  • bin/slave-replias-master-start.sh : Add the primary node from node backup account information and turn on the backup script
  • bin/stop-replicas.sh : Script closed from node backup
  • bin/reset-slave.sh : Reset state from node backup, restoration can not be established because the main cluster after cluster reboot problem
  • .env : The environment variable file
  • bin/show-slave-status.sh: View from the connection status of the main script

Build process:

1. Modify the .envfile

# default environment arguments for docker-compose.yml
# set master data dir
MASTER_DATA=./master-data
# set slave data dir
SLAVE_DATA=./slave-data
# set master & slave root password
MASTER_PASSWD=P@ssw0rd
# set slave root passwor
SLAVE_PASSWD=P@ssw0rd
# set replicas mysql account name
REPL_NAME=replicas
# set replicas mysql password
REPL_PASSWD=replicasPasswd
  • MASTER_DATAMaster node directory data, to modify the position corresponding to the host, SLAVE_DATA versa.

  • MASTER_PASSWDThe master node is the root password, the script in the bin directory will read the value of the variable in order to access the database
  • SLAVE_PASSWDFrom the node is the root password, the script will read
  • REPL_NAMEIs the name of the account you want to create the master node, node accessed from this account
  • REPL_PASSWDIt is the primary node to create REPL_NAMEthe corresponding password

2. Start two nodes, performdocker-compose up -d

Examination has started

3. Go to the bin directory, execute scripts

cd bin
./add-slave-account-to-master.sh #读取mysql密码,为主节点添加备份账户
./slave-replias-master-start.sh #从节点使用备份账户连接主节点,开启备份

4. Check the cluster status, run in the bin directory./show-slave-status.sh

This set up is complete.

Failure recovery

1. Restart MySQL Cluster can not recover from node to resolve normal.

Bin directory under the Executive reset-slave.sh, after attempts to connect to the database, the problem has been resolved.

This article is the original article, refused reproduced

Guess you like

Origin www.cnblogs.com/hellxz/p/docker-mysql-cluster.html