环境:centos7u4
1.vim /etc/hosts
192.168.32.131 master
192.168.32.129 slave
域名解析
[root@master ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.32.131 master
192.168.32.129 slave
2. 所有机器都作以下操做:
修改主机名称
分别为:master和slave
hostnamectl set-hostename master
3. ssh公钥:
ssh-keygen
cd ~
ls -a
ssh-copy-id -i root@192.168.32.131
4.关闭selinux和防火墙
[root@master ~]# setenforce 0 && systemctl stop firewalld
5. 确保时间一致
主机之间的连同性
6.下载并安装Mysql5.7(所有机器都做)
#lftp 10.18.41.251
> cd 1802
> mirror mysql57
# cd mysql57
# rpm -ivh *.rpm
启动mysql:(所有机器都做)
# systemctl start mysqld
7.修改密码
去掉简单密码限制功能:
#vim /etc/my.cnf //追加如下选项
[mysqld]
validate_password=off
重启服务 systemctl restart mysqld
[root@master ~]#grep password /var/log/mysqld.log
[root@master ~]#mysqladmin -uroot -p'查询的密码' password 'root'
MS流程 GTID:
一、master:192.168.32.131
1.[root@master ~]#vim /etc/my.cnf
log-bin
server-id=1
gtid_mode=ON
enforce_gtid_consistency=1
2.mysql -uroot -proot -e 'grant replication slave,replication client on *.* to 'slave'@'%' identified by 'root''
mysql -uroot -proot -e 'flush privileges;'
mysql -u slave -proot -h master
3.重启master数据库
systemctl restart mysqld
二、slave:192.168.32.129
1.vim /etc/my.cnf
log-bin
server-id=2
gtid_mode=ON
enforce_gtid_consistency=1
2.systemctl restart mysqld
3.进入数据库
mysql -u root -proot
mysql > change master to
master_host='master1',
master_user='授权用户=slave',
master_password='授权密码=root',
master_auto_position=1;
4.start slave;
5.show slave status\G
测试:
1.只要slave状态中i/o进程和sql进程为YES,基本可以确定成功
2.主服务器上写入数据,在从服务器上查看,如果能在从上看到数据,则成功!
网友评论