Chinaunix首页 | 论坛 | 博客
  • 博客访问: 461148
  • 博文数量: 237
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-12 14:40
个人简介

  每个人生的当口,都是会有一个孤独的时刻,四顾无人,只有自己,于是不得不看明白自己的脆弱,自己的欲望,自己的念想,自己的界限,还有,自己真正的梦想。

文章分类

全部博文(237)

文章存档

2017年(3)

2016年(234)

分类: 系统运维

2016-05-11 11:03:07

原文地址:LVS + Keepalived之tun模式 作者:chinaboywg

一、仅lvs服务器端安装
yum install ipvsadm openssl-devel popt popt-devel libnl-devel 
cd /opt/src/
tar xzvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure
make && make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
  
修改/etc/keepalived/keepalived.conf文件
[root@WEB ~]# cat /etc/keepalived/keepalived.conf  
! Configuration File for keepalived
  
global_defs {
   notification_email {
     
     123@123.com
   }
   notification_email_from test@foxmail.com 
   smtp_server smtp.foxmail.com 
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
  
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       192.168.1.88 
    }
}
virtual_server 192.168.1.88 80 {
    delay_loop 6
    lb_algo lc
    #lb_kind DR
    lb_kind TUN
    persistence_timeout 60
    protocol TCP
     
    real_server 192.168.2.18 80 {
        weight 3            
        TCP_CHECK {
        connect_timeout 30   
        nb_get_retry 3
        delay_before_retry 2
        connect_port 80
        }
    }
    real_server 192.168.3.68 80 {
        weight 3
        TCP_CHECK {
        connect_timeout 30
        nb_get_retry 3
        delay_before_retry 2
        connect_port 80
        }
     }
 }
[root@WEB ~]# 
[root@WEB ~]# service ipvsadm start
[root@WEB ~]# service keepalived start
  
注意:
打开转发或关闭,dr/tun模式无影响
echo "1" > /proc/sys/net/ipv4/ip_forward
  
二、实际服务器端的操作
  
[root@]# cat /usr/local/vip_tun.sh 
#!/bin/bash
#srcipt to start LVS TUN realserver
  
VIP=192.168.1.88
case "$1" in
  
start)
#start LVS-TUN real server on this machine
/sbin/ifconfig tunl0 down
/sbin/ifconfig tunl0 up
echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
echo 1 > /proc/sys/net/ipv4/conf/tunl0/forwarding
  
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255  up
/sbin/route add -host $VIP dev tunl0
  
;;
stop)
#stop lvs-TUN real server loopback device
/sbin/ifconfig tunl0 down
  
/sbin/ifconfig tunl0 down
echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
;;
status)
islothere='/sbin/ifconfig tunl0 |grep $VIP'
isrothere='netstat -rn |grep "tunl0"|grep $VIP'
if [ ! "$islothere" -o ! "$isrothere" ];then
echo "LVS-TUN real server stopped"
else echo "LVS-TUN Running"
fi
;;
*)
echo "$0: Usage: $0 {start|stop|status}"
exit 1
;;
esac
[root@localhost ~]#  /usr/local/vip.sh start|stop|status
   
  
三、lvs查看 
  
ipvsadm -ln
ipvsadm -lnc
ipvsadm -l -n --stats
  
调度算法:rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq
阅读(1343) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~