Jun 2

[原]编译IMQ(中介队列设备)模块 雷阵雨

linuxing , 14:33 , 基础知识 » RPM , 评论(0) , 引用(0) , 阅读(55218) , Via 本站原创 | |
   IMQ(Intermediate queueing device)中介队列设备通常用于解决两个问题:
引用
入口整形:
Linux仅能进行出口整形(除入口队列可限速外),而IMQ能让您使用出口队列对入口数据进行整形。
对多个网卡整形:
一个队列规定只能处理一块网卡的流量,无法设置全局的限速。而IMQ允许您使用iptables标记那些给队列看的数据包,达到全局限速的目的。

   简单来说,IMQ可以让你往一个队列规定中放任何东西,例如对刚刚进入网卡的数据包打上标记去进行入口整形等。但由于一些原因,IMQ设备并没有加入Linux的标准核心中,所以,使用前需要先单独编译。

一、运行平台
关于最新的IMQ patch见这里:Linux IMQ - Intermediate Queueing Device,其中包括新核心使用的IMQ patch补丁,以及iptables设别imq设备的补丁。不同的核心版本需要的补丁不同,请根据您运行的环境决定。
以红旗DC Server 5.0 sp2为例,核心为2.6.9-42.7AX。
kernel补丁为:下载
iptables补丁为:下载

二、编译核心模块
1、准备原核心的Makefile文件
这一步的作用是,让编译出来的模块核心版本和当前版本是一致的。(若使用默认Makefile,则版本是EXTRAVERSION = -42.7AXcustom,模块会加载不上去)
引用
# uname -r
2.6.9-42.7AX
# cd /usr/src/linux-2.6.9-42.7AX/
# mv Makefile Makefile.old
# cp /lib/modules/2.6.9-42.7AX/build/Makefile ./

2、打imq核心补丁
引用
# patch -p1 < /home/hyphen/linux-2.6.9-imq1.diff
patching file drivers/net/Kconfig
patching file drivers/net/Makefile
Hunk #1 succeeded at 117 (offset 4 lines).
patching file drivers/net/imq.c
patching file include/linux/imq.h
patching file include/linux/netfilter_ipv4/ipt_IMQ.h
patching file include/linux/netfilter_ipv6/ip6t_IMQ.h
patching file include/linux/skbuff.h
patching file net/ipv4/netfilter/Kconfig
patching file net/ipv4/netfilter/Makefile
patching file net/ipv4/netfilter/ipt_IMQ.c
patching file net/ipv6/netfilter/Kconfig
patching file net/ipv6/netfilter/Makefile
patching file net/ipv6/netfilter/ip6t_IMQ.c
patching file net/sched/sch_generic.c

3、引用原核心config文件,增加IMQ配置

# make mrproper (初始化编译环境)
# cp /boot/config-2.6.9-42.7AX ./.config

原核心的配置文件,一般都放在boot目录下。然后,可以选择IMQ的配置。

#make menuconfig

从下面地方选择:
引用
IMQ (intermediate queueing device) support (IMQ)
Location:
   -> Device Drivers
    -> Networking support
     -> Network device support (NETDEVICES)
      -> IMQ (intermediate queueing device) support (IMQ)

选择<M>编译为模块后,有两个参数可以设置:
引用
Number of IMQ devices (IMQ_NUM_DEVS):默认IMQ设备的数量
IMQ behavior (PRE/POSTROUTING):IMQ的处理方法在nat表的勾取位置
默认是BA,也就是:PREROUTING(Before NAT),POSTROUTING(After NAT),可根据实际情况选择。

接下来是NETFILTER部分的选择:
引用
IMQ target support (IP_NF_TARGET_IMQ)
Location:
 -> Device Drivers
  -> Networking support
   -> Networking support (NET)
    -> Networking options
     -> Network packet filtering (replaces ipchains) (NETFILTER)
      -> IP: Netfilter Configuration

另外,IPv6也是可选的:
引用
IPv6: Netfilter Configuration

保存后,可查看新增加的配置:
引用
# cat .config|grep IMQ
CONFIG_IP_NF_TARGET_IMQ=m
CONFIG_IP6_NF_TARGET_IMQ=m
CONFIG_IMQ=m
# CONFIG_IMQ_BEHAVIOR_AA is not set
# CONFIG_IMQ_BEHAVIOR_AB is not set
CONFIG_IMQ_BEHAVIOR_BA=y
# CONFIG_IMQ_BEHAVIOR_BB is not set
CONFIG_IMQ_NUM_DEVS=2

完成后的配置文件如下:
(只适用于DC Server 5.0 sp2 for x86 单核心环境,仅供参考)

4、编译核心镜像
由于增加了IMQ设备,核心中设备表有改变,所以需要重新编译新的核心镜像。
引用
# make bzImage
......
BUILD   arch/i386/boot/bzImage
Root device is (3, 3)
Boot sector 512 bytes.
Setup is 5018 bytes.
System is 1478 kB
Kernel: arch/i386/boot/bzImage is ready

拷贝到启动目录:
引用
# cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.9-42.7AX_new
# cp /boot/System.map-2.6.9-42.7AX /boot/System.map-2.6.9-42.7AX_new

5、编译模块
根据patch修改的文件,编译对应的模块。
首先,是编译IMQ网卡设备:

# make clean
# make modules_prepare
# make SUBDIRS='drivers/net/' modules
# make SUBDIRS='drivers/net/' modules_install

※SUBDIRS可指定含源码的目录,即只编译该目录中的模块。也可以这样运行:
引用
# make M=drivers/net/

接着,加载模块,测试:

# insmod drivers/net/imq.ko numdevs=2

激活设备:

# ifconfig imq0 up
# ifconfig imq1 up

若没问题,则继续编译netfilter及ipv4、ipv6等模块:

# make SUBDIRS='net/ipv4/' modules && make SUBDIRS='net/ipv4/' modules_install
# make SUBDIRS='net/ipv6/' modules && make SUBDIRS='net/ipv6/' modules_install
# make SUBDIRS='net/sched/' modules && make SUBDIRS='net/sched/' modules_install
# depmod -a

☆当然,你也可以直接运行make modules && make modules_install,编译所有的模块,但这个时间很长。
若你按上面的步骤编译后,发现原有的模块有问题,建议你把全部模块都编译吧。安装后的驱动模块,会放在/lib/modules/(核心名称)/kernel/目录中。


6、生成initrd文件

# cd /boot/
# mkinitrd initrd-2.6.9-42.7AX_new.img `uname -r`

7、修改Grub
修改/boot/grub/menu.lst,让其从新核心默认启动:
引用
title Asianux 2.0 SP2 new (2.6.9-42.7AX_new)
       root (hd0,2)
       kernel /boot/vmlinuz-2.6.9-42.7AX_new ro root=LABEL=/
       initrd /boot/initrd-2.6.9-42.7AX_new.img

※注意,千万记得改为从新核心启动,否则,旧核心加载模块时,可能会发生kernel panic错误的。
内文分页: [1] [2] [3]
Tags: , , , ,
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]