您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
其中,
角色 | Hosts | IP地址 | 应用属性 | VIP |
---|---|---|---|---|
master1 | master | 192.168.142.135 | write | 192.168.142.188 |
master2 | backup | 192.168.142.132 | write|read | 192.168.142.188 |
slave1 | slave | 192.168.142.136 | read | 192.168.142.200, 192.168.142.210 |
slave2 | slave | 192.168.142.137 | read | 192.168.142.200, 192.168.142.210 |
monitor | monitor | 192.168.142.143 | moitor | 无VIP |
配置ALI云源(若已安装可跳过)
这里以master1作示范,实际五台均需要安装
[root@master1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@master1 ~]# yum -y install epel-release
[root@master1 ~]# yum clean all && yum makecache
[root@master1 ~]# yum install mysql -y
[root@master1 ~]# vim /etc/my.cnf #修改配置文件
##server id不能一样
server-id =
log-bin = zhu-bin
log-slave-updates = ture ##开启主从同步
sync_binlog = 1 ##二进制文件立即写入
auto_increment_increment=2 ###增量为2
auto_increment_offset=1 ###### 起始值为1
[root@master1 ~]# systemctl restart mysqld
[root@master1 ~]# systemctl enable mysqld
m1给m2从权限,m2给m1从权限
[root@master1 ~]# mysql -u root -p
grant replication slave on *.* to 'myslave'@'192.168.142.%' identified by 'asd123';
#允许从服务器使用myslave账户在主服务器上进行复制操作(两台主均要授权)
show master status;
+------------------+----------+--------------+--------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000001 | 245 | | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
#查看作为主服务器的信息,关键点为position号码
change master to master_host='主服务器地址',master_user='myslave',master_password='asd123',master_log_file='File',master_log_pos=position号码;
##授予权限(m1为m2的主,m2为m1的主)
start slave;
show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
#查看作为从服务器的信息,是否同步开启
配置两台从服务器指向master1
[root@slave1 ~]# vim /etc/my.cnf
server-id = 6 #不能有相同的
log-bin=mysql-bin
log-slave-updates=ture
sync_binlog = 1
[root@slave1 ~]# systemctl restart mysqld
[root@slave1 ~]# netstat -atnp | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 38831/mysqld
#提权,指向master1(两台从操作相同!!!!!)
[root@slave1 ~]# mysql -uroot -p
change master to master_host='主服务器地址',master_user='myslave',master_password='asd123',master_log_file='主服务器查看到的信息',master_log_pos=号码;
##授予权限(slave1、slave2为master1的从)
start slave;
show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
#查看作为从服务器的信息,是否同步开启
修改mmm_common配置文件
[root@master1 ~]# yum -y install mysql-mmm*
#修改MMM配置文件
[root@master1 ~]# vim /etc/mysql-mmm/mmm_common.conf
cluster_interface ens33
......
replication_user myslave #从服务器访问主服务器账户
replication_password asd123
agent_user mmm_user #MMM用户账户
agent_password 123123
<host db1>
ip 192.168.142.135 #master1的IP地址
mode master
peer db2
</host>
<host db2>
ip 192.168.142.132 #master2的IP地址
mode master
peer db1
</host>
<host db3>
ip 192.168.142.136 #slave1的IP地址
mode slave
</host>
<host db4>
ip 192.168.142.137 #slave2的IP地址
mode slave
</host>
<role writer>
hosts db1, db2
ips 192.168.142.188 ###VIP虚拟IP地址
mode exclusive
</role>
<role reader>
hosts db3, db4
ips 192.168.142.200, 192.168.142.210 ###VIP虚拟IP地址
mode balanced
</role>
#scp远程复制,将配置远程推送
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf root@192.168.142.132:/etc/mysql-mmm/
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf root@192.168.142.136:/etc/mysql-mmm/
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf root@192.168.142.137:/etc/mysql-mmm/
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf root@192.168.142.143:/etc/mysql-mmm/
修改mmm_monitor配置文件(仅monitor监听端)
[root@localhost ~]# vim /etc/mysql-mmm/mmm_mon.conf
<monitor>
......
ping_ips 192.168.142.135,192.168.142.132,192.168.142.136,192.168.142.137 #所有主从服务器IP地址
auto_set_online 5
#等待上线时间
<host default>
monitor_user mmm_monitor ##创建监控用户
monitor_password 123123
</host>
在所有主从数据库中(MMM用户、监控用户)进行提权
[root@master1 ~]# mysql -u root -p
grant super,replication client,process on *.* to 'mmm_user'@'192.168.142.%' identified by '123123';
grant replication client on *.* to 'mmm_monitor'@'192.168.142.%' identified by '123123';
flush privileges
##每台主从都要提权
修改agant配置文件(每台主从都要修改)
位置:/etc/mysql-mmm/mmm_agent.conf
[root@master1 ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db1(对应的角色)
所有主从服务器开启mmm_agant服务
[root@master1 ~]# systemctl start mysql-mmm-agent.service
[root@master1 ~]# systemctl enable mysql-mmm-agent.service
监控端开启mmm_monitor服务
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl start mysql-mmm-monitor.service
[root@localhost ~]# mmm_control show ##查看监控状态
[root@localhost mysql-mmm]# mmm_control show
db1(192.168.142.135) master/ONLINE. Roles: writer(192.168.18.250)
db2(192.168.142.132) master/ONLINE. Roles:
db3(192.168.142.136) slave/ONLINE. Roles: reader(192.168.18.251)
db4(192.168.142.137) slave/ONLINE. Roles: reader(192.168.18.252)
//利用命令调整虚拟IP切换至master2:
[root@localhost mysql-mmm]# mmm_control move_role writer db2
OK: Role 'writer' has been moved from 'db1' to 'db2'. Now you can wait some time and check new roles info!
[root@localhost mysql-mmm]# mmm_control show
db1(192.168.142.135) master/ONLINE. Roles:
db2(192.168.142.132) master/ONLINE. Roles: writer(192.168.18.250)
db3(192.168.142.136) slave/ONLINE. Roles: reader(192.168.18.251)
db4(192.168.142.137) slave/ONLINE. Roles: reader(192.168.18.252)
//检测所有状态是否都正常:
[root@localhost mysql-mmm]# mmm_control checks all
db4 ping [last change: 2019/11/25 15:25:54] OK
db4 mysql [last change: 2019/11/25 15:25:54] OK
db4 rep_threads [last change: 2019/11/25 15:25:54] OK
db4 rep_backlog [last change: 2019/11/25 15:25:54] OK: Backlog is null
db2 ping [last change: 2019/11/25 15:25:54] OK
db2 mysql [last change: 2019/11/25 15:25:54] OK
db2 rep_threads [last change: 2019/11/25 15:25:54] OK
db2 rep_backlog [last change: 2019/11/25 15:25:54] OK: Backlog is null
db3 ping [last change: 2019/11/25 15:25:54] OK
db3 mysql [last change: 2019/11/25 15:25:54] OK
db3 rep_threads [last change: 2019/11/25 15:25:54] OK
db3 rep_backlog [last change: 2019/11/25 15:25:54] OK: Backlog is null
db1 ping [last change: 2019/11/25 15:25:54] OK
db1 mysql [last change: 2019/11/25 15:25:54] OK
db1 rep_threads [last change: 2019/11/25 15:25:54] OK
db1 rep_backlog [last change: 2019/11/25 15:25:54] OK: Backlog is null
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。