lvs+keepalived实现负载均衡,基于centos6.5

1.RS服务器增加虚拟IP
#  SNS_VIP  为要绑定的虚拟IP
vi /et/init.d/realserver #增加以下内容保存  修改权限为750  或755
说明: 以下内容 chkconfig  : 2345  description 这两行必须要有 否则 chkconfig --add 增加到系统服务会失败
以下脚本在centos6.5测试正常.
#!/bin/bash
# chkconfig: 2345 30 70 
# description: Starts and Stops VIP.
        SNS_VIP=192.168.200.201
        . /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


# 执行以下脚本将 realserver 增加到系统服务
chkconfig --add realserver
#设置自启动
chkconfig realserver on


2.RS开启HTTPD
yum install httpd
service httpd start   #默认wwwroot  /var/www/
chkconfig httd on #自启动 


3.负载均衡主机
yum install ipvsadm   #LVS linux虚拟服务的一个控制命令工具
yum install keepalived    #










你可能感兴趣的:(lvs+keepalived实现负载均衡,基于centos6.5)