資源描述:
《負(fù)載均衡--lvs+keepalived》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、利用LVS+Keepalived實(shí)現(xiàn)高性能高可用負(fù)載均衡作者:NetSeek網(wǎng)站:http://www.linuxtone.org背景:隨著你的網(wǎng)站業(yè)務(wù)量的增長你網(wǎng)站的服務(wù)器壓力越來越大?需要負(fù)載均衡方案!商業(yè)的硬件如F5又太貴,你們又是創(chuàng)業(yè)型互聯(lián)公司如何有效節(jié)約成本,節(jié)省不必要的浪費(fèi)?同時(shí)實(shí)現(xiàn)商業(yè)硬件一樣的高性能高可用的功能?有什么好的負(fù)載均衡可伸張可擴(kuò)展的方案嗎?答案是肯定的!有!我們利用LVS+Keepalived基于完整開源軟件的架構(gòu)可以為你提供一個(gè)負(fù)載均衡及高可用的服務(wù)器。一.LVS+Ke
2、epalived介紹1.LVSLVS是LinuxVirtualServer的簡寫,意即Linux虛擬服務(wù)器,是一個(gè)虛擬的服務(wù)器集群系統(tǒng)。本項(xiàng)目在1998年5月由章文嵩博士成立,是中國國內(nèi)最早出現(xiàn)的自由軟件項(xiàng)目之一。目前有三種IP負(fù)載均衡技術(shù)(VS/NAT、VS/TUN和VS/DR);八種調(diào)度算法(rr,wrr,lc,wlc,lblc,lblcr,dh,sh)。2.KeepalviedKeepalived在這里主要用作RealServer的健康狀態(tài)檢查以及LoadBalance主機(jī)和BackUP主機(jī)之
3、間failover的實(shí)現(xiàn)二.網(wǎng)站負(fù)載均衡拓樸圖.IP信息列表:名稱IPLVS-DR-Master61.164.122.6LVS-DR-BACKUP61.164.122.7LVS-DR-VIP61.164.122.8WEB1-Realserver61.164.122.9WEB2-Realserver61.164.122.10GateWay61.164.122.1三.安裝LVS和Keepalvied軟件包1.下載相關(guān)軟件包#mkdir/usr/local/src/lvs#cd/usr/local/src
4、/lvs#wgethttp://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz#wgethttp://www.keepalived.org/software/keepalived-1.1.15.tar.gz2.安裝LVS和Keepalived#lsmod
5、grepip_vs#uname-r2.6.18-53.el5PAE#ln-s/usr/src/kernels/2.6.18-53.el5PAE-i686//usr
6、/src/linux#tarzxvfipvsadm-1.24.tar.gz#cdipvsadm-1.24#make&&makeinstall#find/-nameipvsadm#查看ipvsadm的位置#tarzxvfkeepalived-1.1.15.tar.gz#cdkeepalived-1.1.15#./configure&&make&&makeinstall#find/-namekeepalived#查看keepalived位置#cp/usr/local/etc/rc.d/init.d/ke
7、epalived/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/#servicekeepalivedstart
8、stop#做成系統(tǒng)啟動(dòng)服務(wù)方便管理.四.配置LVS實(shí)現(xiàn)負(fù)載均
9、衡1.LVS-DR,配置LVS腳本實(shí)現(xiàn)負(fù)載均衡#vi/usr/local/sbin/lvs-dr.sh#!/bin/bash#description:startLVSofDirectorServer#Writtenby:NetSeekhttp://www.linuxtone.orgGW=61.164.122.1#websitedirectorvip.SNS_VIP=61.164.122.8SNS_RIP1=61.164.122.9SNS_RIP2=61.164.122.10./etc/rc.d/in
10、it.d/functionslogger$0calledwith$1case"$1"instart)#setsquidvip/sbin/ipvsadm--set30560/sbin/ifconfigeth0:0$SNS_VIPbroadcast$SNS_VIPnetmask255.255.255.255broadcast$SNS_VIPup/sbin/routeadd-host$SNS_VIPdeveth0:0/sbin/ipvsadm-A-t$SNS_VIP:80-