RedHat9实现集群负载均衡系统LVS

来源:互联网 发布:手机限制网速软件 编辑:程序博客网 时间:2024/04/29 03:59

工作步骤:下载内核源码和相关的软件包;把ipvs补丁Patch到内核源码中;重新编译支持ipvs的内核;启用新内核;安装ipvs管理工具ipvsadm;配置LVS,构建负载均衡集群。

(1)下载安装所需组件:

标准内核包linux-2.4.20-tar.gz,与内核匹配的软件ipvs-1.0.09.tar.gz
内核需要打的补丁,hidden-2.4.20per10-1.diff ,noarp-2.4.20-1.diff ,iproute-050816-noarp-1.diff

KTCPVS内核补丁包,

标准内核包可以在:www.kernel.org download;

其它所需组件可以在:www.linuxvirtualserver.org download;

安装平台Red hat 9.0 kernel linux-2.4.20-8

下载好的软件包可放置到/usr/src

命令执行过程:

#cd /usr/src

#tar -zxvf linux-2.4.20.tar.gz           把内核解压到/usr/src目录下

建立符号链接,由于ipvs-1.0.09Makefile文件中默认的安装路径是/usr/src/linux

#ln –s /usr/src/liunx-2.4.20/usr/src/linux  

(2)打补丁

#cd /usr/src

#tar –zxvf ipvs-1.0.09.tar.gz

#cd /usr/src/ipvs-1.0.9

IPVSPatch加载到kernelsource

#make patchkernel            给内核打ipvs补丁

#make installsource           ipvssource加进内核

加载 "hidden"patch

#cd /usr/src/linux  软件包hidden目录

#cat hidden-2.4.20pre10-1.diff | patch -p1

如果要使用vs/tul vs/dr功能需要按上面的方法打noarp-2.4.20-1.diff,iproute-050816-noarp-1.diff补丁。KTCPVS所涉及的layer-7补丁是在lvs内核编译通过后,使用新内核时加入。

(3)编译内核

# cp /boot/config-2.4.*  /usr/src/linux/.config

把安装时的配置文件copy/usr/src/linux中,再用make menuconfig编译,它会读取.config中原来的配置信息,这样只要对IP:Virtual ServerConfiguration中的新选项选择即可。

#make mrproper       去除如有上次已编译的*.o文件,如不去除就不会被再次编译

#make menuconfig     以文字菜单模式进行选择编译的配置

LVS相关的kernel选项都在“Networking options”中,进入“Networking options”,可以查看到“IP: Virtual Server Configuration”选项,将其它所有的子选项都选上:

<M> virtual server support (EXPERIMENTAL)
[*] IP virtual server debugging
(12) IPVS connection table size (the Nth power of 2)
--- IPVS scheduler
<M> round-robin scheduling
<M> weighted round-robin scheduling
<M> least-connection scheduling scheduling
<M> weighted least-connection scheduling
<M> locality-based least-connection scheduling
<M> locality-based least-connection with replication scheduling
<M> destination hashing scheduling
<M> source hashing scheduling
<M> shortest expected delay scheduling
<M> never queue scheduling
--- IPVS application helper
<M> FTP protocol helper

如果使用Standard Kernel,make menuconfig 时可能在Networking op
tions
选项中找不到IP:Virtual Server Configuration选项,这是因为没有选中Network
packet filtering
选项.

#make dep       建立选项中模块部分的相依属性关系

#make clean     去除旧的数据,就是上一次编译的目标文件

#make bzImage  开始编译压缩过的核心,这个步骤时间长些,跟硬件配置和内核选择有关,大概20分钟

#make modules  编译模块,这个步骤时间长些,我的大约50分钟(笑)

#make modules_install  安装模块到/lib/modules/2.4.20

4)启用新内核

手动加载新内核

#mkinitrd /boot/initrd-2.4.20ipvs.img 2.4.20            创建initrd映像,用于两个阶段引导

#cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz-2.4.20ipvs  拷贝压缩内核

#cd /boot

#rm vmlinuz删除符号链接

#ln –s vmlinuz-2.4.20ipvs vmlinuz建立符号链接

#cp /usr/src/linux/System.map /boot/System.map-2.4.20ipvs     系统地图

#cd /boot

#rm System.map

#ln –s System.map-2.4.20ipvs System.map     建立系统地图连接

修改grub文件/boot/grub//etc下修改都可以在grub.conf文件中加入如下设置

#vi  /etc/

加入下面的文字,并修改默认引导项 default=1

title LVS-linux (2.4.20)
root (hd0,0)
kernel /boot/vmlinuz-2.4.20ipvs ro root=LABEL=/

initrd /boot/initrd-2.4.20ipvs.img

然后重新启动,选择新内核就可支持最新的ipvs

(5)安装ipvs管理工具ipvsadm

当使用了支持ipvs的内核后,就可以安装ipvsadmipvsadm是设置ipvs转发方式和调度算法的工具

#tar xzvf ipvsadm-1.21.tar.gz

#cd ./ipvsadm-1.21

#make
#make install

安装完成后,执行ipvsadm命令,如果有如下信息出现则说明安装成功了。

IP Virtual Server version 1.0.8 (size=65536)   

Prot LocalAddress:Port Scheduler Flags   

-> RemoteAddress:Port         Forward Weight ActiveConn InActConn

进一步的LVS配置以后继续学习。

原创粉丝点击