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. $tar zxvf httpd-2.2.*.tar.gz $cd httpd-2.2.* $./configure --prefix=/usr/local/apache2 -enable-mods-shared=all --enable-so $make $make install 4.安装resin $tar zxvf resin-3.1.*.tar.gz $cd resin-3.1.* $ ./configure --prefix=/usr/local/resina --with-apxs=/usr/local/apache2/bin/apxs $make $make install $tar zxvf resin-3.0.23.tar.gz $cd resin-3.0.23 $ ./configure --prefix=/usr/local/resinb --with-apxs=/usr/local/apache2/bin/apxs $make $make install $tar zxvf resin-3.1.*.tar.gz $cd resin-3.1.* $ ./configure --prefix=/usr/local/resinb --with-apxs=/usr/local/apache2/bin/apxs $make $make install 4.修改http.conf配置文件 在最后增加如下内容: LoadModule caucho_module /usr/local/apache2/modules/mod_caucho.so ResinConfigServer localhost 6801 ResinConfigServer localhost 6802 ResinConfigServer localhost 6803 CauchoConfigCacheDirectory /tmp CauchoStatus yes 5.配置resina,resinb,resinc的resin.conf文件 三个配置文件修改成一样的. 注释掉默认的8080端口 <server-default> <!-- The http port --> <!-- <http address="*" port="8080"/>--> 找到<!-- define the servers in the cluster -->一行,改为如下内容: <server id="a" address="127.0.0.1" port="6801"/> <server id="b" address="127.0.0.1" port="6802"/> <server id="c" address="127.0.0.1" port="6803"/> 6.启动Apache进行验证: /usr/local/apache2/bin/apachectl start 7.启动三个resin $cd /usr/local/resina/bin $httpd.sh -server a start 启动resinb $cd /usr/local/resina/bin $httpd.sh -server b start 启动resinc $cd /usr/local/resinc/bin $httpd.sh -server c start 8. 停止Apache和Resin /usr/local/apache2/bin/apachectl stop $cd /usr/local/resina/bin $httpd.sh -server a stop 启动resinb $cd /usr/local/resina/bin $httpd.sh -server b stop 启动resinc $cd /usr/local/resinc/bin $httpd.sh -server c stop 9. 192.168.1.127也是这样安装。 10.安装LVS 在192.168.1.128运行如下脚本命令: # description: start LVS of Directorserver 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 " start LVS of DirectorServer" # set the Virtual IP Address /sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev eth0:0 #Clear IPVS table /sbin/ipvsadm -C #set LVS /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 #end ;; stop) echo "close LVS Directorserver" /sbin/ipvsadm -C ;; *) echo "Usage: $0 {start|stop}" exit 1 esac 在192.168.1.126和192.168.1.127下运行如下脚本命令: #!/bin/bash #description : start realserver VIP=192.168.1.130 /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $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 sysctl -p #end 在浏览器中输入http://192.168.1.130就通过LVS转发到127和126两台不同的服务器上。 在通过Apache分发到不同的Resin服务器上. |
|