for i in 4 5 6;do ssh-copy-id root@192.168.100.$i;done
192.168.100.4
ssh-keygen
for i in 3 5 6;do ssh-copy-id root@192.168.100.$i;done
192.168.100.5
ssh-keygen
for i in 4 3 6;do ssh-copy-id root@192.168.100.$i;done
192.168.100.6
ssh-keygen
for i in 4 5 3;do ssh-copy-id root@192.168.100.$i;done
所有节点配置hosts
vim /etc/hosts
for i in 4 5 6 ;do scp/etc/hosts 192.168.100.$i:/etc;done
192.168.100.3 mgt
192.168.100.4 master
192.168.100.5 slave1
192.168.100.6 slave2
测试
for i in 3 4 5;do ssh 192.168.100.$i ;done (在192.168.100.3测试 )
for i in master slave1 slave2;do ssh $i ;done
三、主从复制
master
vim /etc/my.cnf
[mysqld]
server-id = 1
log-bin = master-bin
log-slave-updates = true
ystemctl restart mariadb
mysql -e "grant replication slave on *.* to 'myslave'@'192.168.100.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.3' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.5' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.6' identified by '123.com';"
mysql -e "show master status";
slave1
server-id=2
log-bin=master-bin
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index
mysql -e "grant replication slave on *.* to 'myslave'@'192.168.100.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.3' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.4' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.6' identified by '123.com';"
mysql -e "change master to master_host='192.168.100.4',master_user='myslave',master_password='123.com',master_log_file='master-bin.000003',master_log_pos=1007;"
mysql -e "slave start"
slave2
server-id=3
log-bin=master-bin
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index
mysql -e "grant replication slave on *.* to 'myslave'@'192.168.100.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.3' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.4' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.100.5' identified by '123.com';"
mysql -e "change master to master_host='192.168.100.4',master_user='myslave',master_password='123.com',master_log_file='master-bin.000003',master_log_pos=1007;"