之前已经配置好了mysql-cluster群集,由于日常sql节点通常都大于1台,这意味着应用程序一部分要使用sql1节点,一部分使用sql2节点,当然,所有的应用程序只需要一个节点,但这样不在群集节点间做分流负载,也就不必做群集了,另外,如果一个群集节点down机了,随之而来的程序也down掉,该如何解决,因此我用keepalived来实现对sql节点的高可用,问题又来了,这里的keepalived存在单机故障,所以准备2台互备,我们用lvs来实现负载均衡,这样其中一个节点或者keepalived坏掉,应用程序将仍然可以工作,因为负载均衡器将请求转到了工作正常的另外一个节点,我们需要一个虚拟IP地址:192.168.18.100。它会安排给这个MySQL群集的负载均衡,以便于应用程序通过统一单独的IP地址来访问群集。
回想一下之前的部署ip结构:
192.168.18.10:MGM/SQL1
192.168.18.11:NDBD1/lvs+keepalived
192.168.18.12:NDBD2/lvs+keepalived
192.168.18.9 : SQL2
VIP:192.168.18.100
1.在11/12这2台设备上安装lvs+keepalived [root@localhost home]yum -y install ipvsadm [root@localhost home]tar -zxfkeepalived-1.2.7.tar.gz [root@localhost home]cdkeepalived-1.2.7 [root@localhost keepalived-1.2.7]#./configure --prefix=/usr/local/keepalived/ [root@localhost keepalived-1.2.7]#make && make install [root@localhost keepalived-1.2.7]#vi/usr/local/keepalived/keepalived.conf ! Configuration File for keepalived global_defs {router_id LVS_DEVEL } vrrp_instance VI_1 {state MASTER #备机上改为BACKUP interface eth1 virtual_router_id 51 priority 100 advert_int 3 authentication {auth_type PASS auth_pass 1111 } virtual_ipaddress {192.168.18.100 } } virtual_server 192.168.18.100 3306 {delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 60 protocol TCP real_server 192.168.18.9 3306 {weight 1 TCP_CHECK {connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 3306 } } real_server 192.168.18.10 3306 {weight 1 TCP_CHECK{connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 3306 } } } 启动keepalived: [root@localhost home]/usr/local/keepalived/sbin/keepalived -D -f /usr/local/keepalived/keepalived.conf 2.在2台sql节点行编辑如下脚本 [root@localhost home]vi re.sh #!/bin/sh VIP=192.168.18.100 /etc/rc.d/init.d/functions case "$1" in start) echo "Start LVS of RealServer" /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up route add -host $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 ;; stop) /sbin/ifconfig lo:0 down echo "Stop LVS of RealServer" 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 "Usage:$0{start|stop}" exit 1 esac [root@localhost home] chmod +x re.sh [root@localhost home]./re.sh start 好了,现在可以直接利用vip,192.168.18.100来连接了