系统版本:Red Hat Enterprise Linux Server release 6.3 (Santiago)
内核版本:2.6.32-279.el6.x86_64
lvs使用光盘自带的
keepalived版本:keepalived-1.2.12
apache使用光盘自带的:2.2.15
lvs的安装:
挂在光盘后
yum install ipvsadm
如果不能安装可以在包目录下找到相关的包,手动安装
IP规划:
前端:192.168.2.80-81
后端:192.168.2.82-83
部署情况:前端部署lvs和keepalived 后端部署:apache
keepalived的安装
tar -zvxf keepalived-1.2.12.tar.gz
cd keepalived-1.2.12
./configure
make
make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
做成系统启动服务方便管理.
添加开机启动
vi /etc/rc.local
添加
/etc/init.d/keepalived start
主的keepalived的配置请见附件
备的:
修改
state BACKUP //类型
priority 100 //优先级,数字越大,优先级越高,主的优先级比备的高
之后启动keepalived
主备上可以看到
只有主keepalived获得浮动地址,主keepalived出现故障后备keepalived获得浮动地址
前后端节点出现故障,相关日志都会打印在/var/log/messages
前端的keepalived会根据设置的时间发包检查后端和备机的状态,如果有问题就将后端故障节点剔除,和进行主备切换
前端lvs的配置
#!/bin/bash
#description:start realserver
VIP=192.168.2.84
sh /etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS Of RealServer dr"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
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
;;
stop)
/sbin/ifconfig lo:o down
echo "close LVS OF realserver DR"
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
;;
*)
echo "Usage:S0 {start | stop}"
exit 1
esac
keepalived的作用,在这个环境中,keepalived用来配置ipvsadm,检测后端节点,故障转移之作用
keepalived有PASS和AH两种验证方式,PASS是明文,AH是加密验证,