Keepalived+LVS Centos系统下安装

Keepalived+LVS


部署Keepalived

yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel libnfnetlink-devel ipvsadm
wget http://www.keepalived.org/software/keepalived-2.0.0.tar.gz

tar xf keepalived-2.0.0.tar.gz

cd keepalived-2.0.0

./configure --prefix=/usr/local/keepalived-2.0.0

make && make install

mkdir /etc/keepalived

ln -s /usr/local/keepalived-2.0.0 /usr/local/keepalived

cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

cp /root/keepalived-2.0.0/keepalived/etc/init.d/keepalived /etc/init.d/keepalived

cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

systemctl enable keepalived

systemctl start keepalived

配置Keepalived

cat /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

root@localhost

}

notification_email_from root@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 10

router_id LVS_Master

}

vrrp_instance VIP_1 {

state MASTER

interface eth1

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

10.53.20.240/32 dev eth1 label eth1:0

}

}

#######################################

virtual_server 10.53.20.240 3306 {

delay_loop 6

lb_algo rr

lb_kind DR

persistence_timeout 0

protocol TCP

real_server 10.53.20.145 3306 {

TCP_CHECK {

retry 3

connect_timeout 3

delay_before_retry 3

}

}

real_server 10.53.20.146 3306 {

TCP_CHECK {

retry 3

connect_timeout 3

delay_before_retry 3

}

}

}

#############################################

virtual_server 10.53.20.240 8066 {

delay_loop 6

lb_algo rr

lb_kind DR

persistence_timeout 0

protocol TCP

real_server 10.53.20.145 8066 {

TCP_CHECK {

retry 3

connect_timeout 3

delay_before_retry 3

}

}

real_server 10.53.20.146 8066 {

TCP_CHECK {

retry 3

connect_timeout 3

delay_before_retry 3

}

}

}

##########################################

virtual_server 10.53.20.240 9066 {

delay_loop 6

lb_algo rr

lb_kind DR

persistence_timeout 0

protocol TCP

real_server 10.53.20.145 9066 {

TCP_CHECK {

retry 3

connect_timeout 3

delay_before_retry 3

}

}

real_server 10.53.20.146 9066 {

TCP_CHECK {

retry 3

connect_timeout 3

delay_before_retry 3

}

}

}

开机启动

systemctl start keepalived.service

systemctl enable keepalived.service





配置Real-Server

#!/usr/bin/env bash

#Author: Robin

#Email: xxxxxx@gmail.com

#Description: This script is for lvs VIP

Time=$(date +%F\ %H:%M:%S)

Script_Dir=$(readlink -f $0)

num=0

vip_list="

10.53.208.240

"

case $1 in

start)

echo -e "\033[32m${Time}: Start Real Server VIP......\033[0m"

echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

for vip in $vip_list

do

echo "${Time}: Real Server VIP was $vip added"

/sbin/ifconfig lo:$num $vip netmask 255.255.255.255 broadcast $vip up

let num=$num+1

done

;;

stop)

echo -e "\033[32m${Time}: Stop Real Server VIP......\033[0m"

for vip in $vip_list

do

echo "${Time}: Real Server VIP was $vip deleted"

/sbin/ifconfig lo:$num down

let num=$num+1

done

echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

;;

restart)

$Script_Dir stop && sleep 1 && $Script_Dir start

;;

*)

echo -e "\033[31mUsage: Pls use sh real-server-vip.sh start|stop|restart\033[0m"

exit 1

esac

开机启动

chmod +x /etc/init.d/lvs-realserver-vip.sh

/etc/init.d/lvs-realserver-vip.sh start

echo "/etc/init.d/lvs-realserver-vip.sh start" >> /etc/rc.d/rc.local

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容