lvs+Keepalived
拓扑图:
##############\ / ###############
# # \ / # #
/ # Directory1 # \ / #centosserver1#
/ # # \ / # #
/ ############## \ / ###############
internet\ lvs+keepalived /
\ ############## / \ ###############
\# # / \ # #
# Directory2 # / \ # centosserver2#
# # / \ # #
############## / \###############
注意:Directory1,directory2,centosserver1,centosserver2都在同一网段
Directory1:ip:192.168.10.5
Directory2:ip:192.168.10.6
centosserver1:ip:192.168.10.1
centosserver2:ip:192.168.10.2
VIP=192.168.10.11
一,Directory1 Directory 2 Keepalived安装
1.在两台keepalived上均安装相关的软件包
yum -y install kernel-devel gcc openssl-devel popt-devel
下载地址:
2.安装tar -zxvf keepalived-1.2.7.tar.gz
./configure --sysconf=/etc --with-kernel-dir=/usr/src/kernels/2.6.32-71.el6.x86_64/ #最后这个建议加上,否则无法调用ipvs的的模块
make && make install
ln -s /usr/local/sbin/keepalibed /sbin
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
Keepalived配置
3.修改配置:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER #在备上修改成BACKUP
interface eth0
virtual_router_id 51
priority 100 #在备上面修改成80
advert_int 1
authentication {
auth_type PASS #主辅同步默认密码
auth_pass 1111
}
virtual_ipaddress {
192.168.10.11 #虚拟ip
}
}
virtual_server 192.168.10.11 80 {
delay_loop 6
lb_algo rr #调度算法
lb_kind NAT #模式(NAT或者DR)
nat_mask 255.255.255.0
persistence_timeout 50 #监测超时时间为50内存活
protocol TCP
real_server 192.168.10.1 80 {
weight 1 #权重
TCP_CHECK{
connect_timeout 10
nb_get_retry 3
connect_port 80
}
}
real_server 192.168.10.2 80{
weight 1
TCP_CHECK{
connect_timeout 10
nb_get_retry 3
connect_port 80
}
}
}
4.启动服务:
/etc/init.d/keepalived start #启动服务
ipvadm -L -n # 查看是否设置成功
5.开机启动设置:
ln -s /etc/init.d/keepalived /ect/rc.d/rc3.d/S99keepalived
ln -s /etc/init.d/keepalived /ect/rc.d/rc5.d/S99keepalived
二,centosserver1,centosserver2配置。
1.安装配置httpd
yum -y install httpd
echo welcome centosserver1 >/var/www/html/index.html
server httpd start
chkconfig httpd on
2.运行脚本:
/etc/init.d/centosserver.sh
ln -s /etc/init.d/centosserver.sh /ect/rc.d/rc3.d/S99centos.sh
ln -s /etc/init.d/centosserver.sh /ect/rc.d/rc5.d/S99centos.sh
#!/bin/bash
VIP=192.168.10.11
case "$1" in
start)
ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
/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
echo "Centosserver start OK"
;;
stop) ifconfig lo:0 down
route del $VIP >/dev/null 2>$1
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 "Centosserver Stoped"
;;
*)
echo "Usage: $0{start|stop}"
exit 1
esac
exit
============================================================打开浏览器进行测试==============================================================================
==========================================================进行破坏测试关掉Directory1看看Directory2能否接管=========================
阅读(1138) | 评论(0) | 转发(0) |