lvs-dr+keepalived是linux下的經典負載均衡解決方案,因其配置簡單、效能優越而廣受歡迎,dr是基於二層mac位址的**,real server收到請求後直接響應客戶機,所以這種架構的效率很高,不過要求lvs server和real server在同乙個物理網段內,就是在同乙個交換機下,架構圖如下:
keepalived是保證乙個lvs server失效以後啟用備份lvs server的,我給我的配置方案如下:
lvs server1 10.20.3.74
lvs server2 10.20.3.76
realserver1 10.20.3.93
realserver2 10.20.3.94
virtual ip 10.20.3.78
一、lvs server配置
安裝keepalived和ipvsadm 1.24
#ln -s /usr/src/kernels/2.6.18-53.el5pae-i686/ /usr/src/linux 這一步很重要,要不然會編譯報錯
#tar zxvf keepalived-1.2.2.tar.gz
#cd keepalived-1.2.2
#./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/
#tar zxvf ipvsadm1.24.tar.gz
#cd ipvsadm1.24
#./configure && make && make install
安裝keepalived 時,configure完成是這樣的
keepalived configuration
------------------------
keepalived version : 1.2.2
compiler : gcc
compiler flags : -g -o2 -dethertype_ipv6=0x86dd
extra lib : -lpopt -lssl -lcrypto
use ipvs framework : yes
ipvs sync daemon support : yes
ipvs use libnl : no
use vrrp framework : yes
use debug flags : no
如果要用到lvs的話,use ipvs framework必須是yes的
/usr/include/stdint.h:41: error: conflicting types for 『int64_t』
編譯keepalived-1.2.2,執行make時出現錯誤。這個錯誤出現的原因可能是標頭檔案linux/types.h和sys/types.h的int64_t、u_int64_t定義有衝突,標頭檔案linux/types.h在定義int64_t等時沒有防止重複定義,而sys/types.h標頭檔案在定義int64_t等時是有防止重複定義的措施的。將sys/types.h(其中包含了linux/types.h)放到所有標頭檔案的前面,問題解決
! configuration file for keepalived
global_defs
# notification_email_from localhost@lvs-server1
# smtp_server 127.0.0.1
# smtp_connect_timeout 30
router_id lvs_devel
}vrrp_instance vi_1
virtual_ipaddress
}virtual_server 10.20.3.78 80
}real_server 10.20.3.94 80 }}
啟動keepalived,#service keepalived start
以上輸出表示配置成功
#ping 10.20.3.78
ping 10.20.3.78 (10.20.3.78) 56(84) bytes of data.
64 bytes from 10.20.3.78: icmp_seq=1 ttl=64 time=0.043 ms
64 bytes from 10.20.3.78: icmp_seq=2 ttl=64 time=0.042 ms
通了,表示位址正常
二、real server配置
real server增加乙個啟動指令碼即可,不需要安裝任何軟體,我的如下
/usr/sbin/realserver.sh
vip=10.20.3.78
sh /etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig lo:0 $vip netmask 255.255.255.255 broadcast $vip up
/sbin/route add -host $vip dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
echo "realserver start ok"
;;stop)
route del $vip >/dev/null 2>&1
ifconfig lo:0 down
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "realserver stoped"
;;*)
echo "usage: $0 "
exit 1
esac
exit 0
放到/usr/sbin下賦予執行許可權,在/etc/rc.local增加一行隨機啟動sh /etc/sbin/realserver.sh
ifconfig可以看到多了乙個介面
lo:0 link encap:local loopback
inet addr:10.20.3.78 mask:255.255.255.255
up loopback running mtu:16436 metric:1
三、驗證
訪問10.20.3.78,如果能轉到10.20.3.93/94的內容,即表示配置成功
群集 LVS DR keepalived實戰部署
二 如何部署keepalievd 三 部署lvs dr keepalived 專為lvs和ha設計的一款健康檢查工具 keepalived採用vrrp熱備份協議實現linux伺服器的多機熱備功能 vrrp,虛擬路由冗餘協議,是針對路由器的一種備份解決方案 在lvs群集環境中應用時,也需用到 lipv...
php phpStorm xdebug配置方法
2.配置php.ini,在末尾加上。xdebug zend extension php xdebug 2.3.3 5.6 vc11.dll xdebug.remote enable on xdebug.remote handler dbgp xdebug.remote host localhost ...
ha 配置ssl haproxy ssl 配置方式
haproxy ssl 有兩種方式 1 haproxy 本身提供ssl 證書,後面的web 伺服器走正常的http 2 haproxy 本身只提供 後面的web伺服器https 第一種方式 需要編譯haproxy 支援ssl,編譯引數 make target linux26 use openssl ...