码迷,mamicode.com
首页 > 数据库 > 详细

MySQL高可用之双主复制模式

时间:2018-11-05 19:18:19      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:var   实现   wait   root   图片   半同步   emctl   bubuko   name   

MySQL双主模式高可用实现

技术分享图片

 

生产案例:
VIP:10.105.98.211
MASTER
HOSTNAME IPADDR PORT
my-prod01.oracle.com 192.168.10.97 3306
my-prod02.oracle.com 192.168.10.5 3306
SLAVE
HOSTNAME IPADDR PORT
my-em01.oracle.com 10.100.10.10.65 3306

两个主库之间复制模式:半同步复制 主库从库之间复制模式:异步复制

keepalived配置:
[root@my-prod01]# cat /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

router_id MySQL-MDS-HA
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
smtp_alert
virtual_router_id 46
priority 100
advert_int 1
# preempt
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip 192.168.10.97
unicast_peer {
192.168.10.5
}
virtual_ipaddress {
10.105.98.211/16 #VIP
}
}

virtual_server 10.105.98.211 3306 {
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.97 3306 {
weight 3
notify_down "/etc/keepalived/shutdown_keepalived.sh"
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}

[root@my-prod02 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {

router_id MySQL-MDS-HA
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
smtp_alert
virtual_router_id 46
priority 80
advert_int 1
# preempt
unicast_src_ip 192.168.10.5
unicast_peer {
192.168.10.97
}
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.105.98.211/16 #VIP
}
}

virtual_server 10.105.98.211 3306 {
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.5 3306 {
weight 3
notify_down "/etc/keepalived/shutdown_keepalived.sh"
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}

[root@my-prod02 ~]#cat /etc/keepalived/shutdown_keepalived.sh
systemctl stop keepalived
半同步超时时间1秒
root@(none) 05:55:09>show variables like ‘%semi%‘;
+------------------------------------+-------+
| Variable_name | Value |
+------------------------------------+-------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 1000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | 32 |
+------------------------------------+-------+
6 rows in set (0.00 sec)

root@(none) 05:55:16> show global status like ‘%semi%‘;
+--------------------------------------------+-------------+
| Variable_name | Value |
+--------------------------------------------+-------------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 1309 |
| Rpl_semi_sync_master_net_wait_time | 99361626284 |
| Rpl_semi_sync_master_net_waits | 75893320 |
| Rpl_semi_sync_master_no_times | 6 |
| Rpl_semi_sync_master_no_tx | 620 |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 1420 |
| Rpl_semi_sync_master_tx_wait_time | 86802817655 |
| Rpl_semi_sync_master_tx_waits | 61111551 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 237 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 61234280 |
| Rpl_semi_sync_slave_status | ON |
+--------------------------------------------+-------------+
15 rows in set (0.00 sec)

 

优缺点:
双主模式之双主异步复制模式
存在的风险:
假定主库1的keepalived优先级高,在主库1自增字段到120,但是因为延迟,主库2只同步到100,这时候主库1挂了,vip漂移到主库2上,
因为主库2的自增字段只到了100,所以id可以从101-120被使用,此时主库1重新启动之后,主库1上101-120的数据就因为id冲突,
不能同步到主库2。
1:keepalived 配置state BACKUP模式,避免角色竞争;配置优先级priority

2:该模式需要配置auto_increment_increment auto_increment_offset
auto_increment_offset表示自增长字段从哪个数开始,取值范围是1 .. 65535
auto_increment_increment表示自增长字段每次递增的量,其默认值是1,取值范围是1 .. 65535
在主主同步配置时,需要将两台服务器的auto_increment_increment增长量都配置为2,而要把auto_increment_offset分别配置为1和2.

这样才可以避免两台服务器同时做更新时自增长字段的值之间发生冲突。
https://m.aliyun.com/jiaocheng/1121889.html
双主模式之双主半同步复制模式
存在的风险:

 

MySQL高可用之双主复制模式

标签:var   实现   wait   root   图片   半同步   emctl   bubuko   name   

原文地址:https://www.cnblogs.com/elontian/p/9910466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!