mysql集群(双主)

0、安装

所谓双主基本可以理解为两台服务器互为主备,其核心思路与主备配置相同。

服务器A:
内网IP: 10.44.94.219
服务器B:
内网IP: 10.44.94.97

1、配置服务器A

log-bin=mysql-bin.log 
server-id=219
auto_increment_increment=2 
auto_increment_offset=2
relay_log= mysql-relay-bin.log
log_slave_updates = 1

GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO 'backup'@'10.44.94.97' IDENTIFIED BY 'fredric';

CHANGE MASTER TO MASTER_HOST='10.44.94.97',
MASTER_USER='backup',
MASTER_PORT=3306,
MASTER_PASSWORD='fredric',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=359;

START SLAVE;

2、配置服务器B

log-bin=mysql-bin.log 
server-id=97
auto_increment_increment=2 
auto_increment_offset=1
relay_log= mysql-relay-bin.log
log_slave_updates = 1

GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO 'backup'@'10.44.94.219' IDENTIFIED BY 'fredric';

CHANGE MASTER TO MASTER_HOST='121.40.189.197',
MASTER_USER='backup',
MASTER_PORT=3306,
MASTER_PASSWORD='fredric',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=359;

#备注:其中auto_increment_offset分别设置为偶数和奇数递增,以防止冲突


你可能感兴趣的:(mysql集群(双主))