標籤:linux lvs 伺服器 lvs執行個體 64位
650) this.width=650;" src="http://pub.idqqimg.com/wpa/images/group.png" alt="linux進階營運群" title="linux進階營運群" border="0" /> 更多內容請訪問我的個人網站【迅幫網】
一、伺服器環境
1、拓撲圖
650) this.width=650;" class="aligncenter size-full wp-image-307" alt="lvs_01" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_01.jpg" height="342" width="791" />
OS:Redhat 5.8 64位系統
LVS-Master : 192.168.19.60
LVS-Backup : 192.168.19.61
LVS-VIP : 192.168.19.65
Realserver-1 : 192.168.19.62 (Apache)
Realserver-2 : 192.168.19.63 (Nginx)
Realserver-2 : 192.168.19.64 (IIS)
2、安裝LVS依賴軟體
# yum install -y gcc gcc-c++ make openssl-devel kernel-devel
注:系統採用最少化方法安裝
所有伺服器關閉Selinux
[[email protected]_master ~]# vim /etc/sysconfig/selinux# This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - SELinux is fully disabled.SELINUX=disabled# SELINUXTYPE= type of policy in use. Possible values are:# targeted - Only targeted network daemons are protected.# strict - Full SELinux protection.SELINUXTYPE=targeted
把SELINUX=disabled儲存,然後重啟伺服器即可。
二、安裝ipvsadm
1、建立編譯時間必須的一個軟連結
[[email protected]_master ~]# ln -s /usr/src/kernels/2.6.18-308.el5-x86_64/ /usr/src/linux
(這裡如果找不到以上核心目錄,是因為kernerl-devel沒有裝,先去安裝上就有了)
[[email protected]_master ~]# ll /usr/src/linux
650) this.width=650;" class="aligncenter size-full wp-image-336" alt="lvs_02" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_02.jpg" height="36" width="673" />
2、下載 ipvsadm
[[email protected]_master ~]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
650) this.width=650;" class="aligncenter size-full wp-image-337" alt="lvs_03" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_03.jpg" height="186" width="744" />
3、解壓縮
[[email protected]_master ~]# tar -zxvf ipvsadm-1.24.tar.gz[[email protected]_master ~]# cd ipvsadm-1.24
4、編譯安裝
[[email protected]_master ipvsadm-1.24]# make && make install
5、確認安裝成功
[[email protected]_master ipvsadm-1.24]# whereis ipvsadm
650) this.width=650;" class="aligncenter size-full wp-image-380" alt="lvs_10" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_10.jpg" height="34" width="500" />
[[email protected]_master ipvsadm-1.24]# ipvsadm --version
650) this.width=650;" class="aligncenter size-full wp-image-381" alt="lvs_05" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_05.jpg" height="34" width="500" />
三、安裝keepalived
1、下載keepalived
[[email protected]_master ~]# wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz
650) this.width=650;" class="aligncenter size-full wp-image-338" alt="lvs_04" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_04.jpg" height="185" width="737" />
2、解壓keepalived
[[email protected]_master ~]# tar -zxvf keepalived-1.2.2.tar.gz[[email protected]_master ~]# cd keepalived-1.2.2[[email protected]_master keepalived-1.2.2]# ./configure
650) this.width=650;" class="aligncenter size-full wp-image-350" alt="lvs_09" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_09.jpg" height="400" width="670" />
650) this.width=650;" class="aligncenter size-full wp-image-340" alt="lvs_06" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_06.jpg" height="416" width="670" />
(注意這個步驟要看到以上字樣才是正常的)
3、安裝
[[email protected]_master keepalived-1.2.2]# make && make install
如果報錯,這樣
650) this.width=650;" alt="lvs_15" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_15.jpg" height="358" width="600" />
注意:
把#include linux/types.h /* For __beXX types in userland */
移到#include sys/types.h 這行的下面
再編譯就可以通過了。(這個可能是keepalived版本問題)
[[email protected]_master keepalived-1.2.2]# vim keepalived/libipvs-2.6/ip_vs.h
650) this.width=650;" alt="lvs_07" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_07.jpg" height="343" width="490" />
650) this.width=650;" alt="lvs_8" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_08.jpg" height="343" width="491" />
4. 配置
先看下有沒有檔案
650) this.width=650;" class="aligncenter size-full wp-image-391" alt="lvs_14" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_14.jpg" height="596" width="610" />
[[email protected]_master ~]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/[[email protected]_master ~]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/[[email protected]_master ~]# mkdir /etc/keepalived[[email protected]_master ~]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/[[email protected]_master ~]# cp /usr/local/sbin/keepalived /usr/sbin/[[email protected]_master ~]# chkconfig keepalived on
[[email protected]_master ~]# service keepalived restart
650) this.width=650;" class="aligncenter size-full wp-image-388" alt="lvs_12" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_12.jpg" height="50" width="500" />
查看keepalived進程在不在
650) this.width=650;" class="aligncenter size-full wp-image-389" alt="lvs_13" src="http://xunbang.org/wp-content/uploads/2013/08/lvs_13.jpg" height="83" width="568" />
5、從 keepalived跟主keepalived伺服器同樣的安裝方法,唯一不同的就是keepalived.conf設定檔不同。
四、keepalived.conf設定檔解釋
1、keepalived.conf主設定檔內容
! Configuration File for keepalivedglobal_defs { notification_email { [email protected] #表示發送通知訊息時郵件源地址是誰 } notification_email_from [email protected] smtp_server 127.0.0.1 #表示發送email時使用的smtp伺服器位址,這裡可以用本地的sendmail來實現 # smtp_connect_timeout 30 #串連smtp連線逾時時間 router_id LVS_DEVEL}vrrp_instance VI_1 { state MASTER # 備份LB將MASTER改為BACKUP interface eth0 #執行個體綁定的網卡,因為在配置虛擬IP的時候必須是在已有的網卡上添加的 virtual_router_id 51 #這裡設定VRID,這裡非常重要,相同的VRID為一個組,他將決定多播的MAC地址 priority 100 # 優先順序,備份LB值改為比這個值小 advert_int 1 #檢查間隔,預設為1秒 authentication { #這裡設定認證 auth_type PASS #認證方式,可以是PASS或AH兩種認證方式 auth_pass 1111 #認證密碼 } virtual_ipaddress { 192.168.19.65 # 多個VIP換行寫 }} virtual_server 192.168.19.65 80 { delay_loop 6 #每隔6秒查詢realserver狀態 lb_algo wlc # LVS 演算法 lb_kind DR # LVS模式 DR是直接路由 persistence_timeout 60 #同一IP串連60秒內分配到同一台realserver protocol TCP #TCP協議檢測realserver狀態 real_server 192.168.19.62 80 { weight 3 #權重 TCP_CHECK { connect_timeout 10 #10秒無響應逾時 nb_get_retry 3 #重連次數 delay_before_retry 3 #重連間隔 connect_port 80 #監控檢查的連接埠 } } real_server 192.168.19.63 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.19.64 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } }}
2、keepalived.conf從設定檔內容
! Configuration File for keepalivedglobal_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 127.0.0.1 # smtp_connect_timeout 30 router_id LVS_DEVEL}vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.19.65 }} virtual_server 192.168.19.65 80 { delay_loop 6 lb_algo wlc lb_kind DR persistence_timeout 60 protocol TCP real_server 192.168.19.62 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.19.63 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.19.64 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } }}
到此主從LVS配置完成,下一篇講物理機的配置(也就是real_server)
本文出自 “首席技術官” 部落格,請務必保留此出處http://xunbang.blog.51cto.com/854050/1440899
Redhat5.8 64位LVS執行個體環境講解【一】