淺談LVS NET架構的簡單配置和應用(二)

淺談LVS的NET架構的簡單配置和應用(二)nginx

繼續第一篇的案例,此次咱們使用keepalived 來實現並解決第一篇案例的缺陷。
網上講keepalived一般都配不少東西,其實作個簡單方案配置文件只須要幾行就能夠了。vim

LVS1:架構

#tar xvf keepalived-1.1.20.tar.gz -C /usr/src/
#cd /usr/src/keepalived
./configure && make && make installide

#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/
#service keepalived start|stopoop


#vim /etc/keepalived/keepalived.conf
------------------------------------------

virtual_server 192.168.68.47 80 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    nat_mask 255.255.255.0rest

    protocol TCPserver

 real_server 10.1.1.2 80 {
        weight 1
        TCP_CHECK {
           connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80ip

        }
    }
        real_server 10.1.1.3 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
}get

—————————————————————————it

從新啓動keepalived
#service keepalived restart

運行
[root@lvs1 keepalived-1.1.20]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.68.47:http rr
  -> nginx2.dog.com:http          Masq    1      0          0
  -> nginx1.dog.com:http          Masq    1      0          0
 

能夠看到,效果和第一篇同樣的,keepalived 只是幫咱們調用ipvsadm而已。 並且當nginx1掛了,LVS將會自動切換,不會對nginx1進行調度,當nginx1恢復正常keepalived也會自動添加到ipvsadm裏。 下一章再講一下LVS的高可用。

相關文章
相關標籤/搜索