LVS + Keepalived之nat模式

一、仅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 123@123.com
   smtp_server mail.123.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 {
       88.88.88.88 
    }
}
vrrp_instance LAN_GATEWAY {
    state MASTER               
    interface eth1
    virtual_router_id 52
    priority 100      
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.88
    }
}
virtual_server 88.88.88.88 80 {
    delay_loop 6
    lb_algo lc
    #lb_kind DR
    #lb_kind TUN
    lb_kind NAT
    persistence_timeout 60
    protocol TCP
   
    real_server 192.168.1.18 80 {
        weight 3            
        TCP_CHECK {
        connect_timeout 30   
        nb_get_retry 3
        delay_before_retry 2
        connect_port 80
        }
    }
    real_server 192.168.1.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

注意:
echo "1" > /proc/sys/net/ipv4/ip_forward

二、实际服务器端的操作
将网关设置为lanvip的地址192.168.1.88

三、lvs查看

ipvsadm -ln
ipvsadm -lnc
ipvsadm -l -n --stats

调度算法:rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq

One Reply to “LVS + Keepalived之nat模式”

发表评论

电子邮件地址不会被公开。 必填项已用*标注