MySQL-分布式架构-MyCAT( 二 )

1.1.5 修改权限,启动多实例
chown -R mysql.mysql /data/*systemctl start mysqld3307systemctl start mysqld3308systemctl start mysqld3309systemctl start mysqld3310mysql -S /data/3307/mysql.sock -e "show variables like 'server_id'"mysql -S /data/3308/mysql.sock -e "show variables like 'server_id'"mysql -S /data/3309/mysql.sock -e "show variables like 'server_id'"mysql -S /data/3310/mysql.sock -e "show variables like 'server_id'" 1.1.6 节点主从规划 箭头指向谁是主库
10.0.0.51:3307 <-----> 10.0.0.52:3307 10.0.0.51:3309 ------> 10.0.0.51:3307 10.0.0.52:3309 ------> 10.0.0.52:3307 10.0.0.52:3308 <-----> 10.0.0.51:3308 10.0.0.52:3310 -----> 10.0.0.52:3308 10.0.0.51:3310 -----> 10.0.0.51:33081.1.7 分片规划
shard1: Master:10.0.0.51:3307 slave1:10.0.0.51:3309 Standby Master:10.0.0.52:3307 slave2:10.0.0.52:3309shard2: Master:10.0.0.52:3308 slave1:10.0.0.52:3310 Standby Master:10.0.0.51:3308 slave2:10.0.0.51:33101.1.8 开始配置
shard110.0.0.51:3307 <-----> 10.0.0.52:3307db02mysql -S /data/3307/mysql.sock -e "grant replication slave on *.* to repl@'10.0.0.%' identified by '123';"mysql -S /data/3307/mysql.sock -e "grant all on *.* to root@'10.0.0.%' identified by '123' with grant option;"db01mysql -S /data/3307/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSword='123';"mysql -S /data/3307/mysql.sock -e "start slave;"mysql -S /data/3307/mysql.sock -e "show slave statusG"db02mysql -S /data/3307/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"mysql -S /data/3307/mysql.sock -e "start slave;"mysql -S /data/3307/mysql.sock -e "show slave statusG"10.0.0.51:3309 ------> 10.0.0.51:3307db01mysql -S /data/3309/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"mysql -S /data/3309/mysql.sock -e "start slave;"mysql -S /data/3309/mysql.sock -e "show slave statusG"10.0.0.52:3309 ------> 10.0.0.52:3307db02mysql -S /data/3309/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"mysql -S /data/3309/mysql.sock -e "start slave;"mysql -S /data/3309/mysql.sock -e "show slave statusG"shard210.0.0.52:3308 <-----> 10.0.0.51:3308db01mysql -S /data/3308/mysql.sock -e "grant replication slave on *.* to repl@'10.0.0.%' identified by '123';"mysql -S /data/3308/mysql.sock -e "grant all on *.* to root@'10.0.0.%' identified by '123' with grant option;"db02mysql -S /data/3308/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"mysql -S /data/3308/mysql.sock -e "start slave;"mysql -S /data/3308/mysql.sock -e "show slave statusG"db01mysql -S /data/3308/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"mysql -S /data/3308/mysql.sock -e "start slave;"mysql -S /data/3308/mysql.sock -e "show slave statusG"10.0.0.52:3310 -----> 10.0.0.52:3308db02mysql -S /data/3310/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"mysql -S /data/3310/mysql.sock -e "start slave;"mysql -S /data/3310/mysql.sock -e "show slave statusG"10.0.0.51:3310 -----> 10.0.0.51:3308db01mysql -S /data/3310/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"mysql -S /data/3310/mysql.sock -e "start slave;"mysql -S /data/3310/mysql.sock -e "show slave statusG"1.1.9 检测主从状态
mysql -S /data/3307/mysql.sock -e "show slave statusG"|grep Running:mysql -S /data/3308/mysql.sock -e "show slave statusG"|grep Running:mysql -S /data/3309/mysql.sock -e "show slave statusG"|grep Running:mysql -S /data/3310/mysql.sock -e "show slave statusG"|grep Running:1.1.10 如果中间出现错误,在每个节点进行执行以下命令(2.9 状态正确,忽略此步骤)
mysql -S /data/3307/mysql.sock -e "stop slave; reset slave all;"mysql -S /data/3308/mysql.sock -e "stop slave; reset slave all;"mysql -S /data/3309/mysql.sock -e "stop slave; reset slave all;"mysql -S /data/3310/mysql.sock -e "stop slave; reset slave all;"


推荐阅读