MySQL+KeepAlived+LVS主主同步

MySQL

MySQL+KeepAlived+LVS 单点写入主主同步高可用架构作为目前比较流行、实用的解决方案,lvs主要提供负载均衡,keepalived作为故障转移,提高系统的可用性。但是一般的mysql高可用为了实现mysql数据的一致性,会使用MySQL自带的主从复制。下面讲解下本方案的具体实现思路。

(1) MySQL主主同步配置
(2) LVS 安装
ipvsadm配置过程中链接文件下无内核—解决办法
[root@LVS ~]# yum -y install kernel-devel

在master1 master2:
[root@LVS ~]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
[root@LVS ~]# ln -s /usr/src/kernels/2.6.18-308.el5xen-i686/ /usr/src/linux
[root@LVS ~]# tar -zxv -f ipvsadm-1.24.tar.gz
[root@LVS ~]# cd ipvsadm-1.24
[root@LVS ~]# make
[root@LVS ~]# make install

(3) KeepAlived安装
在master1 master2:
keepalived出现configure: error: Popt libraries is required
解决方法:
[root@LVS ~]# yum install popt-devel
安装好popt的开发包。

重新./configure 即可。
[root@LVS ~]# wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
[root@LVS ~]# tar -zxv -f keepalived-1.1.19.tar.gz
[root@LVS ~]# cd keepalived-1.1.19
[root@LVS ~]# ./configure –prefix=/usr/local/keepalived
[root@LVS ~]# make
[root@LVS ~]# make install
[root@LVS ~]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@LVS ~]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@LVS ~]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@LVS ~]# mkdir /etc/keepalived

(4)KeepAlived配置
在 master1
global_defs {
notification_email {
linwaterbin@gmail.com
}
notification_email_from bychjzh@gmail.com
smtp_server smtp.gmail.com
smtp_connect_timeout 30
router_id LVS1
}

vrrp_sync_group test {
group {
loadbalance
}
}

vrrp_instance loadbalance {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 150
advert_int 1

authentication {
auth_type PASS
auth_pass 1111
}

virtual_ipaddress {
192.168.1.128 dev eth0 label eth0:1
}
}

virtual_server 192.168.1.128 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 20
protocol TCP
sorry_server 192.168.1.115 3306
real_server 192.168.1.116 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}

在 master2:
大部分都和 master1 一样、只有 2 处:
● state BACKUP
● priority 150

(5) realsever 配置
在master1 master2:
#!/bin/bash
# description: Config realserver lo and apply noarp

SNS_VIP=192.168.1.128
/etc/rc.d/init.d/functions
case “$1” in

start)
ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_VIP dev lo:0
echo “1” >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo “2” >/proc/sys/net/ipv4/conf/lo/arp_announce
echo “1” >/proc/sys/net/ipv4/conf/all/arp_ignore
echo “2” >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
echo “RealServer Start OK”
;;

stop)
ifconfig lo:0 down
route del $SNS_VIP >/dev/null 2>&1
echo “0” >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo “0” >/proc/sys/net/ipv4/conf/lo/arp_announce
echo “0” >/proc/sys/net/ipv4/conf/all/arp_ignore
echo “0” >/proc/sys/net/ipv4/conf/all/arp_announce
echo “RealServer Stoped”
;;

*)

echo “Usage: $0 {start|stop}”
exit 1
esac
exit 0

(6) 启动 KeepAlived和 realsever
在master1 master2:
[root@LVS ~]# /etc/rc.d/init.d/realserver.sh start
[root@LVS ~]# /etc/rc.d/init.d/keepalived start
[root@LVS ~]# echo “/etc/rc.d/init.d/realserver.sh start” >> /etc/rc.local
[root@LVS ~]# echo “/etc/rc.d/init.d/keepalived start” >> /etc/rc.local

配置到这边大概都已经差不多了。

来源:MySQL+KeepAlived+LVS主主同步

MySQL+KeepAlived+LVS主主同步” 评论

    2ou 评论:
    2019年5月10日 下午2:59

    先回复,再欣赏。

发表评论

电子邮件地址不会被公开。 必填项已用*标注