realserver2 eth0 192.168.125.10/24 gw192.168.125.6
1 在真实服务器上安装配置和启动Apach
用chkconfig命令配置httpd启动脚本运行在系统默认运行等级,配置日志文件
#touch /var/log/httpd/error_log
#touch /var/log/httpd/access_log
确保DocumentRoot存在,
#mkdir -p /www/htdocs
#echo "This is a test (from the realserver)" > /www/htdocs/index.html
#/etc/init.d/httpd start
或#service httpd start
查看正在运行
#ps -elf | grep httpd
lynx -dump 192.168.125.9
2真实服务器上设置默认路由
将真实服务器上默认路由设置到DIP
#vi /etc/sysconfig/network
GATEWAY=192.169.125.6
手工设置
#/sbin/route add default gw 192.168.125.6
3在Director安装LVS
#tar xvf ipvsadm-1.24.tar.gz
#cd ipvsadm-1.24
#make
#make install
make时确保/usr/src/linux目录
ln -s /usr/src/kernels/2.6.18-xxx.12.1.e15-i686/ /usr/src/linux
4配置LVS
vi /etc/init.d/lvs
#!/bin/bash
#
#LVS script
#
#chkconfig:2345 99 90
#description:LVSsample script
#
case "$1" in
start)
#Bring up the VIP (Normally this should be under Heartbeat's control.)
/sbin/ifconfig eth0:1 192.168.12.8 netmask 255.255.255.0 up
#Since this is the Director we must be
#able to forward packets.
echo 1 > /proc/sys/net/ipv4/ip_forward
#Clear all iptables rules.
/sbin/iptables -F
#Reset iptables counters.
/sbin/iptables -Z
#Clear all ipvsadm rules/services.
/sbin/ipvsadm -C
#Add an IP virtual service for VIP 192.168.12.6 port 80
/sbin/ipvsadm -A -t 192.168.12.8:80 -s rr
#Now direct packets for this VIP to
#to the real server IP(RIP) inside the cluster
/sbin/ipvsadm -a -t 192.168.12.8:80 -r 192.168.125.10 -m
/sbin/ipvsadm -a -t 192.168.12.8:80 -r 192.168.125.9 -m
;;
stop)
#stop forwarding packets
echo 0 > /proc/sys/net/ipv4/ip_forward
#Reset ipvsadm
/sbin/ipvsadm -C
# Bring down the VIP interface
ifconfig eth0:1 down
;;
*)
echo "Usage: $0 {start|stop}"
;;
esac
以下两行
/sbin/ipvsadm -A -t 192.168.12.8:80 -s rr 指定VIP地址和调度方法 (-s rr)
/sbin/ipvsadm -a -t 192.168.12.8:80 -r 192.168.125.10 -m 关联RIP( -r 192.168.125.10 )与VIP,并指定了转发方法(-m)
ipvsadm参数 调度方法
-s rr 循环
-s wrr 带权循环
-s lc 最小连接
-s wlc 带权重最小连接
-s lblc 基于位置的最小连接
-s lblcr 基于位置的最小连接(带复制)
-s dh 目的地散列
-s sh 源散列
-s sed 最短期望延迟
-s nq 无须队列等待
ipvsadm参数 转发方法
-g LVS-DR
-i LVS-TUN
-m LSV-NAT
运行脚本
#/etc/init.d/lvs start
查看虚拟服务表
#sbin/ipvsadm -L -n
5测试集群
命令
#ifconfig -a
#lynx -dump 192.168.125.9
#ps -elf |grep httpd
#netstat -apn |grep httpd
将真实服务器用做真实服务器
/sbin/ipvsadm -a -t 192.168.12.8:80 -r 127.0.0.1 -m