在RHEL5.8上,提供四台虚拟机:
HA1: 172.16.66.6 HA2: 172.16.66.7 vip: 172.16.66.1
RS1:172.16.66.4 lo:0,VIP:172.16.66.1
RS2:172.16.66.5 lo:0,VIP:172.16.66.1
一、RS的配置过程
1、RS1的配置:
首先配置IP:(网卡要改为桥接方式)
setup à Network configuration à Edit Devices à eth0(eth0) – Advanced Micro Devices [AMD] à 修改IP为 172.16.66.4
# service network restart 重启服务(每次修改配置后都不要忘了重启服务)
下载yum源
# yum install httpd –y 安装web服务
vim lvs.sh 脚本内容如下:
#!/bin/bash
#
# Script to start LVS DR real server.
# chkconfig: - 90 10
# description: LVS DR real server
#
. /etc/rc.d/init.d/functions
VIP=172.16.66.1
host=`/bin/hostname`
case "$1" in
start)
# Start LVS-DR real server on this machine.
/sbin/ifconfig lo down
/sbin/ifconfig lo up
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
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
(broadcast为广播地址,255.255.255.255意味着只跟自己在同一个网段内,全是网络地址)
/sbin/route add -host $VIP dev lo:0
;;
stop)
# Stop LVS-DR real server loopback device(s).
/sbin/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
;;
status)
# Status of LVS-DR real server.
islothere=`/sbin/ifconfig lo:0 | grep $VIP`
isrothere=`netstat -rn | grep "lo:0" | grep $VIP`
if [ ! "$islothere" -o ! "isrothere" ];then
# Either the route or the lo:0 device
# not found.
echo "LVS-DR real server Stopped."
else
echo "LVS-DR real server Running."
fi
;;
*)
# Invalid entry.
echo "$0: Usage: $0 {start|status|stop}"
exit 1
;;
esac
# chmod +x lvs.sh 添加执行权限
# ./lvs.sh start 让脚本执行起来
提供相应的网页页面并启动web服务:
# setenforce 0 关闭selinux
在物理主机上ping 172.16.66.1看看是否能ping通
Ping通后 可执行 arp -a 命令查看哪一个IP响应了
ifconfig 验证(虚拟IP为172.16.66.1)