歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習Linux

LVS+keepalived 實戰,lvskeepalived實戰

LVS+keepalived 實戰,lvskeepalived實戰

LVS+keepalived 實戰,lvskeepalived實戰


一、分別在backup lvs和master lvs上安裝LVS

wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
uname -r ln -s /usr/src/kernels/2.6.18-164.el5-i686/ /usr/src/linux tar zxvf ipvsadm-1.24.tar.gz cd ipvsadm-1.24 make && make install

二、分別在backup lvs和master 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

三、修改keepalived相關配置

vi /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -f /usr/local/keepalived/etc/keepalived/keepalived.conf"
vi /etc/init.d/keepalived
#更新
. /etc/sysconfig/keepalived
PATH="$PATH:/usr/sbin"
export PATH
vi /usr/local/keepalived/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server localhost
   smtp_connect_timeout 30
   router_id NodeA
}
vrrp_instance VI_1 {
    state MASTER
    interface ens160
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
         192.168.20.229 //虛擬IP
    }
}
virtual_server 192.168.20.229 80 {    //定義虛擬服務器
    delay_loop 6                  //健康檢查時間,單位是秒
    lb_algo rr              //負載調度算法,這裡設置為rr,即輪詢算法
    lb_kind DR              //LVS實現負載均衡的機制,可以有NAT、TUN和DR三個模式可選
    persistence_timeout 1        //會話保持時間,單位是秒(可以適當延長時間以保持session)
    protocol TCP                  //轉發協議類型,有tcp和udp兩種
    real_server 192.168.20.200 8151 {  //定義WEB服務器
       weight 1                  //權重
       TCP_CHECK {                //通過tcpcheck判斷RealServer的健康狀態
           connect_timeout 5      //連接超時時間
           nb_get_retry 3        //重連次數
           delay_before_retry 3  //重連間隔時間
           connect_port 8151        //檢測端口
       }
    }
    real_server 192.168.20.201 8151 {  //定義WEB服務器
       weight 2                 //權重
       TCP_CHECK {                //通過tcpcheck判斷RealServer的健康狀態
           connect_timeout 5      //連接超時時間
           nb_get_retry 3        //重連次數
           delay_before_retry 3  //重連間隔時間
           connect_port 8151        //檢測端口
       }
    }
}

虛擬VIP:192.168.20.229 

分流WEB:192.168.20.200、192.168.20.201

四、啟動keepalived 

/etc/init.d/keepalived start

五、測試

ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  docker223:80 rr persistent 1
  -> 192.168.20.200:8151          Route   1      0          0    

浏覽器訪問 http://192.168.20.229 分流 http://192.168.20.200:8151 WEB服務

 

http://xxxxxx/Linuxjc/1188594.html TechArticle

Copyright © Linux教程網 All Rights Reserved