用yum安装(先检查下yum是否可用,如果可用,就用yum安装)
#yum install ipvsadm piranha
修改LVS配置
#cd /etc/sysconfig/ha/
先对lvs默认配置文件进行备份,再创建新的配置文件
#mv lvs.cf lvs.cf.back
#vi lvs.cf ####内容如下
serial_no = 39
primary = 10.5.20.12
service = lvs
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
本文出自 “石头” 博客,请务必保留此出处http://410477.blog.51cto.com/400477/1639030
原文地址:http://410477.blog.51cto.com/400477/1639030