浏览 1775 次
锁定老帖子 主题:LVS负载均衡配置
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2012-05-22
lvs server: 10.10.10.20 real server: 10.10.10.21和10.10.10.22 vip: 10.10.10.30 (三台机器都使用虚拟IP 30) real server上分别安装了apache2.2 1. 安装ipvsadm 1)下载安装包 http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24-6.src.rpm 2)使用命令rpmbuild --rebuild ipvsadm-1.24-6.src.rpm #rpmbuild --rebuild ipvsadm-1.24-6.src.rpm 会提示有警告和错误 忽略 3)vi /usr/src/redhat/SPECS/ipvsadm.spec 将第7行Copyright修改为License 保存退出 4)建立软连接ln -s /usr/src/kernels/2.6.18-128.el5-i686/ /usr/src/linux,注意源目录地址。 #ln -s /usr/src/kernels/2.6.18-128.el5-i686/ /usr/src/linux 5)生成二进制安装包 #rpmbuild -ba /usr/src/redhat/SPECS/ipvsadm.spec 6)安装ipvsadm #rpm -ivh /usr/src/redhat/RPMS/i386/ipvsadm-1.24-6.i386.rpm 2. lvs server配置 执行命令:vi /etc/init.d/lvs 将如下代码复制进去: ============================================================================== #!/bin/sh # description: Start LVS of Director server VIP=10.10.10.30 RIP1=10.10.10.21 RIP2=10.10.10.22 ./etc/rc.d/init.d/functions case "$1" in start) echo " start LVS of Director Server" # set the Virtual IP Address and sysctl parameter /sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up echo "1" >/proc/sys/net/ipv4/ip_forward #Clear IPVS table /sbin/ipvsadm -C #set LVS /sbin/ipvsadm -A -t $VIP:80 -s rr -p 600 /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 {start|stop}" exit 1 esac ============================================================================== 执行命令启动: service lvs start 停止命令:service lvs stop 3. lvs real server配置 执行命令:vi /etc/init.d/lvsrs 将如下内容复制进去: ============================================================================== #!/bin/bash #description : Start Real Server VIP=10.10.10.30 ./etc/rc.d/init.d/functions case "$1" in start) echo " Start LVS of Real Server" /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 Director server" 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 {start|stop}" exit 1 esac ============================================================================== 执行命令启动: service lvsrs start 停止命令:service lvsrs stop 访问虚拟IP 10.10.10.30时,访问会被轮流分配到10和20上。该配置属于DR方式,所以三台服务器必须都在一个交换机下,不能跨网段。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |