記錄一下搭建lvs環境的步驟
其中master 10.0.0.11,backup 10.0.0.15,realserver1 10.0.0.119,realserver210.0.0.11
1.mkdir /usr/local/src/lvs
2.cd /usr/local/src/lvs
3.上傳keepalived-1.1.20.tar.gz ipvsadm-1.24.tar.gz到指定資料夾
4.lsmod |grep ip_vs
5.uname -r
結果:2.6.32-431.el6.x86_64
6.ln -s /usr/src/kernels/2.6.32-431.el6.x86_64/ /usr/src/linux
7 tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install
然後用 ipvsadm 進行測試
8. tar zxvf keepalived-1.1.20.tar.gz
cd keepalived-1.1.20
./configure && make && make install
find / -name keepalived # 檢視keepalived位置
9. 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/
service keepalived start|stop #做成系統啟動服務方便管理.
10vim /etc/init.d/lvsdr
#!/bin/bash
rip1=10.0.0.19
rip2=10.0.0.23
vip=10.0.0.11
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo " start lvs of directorserver"
# set the virtual ip address and sysctl parameter
/sbin/ifconfig eth0:0 $vip broadcast $vip netmask 255.255.255.255 up
/sbin/route add -host $vip dev eth0:0
echo "1" >/proc/sys/net/ipv4/ip_forward
#clear ipvs table
/sbin/ipvsadm -c
#set lvs
#web apache
/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
#run lvs
/sbin/ipvsadm
;;stop)
echo "close lvs directorserver"
echo "0" >/proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -c
/sbin/ifconfig eth0:0 down
;;*)
echo "usage: $0 "
exit 1
esac
11. chmod a+x /etc/init.d/lvsdr
service lvsdr start|stop
12.檢視結果
ipvsadm -ln
13配置realserver指令碼
vim /etc/init.d/realserver
#!/bin/bash
vip=10.0.0.11
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo " start lvs of realserver"
/sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
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:0 down
echo "close lvs directorserver"
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: $0 "
exit 1
esac
chmod a+x /etc/init.d/realserver
service realserver start|stop
可以通過ifconfig或者ip add 命令檢視是否繫結
備註:此指令碼在兩台realserver上均須執行。
LVS 負載均衡 DR模式環境搭建
簡單記錄一下搭建lvs負載均衡集群的過程。具體原理請看 lvs負載均衡原理和模式 排程器.centos7.5,ip 10.0.0.10 ens33 ip 10.0.0.100 ens33 0 rs1.centos7.5,ip 10.0.0.11 lo ip 10.0.0.100 lo 0 rs2.c...
LVS搭建負載均衡集群服務
一,lvs簡介 lvs是linux virtual server的簡稱,也就是linux虛擬伺服器,是乙個由章文嵩博士發起的自由軟體專案,它的官方站點是www.linuxvirtualserver.org。現在lvs已經是 linux標準核心的一部分,在linux2.4核心以前,使用lvs時必須要重...
LVS搭建負載均衡和併發
lvs搭建 先準備三颱虛擬機器 配置在同一網段 eth0 配置在乙個網段 dip,rip在乙個網段 主 1.進行 ifconfig eth0 2 192.168.40.100 進行配置vip的操作 echo 1 proc sys net ipv4 ip forward 配置從的伺服器ip echo ...