您好,登錄后才能下訂單哦!
其中,
角色 | 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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。