docker-compose構建 mysql 主從複製(讀寫分離)集羣
MySQL master-slave replication with using Docker.
源碼在github上:
https://github.com/docker-box...mysql
git clone https://github.com/docker-box/mysql-cluster.git cd mysql-cluster ./build.sh
能夠在build.sh
內自定義對應參數提示: 運行前須要確保安裝了docker和docker-compose,具體安裝方法請參考官網git
若是想手動安裝, 則能夠按照
build.sh
內的命令來手動執行便可github
docker exec mysql_master sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'create table code(code int); insert into code values (100), (200)'"
docker exec mysql_slave sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'select * from code \G'"
docker exec mysql_slave2 sh -c "export MYSQL_PWD=111; mysql -u root mydb -e 'select * from code \G'"
若是前邊的安裝正確的話, 就能夠看到第一步插入的兩條數據了
docker-compose logs
docker-compose ps
docker exec mysql_master sh -c 'mysql -u root -p111 -e "SHOW MASTER STATUS \G"'
docker exec mysql_slave sh -c 'mysql -u root -p111 -e "SHOW SLAVE STATUS \G"'
docker exec mysql_slave2 sh -c 'mysql -u root -p111 -e "SHOW SLAVE STATUS \G"'
docker exec -it mysql_master bash
docker exec -it mysql_slave bash
docker exec -it mysql_slave2 bash