扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
文章摘要:负载均衡服务器的配置过程,首先了解各个设备的IP分配具体内容,之后是apache,resin的配置代码展示。希望大家能从中学到配置方法和思路。
接触负载均衡这个领域已经有一段时间了,但是对于linux下的负载均衡服务器的设置问题总是掌握的不得要领。那么现在,特意找来了一篇资料,跟大家一起分享。共同看看具体的配置过程是如何的。那么,具体的内容,我们一起来看文章吧。
两台resin 服务器和两台apache服务器?一台负载均衡服务器,一共5台server。
两台apache服务器ip地址:
apache1 ip:192.168.9.101
apache2 ip:192.168.9.110
两台resin 服务器ip地址:
resin1 ip:192.168.9.145
resin2 ip:192.168.9.146
一台负载均衡服务器ip地址:
vip1:192.168.9.106 提供两台apache负载均衡的虚拟ip地址
vip2:192.168.9.150 提供两台resin负载均衡的虚拟ip地址
负载均衡服务器 ip地址192.168.9.109
apache1 lvs相关配置如下:
建一个shell脚本vi /usr/local/lvs/real.sh
#!/bin/bash
# set the Virtual IP Address
/sbin/ifconfig lo:0 192.168.9.106 broadcast 192.168.9.106 netmask 255.255.255.255 up
/sbin/route add -host 192.168.9.106 dev lo:0
#off ARP
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
# run
sysctl -p
#end
保存退出
将此脚本添加自启动文件
[root@web1 ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
/usr/local/lvs/real.sh
touch /var/lock/subsys/local
apache2服务器lvs配置和apache1相同
resin1服务器lvs配置如下
建一个shell脚本 vi /usr/local/realserver/real.sh
#!/bin/bash
# set the Virtual IP Address
/sbin/ifconfig lo:0 192.168.9.150 broadcast 192.168.9.150 netmask 255.255.255.255 up
/sbin/route add -host 192.168.9.150 dev lo:0
#off ARP
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
# run
sysctl -p
#end
将此脚本添加自启动文件
[root@resin1 ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
/usr/local/realserver/real.sh
touch /var/lock/subsys/local
resin2服务器lvs配置和resin1相同
负载均衡服务器配置
安装libnet ?ipvsadm?ldirectord软件
yum install libnet
yum install ipvsadm
yum install ldirectord*
新建/usr/local/lvsdr/lvs.sh脚本
vi /usr/local/lvsdr/lvs.sh
VIP1=192.168.9.106
VIP2=192.168.9.150
RIP1=192.168.9.101
RIP2=192.168.9.110
RIP3=192.168.9.145
RIP4=192.168.9.146
GW=192.168.9.2
#set the vritual IP Address
/sbin/ifconfig eth0:0 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
/sbin/route add -host $VIP1 dev eth0:0
/sbin/ifconfig eth0:1 $VIP2 broadcast $VIP2 netmask 255.255.255.255 up
/sbin/route add -host $VIP2 dev eth0:1
#clear IPVS table
/sbin/ipvsadm -C
#Set LVS
/sbin/ipvsadm -A -t $VIP1:80 -s rr
/sbin/ipvsadm -a -t $VIP1:80 -r $RIP1:80 -g
/sbin/ipvsadm -a -t $VIP1:80 -r $RIP2:80 -g
/sbin/ipvsadm -A -t $VIP2:8080 -s wlc -p 120
/sbin/ipvsadm -a -t $VIP2:8080 -r $RIP3:8080 -g
/sbin/ipvsadm -a -t $VIP2:8080 -r $RIP4:8080-g
#Run lvs
/sbin/ipvsadm
#end
配置ldirectord
[root@lvsdr ~]# cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf /etc/ha.d
vi /etc/ha.d/ldirectord.cf
# Global Directives
checktimeout=3
checkinterval=1
#fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
#logfile="local0"
#emailalert="admin@x.y.z"
#emailalertfreq=3600
#emailalertstatus=all
quiescent=yes
#VIP1=192.168.9.106 HTTP
virtual=192.168.9.106:80
real=192.168.9.101:80 gate
real=192.168.9.110:80 gate
#real=192.168.6.6:80 gate
#fallback=127.0.0.1:80 gate
service=http
#request="index.html"
#receive="Test Page"
#virtualhost=some.domain.com.au
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcp
#checktype=negotiate
checkport=80
#request="index.html"
#receive="Test Page"
#virtualhost=www.x.y.z
#VIP2=192.168.9.150 RESIN
virtual=192.168.9.150:8080
real=192.168.9.145:8080 gate
real=192.168.9.146:8080 gate
#real=192.168.6.6:8080 gate
#fallback=127.0.0.1:80 gate
#service=http
#request="index.html"
#receive="Test Page"
#virtualhost=some.domain.com.au
scheduler=wlc
persistent=600
#netmask=255.255.255.255
protocol=tcp
checktype=connect
checkport=8080
#request="index.html"
#receive="Test Page"
#virtualhost=www.x.y.z
加入自启动
[root@lvsdr ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
#/usr/local/bin/lvsdr start
/usr/local/lvsdr/lvs.sh
/etc/init.d/ldirectord start
#/etc/init.d/ipvsadm start
测试http://192.168.9.106 (两台apache负载均衡服务器测试)
测试http://192.168.9.150 (两台resin负载均衡服务器测试)
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者