Linux下的LVS,Apache,resin配置负载均衡

1.需要准备的硬件和安装的软件.

192.168.1.128安装LVS虚拟服务器。

192.168.1.126安装一个Apache和3个resin,LVS真实服务器

192.168.1.127安装一个Apache和3个resin,LVS真实服务器

2.先在126上进行安装

3.安装Apache.

$tarzxvfhttpd-2.2.*.tar.gz

$cdhttpd-2.2.*

$./configure--prefix=/usr/local/apache2-enable-mods-shared=all--enable-so

$make

$makeinstall

4.安装resin

$tarzxvfresin-3.1.*.tar.gz

$cdresin-3.1.*

$./configure--prefix=/usr/local/resina--with-apxs=/usr/local/apache2/bin/apxs

$make

$makeinstall

$tarzxvfresin-3.0.23.tar.gz

$cdresin-3.0.23

$./configure--prefix=/usr/local/resinb--with-apxs=/usr/local/apache2/bin/apxs

$make

$makeinstall

$tarzxvfresin-3.1.*.tar.gz

$cdresin-3.1.*

$./configure--prefix=/usr/local/resinb--with-apxs=/usr/local/apache2/bin/apxs

$make

$makeinstall

4.修改http.conf配置文件

在最后增加如下内容:

LoadModulecaucho_module/usr/local/apache2/modules/mod_caucho.so

ResinConfigServerlocalhost6801

ResinConfigServerlocalhost6802

ResinConfigServerlocalhost6803

CauchoConfigCacheDirectory/tmp

CauchoStatusyes

5.配置resina,resinb,resinc的resin.conf文件

三个配置文件修改成一样的.

注释掉默认的8080端口

<server-default>

<!--Thehttpport-->

<!--<httpaddress="*"port="8080"/>-->

找到<!--definetheserversinthecluster-->一行,改为如下内容:

<serverid="a"address="127.0.0.1"port="6801"/>

<serverid="b"address="127.0.0.1"port="6802"/>

<serverid="c"address="127.0.0.1"port="6803"/>

6.启动Apache进行验证:

/usr/local/apache2/bin/apachectlstart

7.启动三个resin

$cd/usr/local/resina/bin

$httpd.sh-serverastart

启动resinb

$cd/usr/local/resina/bin

$httpd.sh-serverbstart

启动resinc

$cd/usr/local/resinc/bin

$httpd.sh-servercstart

8.停止Apache和Resin

/usr/local/apache2/bin/apachectlstop

$cd/usr/local/resina/bin

$httpd.sh-serverastop

启动resinb

$cd/usr/local/resina/bin

$httpd.sh-serverbstop

启动resinc

$cd/usr/local/resinc/bin

$httpd.sh-servercstop

9.192.168.1.127也是这样安装。

10.安装LVS

在192.168.1.128运行如下脚本命令:

#description:startLVSofDirectorserver

VIP=192.168.1.130

RIP1=192.168.1.126

RIP2=192.168.1.127

GW=192.168.1.1

./etc/rc.d/init.d/functions

case"$1"in

start)

echo"startLVSofDirectorServer"

#settheVirtualIPAddress

/sbin/ifconfigeth0:0$VIPbroadcast$VIPnetmask255.255.255.255up

/sbin/routeadd-host$VIPdeveth0:0

#ClearIPVStable

/sbin/ipvsadm-C

#setLVS

/sbin/ipvsadm-A-t$VIP:80-srr

/sbin/ipvsadm-a-t$VIP:80-r$RIP1:80-g

/sbin/ipvsadm-a-t$VIP:80-r$RIP2:80-g

#RunLVS

/sbin/ipvsadm

#end

;;

stop)

echo"closeLVSDirectorserver"

/sbin/ipvsadm-C

;;

*)

echo"Usage:$0{start|stop}"

exit1

esac

在192.168.1.126和192.168.1.127下运行如下脚本命令:

#!/bin/bash

#description:startrealserver

VIP=192.168.1.130

/sbin/ifconfiglo:0$VIPbroadcast$VIPnetmask255.255.255.255up

/sbin/routeadd-host$VIPdevlo: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

#end

在浏览器中输入http://192.168.1.130就通过LVS转发到127和126两台不同的服务器上。

在通过Apache分发到不同的Resin服务器上.

相关推荐