歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> redhat7 上安裝dummynet

redhat7 上安裝dummynet

日期:2017/3/3 13:08:40   编辑:Linux技術
更多請訪問 http://www.webpersonaldeveloper.cn

摘要:

在redhat 上部署dummynet 需要將ipfw 編譯為內核模塊,而ipfw需要調用linux kernel的一些函數。
linux kernel版本在不斷提升,相關的數據結構也在變化。所以可能需要根據你要部署的系統內核版本,來調整參數

提醒

如果你要部署在Redhat6,CentOS6等內核版本比較低的平台,不必參考下面的部署流程。
這篇文章就可以滿足的你要求
http://xmodulo.com/how-to-install-dummynet-on-centos.html
如果遇到問題,再返回這篇進一步學習

dummynet簡介

dummynet 是linux下面(現在也可以部署在window下)一款開源的網絡帶寬控制工具,
在網站上線前,可能需要測試帶寬對站點的影響。而dummynet就是為此而生。

部署流程

准備內核版本
參看系統內核版本
uname -r

我們需要將IPFW編譯成內核模塊,請確保
IPFW用到的內核源碼版本同你LINUX系統運行內核版本一致。
我的linux系統版本redhat7.2,內核版本3.10.0-327.13.1.el7.x86_64
下載此版本的內核源碼包
kernel-3.10.0-327.13.1.el7.src.rpm
http://vault.centos.org/7.2.1511/updates/Source/SPackages/
使用wget或者直接下載放在/usr/src/kernels 目錄
解壓源碼包
`
rpm2cpio kernel-3.10.0-327.13.1.el7.src.rpm |cpio -div
tar xvf linux-3.10.0-327.13.1.el7.tar.xz
cd 3.10.0-327.13.1.el7.x86_64
make oldconfig
make prepare
make scripts
`
編譯dummynet
[code]git clonehttps://github.com/FS1360472174/dummynet.git cd dummynet
make KERNELPATH=/usr/src/kernels/3.10.0-327.13.1.el7.x86_64

加載ipfw 模塊
[code]cd kipfw-mod
insmod ipfw-mod.ko
cd dummy/ipfw
cp ipfw /sbin
chmod 700 /sbin/ipfw

驗證ipfw
[code]ipfw add pipe 2 in proto tcp

optional,將ipfw 設置為boot啟動
[code] cp ipfw_mod.ko /lib/modules/3.10.0-327.13.1.el7.x86_64/kernel/net/netfilter
 depmod
 sh -c 'echo modprobe ipfw_mod >> /etc/rc.modules'
 chmod +x /etc/rc.modules

問題分析

1.insmod: ERROR: could not insert module ipfw_mod.ko: Invalid module format
解決:
modinfo ipfw_mod.ko 看下vermagic版本是不是uname -r的版本。
然後重新編譯ipfw 模塊
[code]make KERNELPATH=/usr/src/kernels/3.10.0-327.13.1.el7.x86_64

2.ipfw: getsockopt(IP_FW_ADD): Protocol not available
解決:
ipfw 模塊未加載到內核
可以
lsmod |grep ipfw
看下
需要重述上述步驟,將ipfw編譯進內核模塊
3.編譯模塊時報錯
類似於ipfw2_mod.c line 848 nf_hook_ops.hk struct have erors.
解決:
Hook structure 在各個版本的linux中定義不一樣,所以如果是從dummynet 站點中下載的
老的dummynet 包或者從這個download下來的包可能就有錯誤。
https://github.com/luigirizzo/dummynet
建議你查看下當前所用系統的hook 結構
/usr/src/kernels/linux-3.10.0-327.4.5.el7/include/linux/netfilter.h
定義了nf_hook_ops,nf_hookfn的結構
struct nf_hook_ops {
struct list_head list;
[code]    /* User fills in from here down. */
    nf_hookfn       *hook;
    struct module   *owner;
    void            *priv;
    u_int8_t        pf;
    unsigned int    hooknum;
    /* Hooks are ordered in ascending priority. */
    int             priority;

    /* Reserved for use in the future RHEL versions. Set to zero. */
    unsigned long   __rht_reserved1;
    unsigned long   __rht_reserved2;
    unsigned long   __rht_reserved3;
    unsigned long   __rht_reserved4;
    unsigned long   __rht_reserved5;
};

typedef unsigned int nf_hookfn(const struct nf_hook_ops *ops,
   struct sk_buff *skb,
   const struct net_device *in,
   const struct net_device *out,
#ifndef __GENKSYMS__
   const struct nf_hook_state *state
#else
   int (*okfn)(struct sk_buff *)
#endif
   );

參考:
http://vault.centos.org/7.2.1511/updates/Source/SPackages/kernel-3.10.0-327.4.5.el7.src.rpm
https://www.rpmfind.net/linux/RPM/centos/updates/7.2.1511/x86_64/Packages/kernel-3.10.0-327.13.1.el7.x86_64.html
http://xmodulo.com/how-to-install-dummynet-on-centos.html
https://access.redhat.com/articles/3078
Copyright © Linux教程網 All Rights Reserved