用yum安裝(先檢查下yum是否可用,若是可用,就用yum安裝)服務器
#yum install ipvsadm piranha負載均衡
修改LVS配置tcp
#cd /etc/sysconfig/ha/ide
先對lvs默認配置文件進行備份,再建立新的配置文件ui
#mv lvs.cf lvs.cf.backdebug
#vi lvs.cf ####內容以下server
serial_no = 39ip
primary = 10.5.20.12it
service = lvsio
backup_active = 1
backup = 10.5.20.13
heartbeat = 1
heartbeat_port = 539
keepalive = 3
deadtime = 9
network = direct
debug_level = NONE
monitor_links = 0
syncdaemon = 0
virtual XP {
active = 1
address = 10.5.20.14 bond0:0
vip_nmask = 255.255.255.0
port = 80
send = "GET / HTTP/1.0\r\n\r\n"
expect = "HTTP"
use_regex = 0
load_monitor = none
scheduler = wlc
protocol = tcp
timeout = 5
reentry = 5
quiesce_server = 0
server xp1 {
address = 10.5.20.12
active = 1
weight = 1
}
server xp2 {
address = 10.5.20.13
active = 1
weight = 1
}
}
在兩臺物理機上分別啓動心跳服務:
# service pulse start
Starting pulse: [ OK ]
這時,能在主物理機10.5.20.12上看到負載均衡網卡已啓動,
而10.5.20.13上是沒有這個網卡的:
# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:29:E9:2F:F0
inet addr:10.5.20.12 Bcast:10.5.23.255 Mask:255.255.252.0
inet6 addr: fe80::20c:29ff:fee9:2ff0/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:2039549 errors:0 dropped:0 overruns:0 frame:0
TX packets:692572 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:748901428 (714.2 MiB) TX bytes:153254084 (146.1 MiB)
bond0:0 Link encap:Ethernet HWaddr 00:0C:29:E9:2F:F0
inet addr:10.5.20.14 Bcast:10.5.20.255 Mask:255.255.255.0
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
當主物理機的服務關閉時,在10.5.20.13上看到網卡已啓動:
# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:29:4C:FC:A4
inet addr:10.5.20.13 Bcast:10.5.23.255 Mask:255.255.252.0
inet6 addr: fe80::20c:29ff:fe4c:fca4/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:19679 errors:0 dropped:0 overruns:0 frame:0
TX packets:16633 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:18527316 (17.6 MiB) TX bytes:1528599 (1.4 MiB)
bond0:0 Link encap:Ethernet HWaddr 00:0C:29:4C:FC:A4
inet addr:10.5.20.14 Bcast:10.5.20.255 Mask:255.255.255.0
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
查看虛擬服務器狀態:
# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.5.20.14:80 wlc
將服務設成開機自啓動:# chkconfig --level 345 pulse on