标签:stat null mask 指定 网站群 ddr 防火 S3 col
今天以DR模式的LVS群集为基础,增加了一台从负载调度器,使用keepalived来实现主、备调度服务器的热备,从而构架具有负载均衡、高可用两种能力的LVS网站群集平台。主机 | 操作系统 | IP地址 |
---|---|---|
DR1主调度服务器: | CentOS 7.0 x86_64 | 192.168.100.25 |
DR2备调度服务器: | CentOS 7.0 x86_64 | 192.168.100.26 |
web1节点服务器: | CentOS 7.0 x86_64 | 192.168.100.27 |
web2节点服务器: | CentOS 7.0 x86_64 | 192.168.100.29 |
VIP虚拟IP地址: | 192.168.100.100 | |
Win 7 客户端: | Windows 7 | 192.168.100.30 |
yum install -y httpd
systemctl start httpd.service
echo "<h1>this is web1</h1>" > /var/www/html/index.html
vim /etc/init.d/web.sh
#!/bin/bash
VIP=192.168.100.100 #VIP虚拟IP地址
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
systemctl stop firewalld.service
setenforce 0
yum install -y httpd
systemctl start httpd.service
echo "<h1>this is web2</h1>" > /var/www/html/index.html
vim /etc/init.d/web.sh
#!/bin/bash
VIP=192.168.100.100 #VIP虚拟IP地址
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
systemctl stop firewalld.service
setenforce 0
yum install keepalived ipvsadm -y
vi /etc/sysctl.conf
net.ipv4.ip_forward=1 #开启路由转发功能
net.ipv4.conf.all.send_redirects = 0 #proc响应关闭重定向功能
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p
vim /etc/init.d/dr.sh
#!/bin/bash
GW=192.168.100.1 #网关地址
VIP=192.168.100.100 #VIP虚拟地址
RIP1=192.168.100.27 #web1节点服务器IP
RIP2=192.168.100.29 #web2节点服务器IP
case "$1" in
start)
/sbin/ipvsadm --save > /etc/sysconfig/ipvsadm #保存ipvsadm策略
systemctl start ipvsadm #启动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
ipvsadm -ln
vim /etc/keepalived/keepalived.conf
global_defs {
...
smtp_server 127.0.0.1 #指向本地
router_id LVS_01 ##指定服务器名称
...
}
vrrp_instance VI_1 {
state MASTER #主调度服务器
interface ens33
virtual_router_id 10 #主备组号相同
priority 100 #优先级备服务器小于主服务器
...
auth_pass abc123 #验证密码,主备相同
...
virtual_ipaddress {
192.168.100.100 #虚拟VIP地址
}
...
virtual_server 192.168.100.100 80 { #虚拟服务器VIP、端口
...
lb_kind DR
...
real_server 192.168.100.27 80 { #真实web1节点服务器IP、端口
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.29 80 { #真实web2节点服务器IP、端口
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
systemctl start keepalived
yum install keepalived ipvsadm -y
vi /etc/sysctl.conf
net.ipv4.ip_forward=1 #开启路由转发功能
net.ipv4.conf.all.send_redirects = 0 #proc响应关闭重定向功能
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p
vim /etc/init.d/dr.sh
#!/bin/bash
GW=192.168.100.1 #网关地址
VIP=192.168.100.100 #VIP虚拟地址
RIP1=192.168.100.27 #web1节点服务器IP
RIP2=192.168.100.29 #web2节点服务器IP
case "$1" in
start)
/sbin/ipvsadm --save > /etc/sysconfig/ipvsadm #保存ipvsadm策略
systemctl start ipvsadm #启动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
ipvsadm -ln
vim /etc/keepalived/keepalived.conf
global_defs {
...
smtp_server 127.0.0.1 #指向本地
router_id LVS_02 #指定服务器名称
...
}
vrrp_instance VI_1 {
state BACKUP #备用调度服务器
interface ens33
virtual_router_id 10 #主备组号相同
priority 100 #优先级备服务器小于主服务器
...
auth_pass abc123 #验证密码,主备相同
...
virtual_ipaddress {
192.168.100.100 #虚拟VIP地址
}
...
virtual_server 192.168.100.100 80 { #虚拟服务器VIP、端口
...
lb_kind DR
...
real_server 192.168.100.27 80 { #真实web1节点服务器IP、端口
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.29 80 { #真实web2节点服务器IP、端口
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
systemctl start keepalived
win7客户机访问VIP地址,如下
等待几十秒钟后再刷新,不行的话,请删除浏览器的缓存然后再访问即可
至此,高可用的LVS负载均衡群集已经搭建成功了。
标签:stat null mask 指定 网站群 ddr 防火 S3 col
原文地址:http://blog.51cto.com/10316297/2133639