主主复制
主服务器一配置
vim /etc/my.cnf
[mysqld]
server-id=1
log-bin=/data/logbin/mysql-bin
auto_increment_offset=1
auto_increment_increment=2
systemctl start mariadb
mysqldump -A --single-transaction --master-data=1 > /data/all.sql
scp /data/all.sql 192.168.160.129:/data/
主服务器二配置
vim /etc/my.cnf
[mysqld]
server-id=2
log-bin=/data/logbin/mysql-bin
auto_increment_offset=2
auto_increment_increment=2
systemctl start mariadb
vim /data/all.sql
CHANGE MASTER TO
MASTER_HOST='192.168.160.136',
MASTER_USER='repluser',
MASTER_PASSWORD='centos',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=245;
mysql </data/all.sql
start slave;
flush privileges;
半同步
主服务器配置
vim /etc/my.cnf
[mysqld]
server-id=1
log-bin=/data/logbin/mysql-bin
systemctl start mariadb
mysql
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
SHOW GLOBAL VARIABLES LIKE '%semi%';
SET GLOBAL rpl_semi_sync_master_enabled=1;
从服务器一
vim /etc/my.cnf
[mysqld]
server-id=2
read-only
systemctl start mariadb
CHANGE MASTER TO
MASTER_HOST='192.168.160.136',
MASTER_USER='repluser',
MASTER_PASSWORD='centos',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=245;
start slave;
INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
SET GLOBAL rpl_semi_sync_slave_enabled=1;
stop slave;
start slave;
从服务器二
vim /etc/my.cnf
[mysqld]
server-id=2
read-only
systemctl start mariadb
CHANGE MASTER TO
MASTER_HOST='192.168.160.136',
MASTER_USER='repluser',
MASTER_PASSWORD='centos',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=245;
start slave;
INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
SET GLOBAL rpl_semi_sync_slave_enabled=1;
stop slave;
start slave;