调度服务器地址192.168.100.100
节点1 192.168.100.110
节点2 192.168.100.120
-------------------------DR调度服务器------------------------------
yum install keepalived ipvsadm -y
关闭防火墙安全组件
vi /etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
proc响应关闭重定向功能----------------------------------------------------
cp ifcfg-ens33 ifcfg-ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.0
ifup ens33:0
————————————————————————————————
设置ipvsadm启动脚本
cd /etc/init.d/
vi dr.sh
#!/bin/bash
GW=192.168.100.1
VIP=192.168.100.10
RIP1=192.168.100.110
RIP2=192.168.100.120
case "$1" in
start)
/sbin/ipvsadm --save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm
/sbin/ifconfig ens33:0 $VIP broadcast $VIP netmask 255.255.255.255 broadcast
$VIP up
/sbin/route add -host $VIP dev ens33:0
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
echo "ipvsadm starting --------------------[ok]"
;;
stop)
/sbin/ipvsadm -C
systemctl stop ipvsadm
ifconfig ens33:0 down
route del $VIP
echo "ipvsamd stoped----------------------[ok]"
;;
status)
if [ ! -e /var/lock/subsys/ipvsadm ];then
echo "ipvsadm stoped---------------"
exit 1
else
echo "ipvsamd Runing ---------[ok]"
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
exit 0
chmod +x dr.sh
service dr.sh start
-----------------------节点服务器------------------------------------------
yum install httpd
systemctl start httpd.service
systemctl stop firewalld.service
setenforce 0
cd /var/www/html/
echo "this is accp web" > index.html
cd /etc/sysconfig/network-scripts
cp ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.0
ONBOOT=yes
设置ifcfg-lo:0 启动脚本
cd /etc/init.d/
vim web.sh
#!/bin/bash
VIP=192.168.100.10
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
sysctl -p >/dev/null 2>&1
echo "RealServer 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 "RealServer Stopd"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
chmod +x web.sh
service web.sh start
ifup lo:0 (启用立刻中断)
firefox "http://127.0.0.1/" & 本地自测网页
service web.sh stop
service web.sh start(建议重启服务)
-------------keepalived部署--(在调度服务器上设置)-------------------------
cd /etc/keepalived/
vim keepalived.conf
global_defs {
...
smtp_server 127.0.0.1 #指向本地
router_id LVS_01 #指定名称,备份服务器不同名称
...
}
vrrp_instance VI_1 {
state MASTER #备份服务器是BACKUP
virtual_router_id 10 #组号相同
...
auth_pass abc123 #验证密码
priority 100 #优先级备份小于主
...
virtual_ipaddress {
192.168.100.10
}
...
virtual_server 192.168.100.10 80 {
...
real_server 192.168.100.201 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.203 80 {
weight 1
TCP_CHECK {
connect_port 80 #添加端口
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
systemctl start keepalived
ip addr show dev ens33:0 #查看虚拟网卡
keepalived启动不到10秒就黑,可能是绑定eth0的问题 会报错 keepalived绑定ens33
keepalived状态常在的时候访问不了,重启防火墙又好了,很无语。
能访问之后设置的轮询机制又不启用 开启很多网页才OK,不明所以
原文地址:http://blog.51cto.com/13760226/2162761