Written on the front
MySQL to build separate read and write from the main cluster, there is not used binlog
the way, using the GTID
way 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 nodeconfig/master.cnf
: MySQL Master node configuration fileconfig/slave.cnf
: MySQL Slave node configuration filedocker-compose.yml
: Construction docker-compose the main configuration file from the node data directory mountmaster-data
: The master node position data, of course, linked to the production environment to another locationslave-data
: Data from the node positions, of course, linked to the production environment to another locationbin/slave-replias-master-start.sh
: Add the primary node from node backup account information and turn on the backup scriptbin/stop-replicas.sh
: Script closed from node backupbin/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 filebin/show-slave-status.sh
: View from the connection status of the main script
Build process:
1. Modify the .env
file
# 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_DATA
Master node directory data, to modify the position corresponding to the host, SLAVE_DATA versa.MASTER_PASSWD
The master node is the root password, the script in the bin directory will read the value of the variable in order to access the databaseSLAVE_PASSWD
From the node is the root password, the script will readREPL_NAME
Is the name of the account you want to create the master node, node accessed from this account
REPL_PASSWD
It is the primary node to createREPL_NAME
the 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