LVS负载均衡+三台Route Process服务器

lvs+keepalived一台

 

mongos服务器分别为172.16.0.103,172.16.0.114,172.16.0.115

1.4.5 Lvs的安装

lvs+keepalived服务器进行安装:

wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz

ln -s /usr/src/kernels/2.6.18-371.9.1.el5-x86_64/ /usr/src/linux

tar zxvf ipvsadm-1.24.tar.gz

cd ipvsadm-1.24

make&& make install

1.4.6 Keepalived的安装

lvs+keepalived服务器进行安装:

wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
tar zxvf keepalived-1.1.19.tar.gz
cd keepalived-1.1.19

./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived

 

1.4.7.1配置keeplived.conf

lvs-master在172.16.0.114上布置

vim /etc/keepalived/keepalived.conf

 

 

 

global_defs {

notification_email {

               [email protected] 

        }

        notification_email_from [email protected]

        smtp_server 127.0.0.1

        smtp_connect_timeout 30

        router_id LVS1         

}

vrrp_sync_group test {         

group {

        loadbalance

}

}

 

vrrp_instance loadbalance {

        state MASTER     

        interface eth0    

        lvs_sync_daemon_inteface eth0  

        virtual_router_id 51                  

        priority 180            

        advert_int 5        

authentication {                

        auth_type PASS

        auth_pass 1111

}

virtual_ipaddress {            

        172.16.0.222

}

}

 

virtual_server 172.16.0.222 60000 {

        delay_loop 6         

        lb_algo rr            

        lb_kind DR           

        #persistence_timeout 20 

        protocol TCP               

        real_server 172.16.0.114 60000 {

        weight 3               

        TCP_CHECK {

        connect_timeout 3

        nb_get_retry 3

        delay_before_retry 3

        connect_port 60000

}

}

        real_server 172.16.0.103 60000 {

        weight 3

        TCP_CHECK {

        connect_timeout 3

        nb_get_retry 3

        delay_before_retry 3

        connect_port 60000

}

}

        real_server 172.16.0.115 60000 {

        weight 3

        TCP_CHECK {

        connect_timeout 3

        nb_get_retry 3

        delay_before_retry 3

        connect_port 60000

}

}

}

lvs-backup在172.16.0.115上布置

vim /etc/keepalived/keepalived.conf

 

 

 

global_defs {

notification_email {

               [email protected] 

        }

        notification_email_from [email protected]

        smtp_server 127.0.0.1

        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 5        

authentication {                

        auth_type PASS

        auth_pass 1111

}

virtual_ipaddress {            

        172.16.0.222

}

}

 

virtual_server 172.16.0.222 60000 {

        delay_loop 6         

        lb_algo rr            

        lb_kind DR           

        #persistence_timeout 20 

        protocol TCP               

        real_server 172.16.0.114 60000 {

        weight 3               

        TCP_CHECK {

        connect_timeout 3

        nb_get_retry 3

        delay_before_retry 3

        connect_port 60000

}

}

        real_server 172.16.0.103 60000 {

        weight 3

        TCP_CHECK {

        connect_timeout 3

        nb_get_retry 3

        delay_before_retry 3

        connect_port 60000

}

}

        real_server 172.16.0.115 60000 {

        weight 3

        TCP_CHECK {

        connect_timeout 3

        nb_get_retry 3

        delay_before_retry 3

        connect_port 60000

}

}

}

 

三台mongos里增加

vi /etc/init.d/realserver.sh

 

#!/bin/bash

# description: Config realserver lo and apply noarp

 

SNS_VIP=172.16.0.222

 

/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

 

主备启动keepalived:

/etc/rc.d/init.d/keepalived start

三台mongos启动

/etc/init.d/realserver.sh start

并将keepalived和realserver的启动脚本加入到rc.local自启动中:

echo “/etc/rc.d/init.d/keepalived start” >> /etc/rc.local

echo “/etc/init.d/realserver.sh  start” >> /etc/rc.local