1. 程式人生 > >Nginx(十一)-- keepalived簡介

Nginx(十一)-- keepalived簡介

target 運行 多個 vrrp unzip ilo digest and style

1. 什麽是keepalived

  基於VRRP(虛擬路由器冗余協議)來實現對web服務的高可用方案。

  keepalived下載地址:http://download.csdn.net/detail/u010821757/9892484

2.安裝keepalived服務器

  1.將keepalived-1.3.4.zip解壓到/usr/java目錄

   unzip keepalived-1.3.4.zip

  2.進入到keepalived

   cd keepalived

  3.編譯安裝

   ./conf 按 Tab鍵提示不出來,不能自動補全

  4.發現沒有權限,接下來就要賦權

chmod +x configure

  5.在/usr/java中創建一個文件夾 keepalived

   mkdir keepalived

  6.進入 keepalived-1.3.4文件夾中,然後編譯安裝

   ./configure --prefix=/usr/java/keepalived --sysconf=/etc

   說明:當keepalived啟動的時候,會默認讀取 etc下的keepalived.conf,所以安裝的時候就指向/etc

  7.執行6的時候,可能會出現缺少依賴openssl,解決方法,安裝openssl

yum install openssl-devel

  8.安裝

   make && make install

   技術分享

   出現上圖,表示安裝成功!

  9.設置成系統服務

   1) 進入到源碼包,即 /usr/java/keepalived-1.3.4

   2) 建立軟連接(相當於快捷方式)

   2.1) 把啟動腳本添加到系統/sbin中,ln -s /usr/java/keepalived/sbin/keepalived /sbin

    2.2) 復制源碼路徑中的keepalived復制到/etc/init.d中:cp /usr/java/keepalived-1.3.4/keepalived/etc/init.d/keepalived /etc/init.d/

   3) 添加到系統服務中

   chkconfig --add keepalived

   4) 設置服務啟動

chkconfig keepalived on

   5) 啟動服務

    service keepalived start,出現:

   技術分享

   說明沒有權限,賦權:chmod +x /etc/init.d/keepalived

   重新啟動:service keepalived start

   技術分享

    出現上圖,即啟動成功,我們可以查看進程:ps -ef|grep keepalived

   技術分享

3.keepalived配置文件

  • global_defs 全局配置
  • vrrp_instance VI_1
  • virtual_server lvs配置

 1) global_defs 全局配置

 global_defs {
   notification_email {   # 設置報警的郵件,如果keepalived出現問題,會發郵件到下面的郵箱
     [email protected]   # 每一行代表一個郵箱,可配置多個
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]  # 由哪一個郵箱發送,即發件箱
   smtp_server 192.168.200.1  # 郵件服務地址
   smtp_connect_timeout 30  # 超時時間
   router_id LVS_DEVEL   # 唯一的一個名字,運行keepalived的唯一標識
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
 }

 2) vrrp_instance VI_1

 vrrp_instance VI_1 {
    state MASTER   #當前keepalived的狀態
    interface eth0  # 高可用的檢測端口 和 網卡名稱
    virtual_router_id 51  # 虛擬路由的標識
    priority 100  # 權重,節點優先級
    advert_int 1    # 主備服務器檢查的時間,單位秒
    authentication {  # master和backup的通訊驗證,
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {  # 虛擬IP地址
        192.168.200.16
        192.168.200.17
        192.168.200.18
    }
 }

 3) virtual_server lvs配置

   virtual_server 192.168.200.100 443 { # 虛擬IP對應的真實IP
     delay_loop 6
     lb_algo rr
     lb_kind NAT
     persistence_timeout 50
     protocol TCP
 
    real_server 192.168.201.100 443 {
         weight 1
         SSL_GET {
             url {
              path /
               digest ff20ad2481f97b1754ef3e12ecd3a9cc
             } 
             url {
               path /mrtg/
               digest 9b3a0c85a887a256d6939da88aabd8cd
             } 
             connect_timeout 3
             nb_get_retry 3
             delay_before_retry 3
         }   
     }   
  }   

  

Nginx(十一)-- keepalived簡介