博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lvs 集群配置
阅读量:6705 次
发布时间:2019-06-25

本文共 2826 字,大约阅读时间需要 9 分钟。

hot3.png

实验环境
DR_MASTER  192.168.0.130
DR_BACKUP  192.168.0.131
DR_VIP      192.168.0.138
WEBONE     192.168.0.132
WEBTWO    192.168.0.133
GETEWAY    192.168.0.1
1、    下载相关软件:
http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
2、    安装lvs和keepalived
modproble –l | grep ip_vs 看内核是否支持lvs
ln –s /usr/src/kernels/$(uname -r)/ /usr/src/linux
tar –zxvf ipvsadm-1.24.tar.gz
make
make install
tar –zxvf keepalived-1.1.15.tar.gz
./configure  –sysconf=/etc/(可选) 
--with-kernel-dir=/usr/src/kernels/`uname -r` (配置lvs需要编译的选项)
make
make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d
cp /usr/local/etc/sysconfgi/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
3、配置lvs 实现负载均衡
lvsconf.sh
#/bin/bash
#LVS-DR 配置脚本
GATEWAY=192.168.0.1
DR_VIP=192.168.0.138
WEBONE=192.168.0.132
WEBTWO=192.168.0.133
case "$1" in
start)
        echo "Start lvs of director server"
        /sbin/iptables -F
        /sbin/iptables -Z
        /sbin/ifconfig eth0:0 $DR_VIP boradcast $DR_VIP netmask 255.255.255.255 up
        /sbin/route add -host $DR_VIP dev eht0:0
        echo "1" >/proc/sys/net/ipv4/ip_forward
        /sbin/ipvsadm -A -t $DR_VIP:80  -s rr
        /sbin/ipvsadm -a -t $DR_VIP:80 -r $WEBONE -g -w 1
        /sbin/ipvsadm -a -t $DR_VIP:80 -r $WEBTWO -g -w 1
        touch /var/lock/subsys/ipvsadm>/dev/null 2>&1
#run lvs
        /sbin/ipvsadm
        ;;
stop)
        echo "Stop lvs director server"
        echo "0" >/proc/sys/net/ipv4/ip_forward
        /sbin/ifconfig eth0:0 down
        rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1
        ;;
status)
        if [ ! -e /var/lock/subsys/ipvsadm ]; then
        echo "ipvsadm is stop"
        exit 1
        else
        /sbin/ipvsadm -ln
        echo "ipvsadm is ok"
        fi
        ;;
*)
        echo "Usage :$0{start|stop|status}"
        exit 1
esac
exit 0
4、配置真实服务器脚本
realconf.sh
#!/bin/bash
#description:config realserver lo and applu noarp
DR_VIP=192.168.0.138
#./etc/rc.d/init.d/functions
case "$1" in
start)
        ifconfig lo:0 $DR_VIP netmask 255.255.255.255 broadcast $DR_VIP up
        /sbin/route add -host $DR_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
        touch /var/nginxtesting
        sysctl -p >/dev/null 2>&1
        echo "Realserver start ok"
        ;;
stop)
        ifconfig lo:0 down
        route del $DR_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
        rm -rf /var/nginxtesting
        echo "Realserver stoped"
        ;;
status)
        if [ -e /var/nginxtesting ]; then
        echo "Realserver is starting"
        else
        echo "Realserver is stopped"
        fi
        ;;
*)
        echo "Usage:$0{start|stop|status}"
        esac
exit 0
     

转载于:https://my.oschina.net/u/573134/blog/67277

你可能感兴趣的文章
[Node.js] npm init && npm install
查看>>
linux下命令学习
查看>>
Jar
查看>>
Java开发中的23种设计模式详解
查看>>
kafka Windows客户端Linux服务器---转
查看>>
hadoop mapreduce 基础实例一记词
查看>>
Oracle Trunc
查看>>
链表中倒数第k个结点
查看>>
OpenStreetMap初探(一)——了解OpenStreetMap
查看>>
判断线段相交
查看>>
traceroute工作原理
查看>>
C++入门知识总结(1)
查看>>
C#删除文件直接到回收站,而不是直接删除
查看>>
4个好用的JS联动选择插件
查看>>
C# 超时工具类 第二版
查看>>
man手册导出成txt,pdf,html的一些小技巧
查看>>
SQL Server中使用正则表达式
查看>>
IntegrityError duplicate key value violates unique constraint - django/postgres
查看>>
linux上怎么切换不同版本的arm-linux-gcc?只需改一行函数
查看>>
又一次拾起C语言的威严
查看>>