LVS-NAT配置(原創)
LVS,即Linux Virtual Server,是一款由章文嵩博士開發的開源軟件,可以實現Linux 下面的負載均衡。LVS 各個組成部分爲:Director Server,Real Server,shared Storage.
目前我使用的是平臺爲:WIN7 + VMWARE 9.0, DirectorServer,Real Server 均使用虛擬機中的Linux,具體爲CentOS 6.3, 詳細配置如下:
Windows7 :
ip:192.168.2.102
netmask:255.255.255.0
gateway:192.168.2.1
Director Server:
ip:192.168.12.10 (這個ip在內網使用,所以可以不用配置子網掩碼和網關)
vip:192.168.2.111 #虛擬IP
netmask:255.255.255.0
gateway:192.168.2.1
Real Server 1:
ip:192.168.12.3
netmask:255.255.255.0
gateway:192.168.12.10 #注意這裏要指向Director Server
vip:192.168.2.111
Real Server 2:
ip:192.168.12.4
netmask:255.255.255.0
gateway:192.168.12.10 #注意這裏要指向Director Server
vip:192.168.2.111
下面是各服務器配置步驟:
1,配置Director Server(關閉防火牆)
首先這臺服務器工作在NAT 模式,所以需要兩張網卡,我們在虛擬機中可以再增加一個。我們可以把虛擬機中默認的第一個網卡設置爲自定義,選擇vmnet2。第二張網卡(也就是我們剛剛增加的一張網卡)配置爲NAT 模式。
進入CentOS,
#vi /etc/sysctl.conf
修改裏面其中一行net.ipv4.ip_forward = 0 改爲net.ipv4.ip_forward = 1
這樣ip轉發就開啓了。可以通過命令sysctl -p查看。
#cd /etc/sysconfig/network-scripts
#vi ifcfg-Auto_eth1
這裏將IP 設置爲192.168.2.111,子網掩碼爲255.255.255.0,網關爲192.168.2.1
#vi ifcfg-Auto_eth2
這裏將IP設置爲192.168.12.10
#vi /etc/resolv.conf 這裏加上DNS:202.103.24.68,202.103.44.150
#service network restart
因爲我們的物理機Windows7 已經通過有線聯網,這裏我們可以
ping www.163.com
發現Director Server已經可以聯網了。
#yum –y install ipvsadm //安裝ipvsadm
#yum –erase httpd //如果此機安裝有apache,移除該軟件。
查看ipvs 系統內核是否支持
#grep –I ip_vs /boot/config-2.6.32-279.el6.i686
#lsmod |grep ip_vs
2,配置Real Server1
#vi /etc/sysctl.conf
在net.ipv4.ip_forward = 0後面再增加兩行:
net.ipv4.conf.all.hidden= 1
net.ipv4.conf.lo.hidden= 1
增加虛擬IP:
#cd /etc/sysconfig/network-scripts
#cp ifcfg-lo ifcfg-lo:0
#vi ifcgf-lo:0
按照以下來修改:
DEVICE=lo:0
IPADDR=192.168.2.111
NETMASK=255.255.255.255
ONBOOT=YES
…
#vi /etc/sysconfig/networscripts/ifg-eth0
設置IP爲:192.168.12.3 netmask:255.255.255.0gateway:192.168.12.10
#yum –y install httpd //安裝apache web服務器
#vi /var/www/html/index.html //建立web首頁
寫入:This is Server 1
#service httpd restart //重啓下web
查看網頁是否正常打開:#firefox:http://localhost/
配置Real Server2
#vi /etc/sysctl.conf
在net.ipv4.ip_forward = 0後面再增加兩行:
net.ipv4.conf.all.hidden= 1
net.ipv4.conf.lo.hidden= 1
增加虛擬IP:
#cd /etc/sysconfig/network-scripts
# cp ifcfg-lo ifcfg-lo:0
#vi ifcgf-lo:0
按照以下來修改:
DEVICE=lo:0
IPADDR=192.168.2.111
NETMASK=255.255.255.255
ONBOOT=YES
…
#vi /etc/sysconfig/networscripts/ifg-eth0
設置IP爲:192.168.12.4 netmask:255.255.255.0gateway:192.168.12.10
#yum –y install httpd //安裝apache web服務器
#vi /var/www/html/index.html //建立web首頁
寫入:This is Server 2
#service httpd restart //重啓下web
查看網頁是否正常打開:# firefox http://localhost/
3,在Director Server 上面配置ipvsadm
先分別
ping 192.168.12.10
ping 192.168.2.111
ping 192.168.12.3
ping 192.168.12.4
發現均能ping通
#ipvsadm –A –t 192.168.2.111 –s rr //rr爲輪詢調度
#ipvsadm –a –t 192.168.2.111 –r 192.168.12.13 –m–w 1
#ipvsadm –a –t 192.168.2.111 –r 192.168.12.14 –m –w 2
#service ipvsadm save //保存ipvsadm
查看ipvsadm :
#ipvsadm –L –n
可以看到已經有RealServer的信息了。
在WIN 7 上打開瀏覽器,訪問:http://192.168.2.111
修改調度算法爲wlc:
#ipvsadm –E –t 192.168.2.111 –s wlc
#service ipvsadm save
在WIN 7 上打開瀏覽器,訪問:http://192.168.2.111
現在刷新第一次爲This is Server 1,刷新第二次第三次均爲This is Server 2 了。
lvs_nat 配置_落英繽紛(原創)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
用VM+PE+GHOST安裝winxp系統
zhoukenny
2019-02-23 13:52:17
nagios學習手札
3543772
2019-02-23 13:51:43
虛擬機安裝蘋果系統的教程
lhslllj
2019-02-23 13:50:59
虛擬機家園VirtualBox虛擬機圖文安裝教程
lhslllj
2019-02-23 13:50:59
大數據教你IT運維管理產品選擇,專業化or平臺化能否兼具?
IT女漢子
2019-02-23 13:50:13
VMware虛擬機linux系統時間同步的解決辦法
小紅帽子
2019-02-23 13:43:55
vmware workstation8輸入多次正確序列號提示錯誤
小紅帽子
2019-02-23 13:43:54
VDI序曲二 RemotoAPP部署
vip2008
2019-02-23 13:42:18
安裝VMware Workstation虛擬機中文版
63332128
2019-02-23 13:41:40
VMware虛擬機三種聯網方法及原理
聽雷
2019-02-23 13:37:20
VMware 虛擬機(linux)增加根目錄磁盤空間
wlzxzxw
2019-02-23 13:27:58
關於VMware 虛擬機磁盤類型和區別
Dreams小強
2019-02-23 13:26:36