RHEL5_LVS+cluster配置

更新时间:2023-06-07 06:35:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

LVS cluster: Direct Routing Mode

Routing/LoadBalance Server: OS RHEL 5 Primary IP: 9.125.91.239,

Virtual IP: 9.125.91.254

Apache Server1: OS Gentoo Linux IP: 9.125.91.60

Solution Description

Routing server is using the virtual IP to receive HTTP request from any outside machines, and LVS will deliver the request to backend Apache Servers according to preset load balancing algorithms.

Environment Setup

According to the material I found and the hands-on experience, at this moment RHEL 5 provides the best LVS support. All necessary software is included in the installation disk. For other Linux Operating System, LVS support is less matured or needs many hack efforts. So, the very first step is to install the RHEL 5 on machine to be the following RPMs are installed:

1. ipvsadm-1.24-8.1.i386.rpm

2. modcluster-0.8-27.el5.i386.rpm

3. piranha-0.8.4-7.el5.i386.rpm

4. system-config-cluster-1.0.39-1.0.noarch.rpm

5. php-5.1.6-5.el5.i386.rpm

6. php-cli-5.1.6-5.el5.i386.rpm

7. php-common-5.1.6-5.el5.i386.rpm

8. http*

Run command “rpm –ivh * “ to install everything. If any dependency RPM needed, found it out from installation DISK.

After installation, check the following files for their existence:

“/etc/sysconfig/ha/lvs.cf,/etc/init.d/piranha-gui,/etc/init.d/pulse”

Run command “piranha-passwd” to set up the password for user “piranha”.

配置LVS主要是通过http的方式,地址如下:

http://9.125.91.239:3636

将会看到如下的界面,在这里,如果要登陆进去,在命令行里输入piranha-passwd然后输入密码,就可以登陆下面的页面了,用户名piranha,密码是刚才设置的。

Piranha Setup:

Execute: /etc/init.d/piranha-gui start

Then connect to http://routingserver:3636. In my case routingserver ==

9.125.91.239. Make sure port 3636 is accessible from firewall.

Any change should kick “ACCEPT” to enable the change. User can choose “Scheduling” algorithm for optimize the routing policy.

Now the Piranha setup is done.

启动转发

vi /etc/sysctl.conf

net.ipv4.ip_forward = 0

将 0 改成 1

net.ipv4.ip_forward = 1

执行如下命令来应用生效:

sysctl –p

LVS自启动设置

Execute:

Chkconfig –add piranha-gui

Chkconfig –add pulse

chkconfig --level 345 piranha-gui on

chkconfig --level 345 pulse on

/etc/init.d/pulse start. 这个命令特别关键,任何配置上的改动,都要用” /etc/init.d/pulse restart”来生效。

Routing server配置脚本:

$cd /opt

$vi vs-up.sh

#!/bin/bash

#Remember to change the IP for your needs:

ifconfig lo:0 9.125.91.254 netmask 255.255.255.255 broadcast

route add –host 9.125.91.254 dev lo:0

echo 1 > /proc/sys/net/ipv4/ip_forward

echo 1 > /proc/sys/net/ipv4/conf/all/hidden

LVSADM='/sbin/ipvsadm'

$LVSADM -C

$LVSADM -A -t 9.125.91.254:80 -s wlc

$LVSADM -a -t 9.125.91.254:80 -r 9.125.91.60:80 -g -w 1

#add more Apache server here according to your needs:

#$LVSADM -a -t 9.125.91.254:80 -r 9.125.91.55:80 -g -w 1

#$LVSADM -a -t 9.125.91.254:80 -r 173.17.17.7:80 -g -w 1

#$LVSADM -a -t 9.125.91.254:80 -r 173.17.17.8:80 -g -w 1

$chmod 755 vs-up.sh

$ ./vs-up.sh

此时Routing server的配置基本完成,在“/etc/init.d/pulse restart”让所有改动生效后,用一下两个命令检验设置:

$ ipvsadm

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 9.125.91.254:http wlc

->9.125.91.60:http Route 1 3 0

$ifconfig

eth0 Link encap:Ethernet HWaddr 00:11:25:97:1C:39

inet addr:9.125.91.239 Bcast:9.125.91.255 Mask:255.255.255.0

inet6 addr: fe80::211:25ff:fe97:1c39/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:19470 errors:0 dropped:0 overruns:0 frame:0

TX packets:11199 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:2114994 (2.0 MiB) TX bytes:1075789 (1.0 MiB)

Base address:0x2000 Memory:e8100000-e8120000

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:4085 errors:0 dropped:0 overruns:0 frame:0

TX packets:4085 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:6479927 (6.1 MiB) TX bytes:6479927 (6.1 MiB)

lo:0 Link encap:Local Loopback

inet addr:9.125.91.254 Mask:255.255.255.255

UP LOOPBACK RUNNING MTU:16436 Metric:1

如果看到这两个结果,Routing server就配好了。

Backend Apache Server配置

在后端的apache server仅需要简单配置:

对于我的环境,本机的IP:9.125.91.60 然后执行以下命令:

ifconfig lo:0 192.168.2.254 netmask 255.255.255.255 broadcast

route add -host 192.168.2.254 dev lo:0

用命令ifconfig查看:

$ifconfig

eth0 Link encap:Ethernet HWaddr 00:0D:60:AC:12:61

inet addr:9.125.91.60 Bcast:9.125.91.255 Mask:255.255.255.0

inet6 addr: fe80::20d:60ff:feac:1261/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:509766 errors:0 dropped:0 overruns:0 frame:0

TX packets:298381 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:186066463 (177.4 Mb) TX bytes:178428987 (170.1 Mb)

Base address:0x2000 Memory:e8100000-e8120000

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:5595 errors:0 dropped:0 overruns:0 frame:0

TX packets:5595 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:1146313 (1.0 Mb) TX bytes:1146313 (1.0 Mb)

lo:0 Link encap:Local Loopback

inet addr:9.125.91.254 Mask:255.255.255.255

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:509766 errors:0 dropped:0 overruns:0 frame:0

TX packets:298381 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:186066463 (177.4 Mb) TX bytes:178428987 (170.1 Mb)

到这里所有配置就完成了。

下面要进行验证:

验证

用任意机器访问http://9.125.91.254/, 可以拿到9.125.91.60的Apache Server回答就成功了。

未完结的事宜

其实在cluster架设到这里之后,还并不能达到正式应用的要求,实际应用中还有一些问题需要解决,比如要安装监视软件,监视集群的运作,要能及时发现 real server的故障并对应调整real server的列表。尤其是多台Apache server同时操作数据库,还有后台real server节点的数据一致性等问题,而如果应用MySQL cluser还把数据同步的问题进一步复杂化。这些在一些商用的cluster软件产品中就得到了很好的解决,而网络也有一些非商用的软件。还需要进行测试。

本文来源:https://www.bwwdw.com/article/rli1.html

Top