RHEL6如何限制自己某个端口的上传带宽

juaby 2011-11-28 09:30:03
需求背景:
某项目,全国各地区部署分服务器,中心部署总服务器,分服务器24小时不间断的向中心服务器传输文件,单个 文件150K左右,地区到中心网络带宽2M,要求地区服务器向中心服务器传输文件所占用的带宽在512Kb以内,512/8,根据此需求,我在互联网搜肠刮肚,找到了wondershaper,其实就是iptables+tc的脚本,我目前是可以限制上传下载的带宽了,但是不幸的是,地区分服务器也是服务器,也部署了应用软件,客户端和他通信的时候,由于带宽限制了 ,所以很慢,wondershaper能否仅仅针对某个端口的上传带宽进行限制,望各位大侠指点,下面是我所做的,
操作系统:RHEL6
目标软件:wondershaper_1.1a-6_all.deb
依赖软件:
http://kitenet.net/~joey/code/alien/,下载alien_8.86.tar.gz
perl.x86_64 perl-devel.x86_64 (解决MakeMake.PL)(64位OS,32位同理)
安装步骤:
第一步,下载需要的软件及依赖软件
第二步,安装alien
1、http://kitenet.net/~joey/code/alien/,下载alien_8.83.tar.gz
2、yum install perl.x86_64 perl-devel.x86_64 (解决MakeMake.PL)
3、tar -zxvf alien_8.86.tar.gz
4、cd alien
5、perl Makefile.PL
6、make
7、make install
8、yum install rpmdevtools (解决rpmbulid)
第三部,deb转rpm
1、alien -r wondershaper_1.1a-6_all.deb,得到wondershaper-1.1a-7.noarch.rpm
2、yum localinstall PPStream-1.0.0-2.i386.rpm --nogpgcheck(解决依赖关系)
第四部,软件使用
启用 wondershaper eth0 1000 200
关闭 wondershaper clear eth0
查看 wondershaper eth0
附件:wondershaper 脚本,看着此脚本我脑袋疼
#!/bin/sh

# Wonder Shaper

# Modifications by Vince Mulhollon for debian package

if [ $# -eq 0 ]; then
echo Please read the man page for the wondershaper and
echo the file /usr/share/doc/wondershaper/README.Debian.gz
exit
fi

if [ $# -eq 1 ]; then
/sbin/tc -s qdisc ls dev $1
/sbin/tc -s class ls dev $1
exit
fi

if [ $# -eq 2 ]; then
/sbin/tc qdisc del dev $2 root 2> /dev/null > /dev/null
/sbin/tc qdisc del dev $2 ingress 2> /dev/null > /dev/null
echo Wondershaper queues have been cleared.
exit
fi

if [ $# -ne 3 ]; then
echo Please read the man page for the wondershaper and
echo the file /usr/share/doc/wondershaper/README.Debian.gz
exit
fi

# please read the README before filling out these values
#
# Set the following values to somewhat less than your actual download
# and uplink speed. In kilobits. Also set the device that is to be shaped.
DOWNLINK=$2
UPLINK=$3
DEV=$1

# low priority OUTGOING traffic - you can leave this blank if you want
# low priority source netmasks
NOPRIOHOSTSRC=

# low priority destination netmasks
NOPRIOHOSTDST=

# low priority source ports
NOPRIOPORTSRC=

# low priority destination ports
NOPRIOPORTDST=

# Now remove the following two lines :-)

#echo Please read the documentation in 'README' first :-\)
#exit

#########################################################

#if [ "$1" = "status" ]
#then
# /sbin/tc -s qdisc ls dev $DEV
# /sbin/tc -s class ls dev $DEV
# exit
#fi


# clean existing down- and uplink qdiscs, hide errors
/sbin/tc qdisc del dev $DEV root 2> /dev/null > /dev/null
/sbin/tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null

#if [ "$1" = "stop" ]
#then
# exit
#fi

###### uplink

# install root CBQ

/sbin/tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit

# shape everything at $UPLINK speed - this prevents huge queues in your
# DSL modem which destroy latency:
# main class

/sbin/tc class add dev $DEV parent 1: classid 1:1 cbq rate ${UPLINK}kbit \
allot 1500 prio 5 bounded isolated

# high prio class 1:10:

/sbin/tc class add dev $DEV parent 1:1 classid 1:10 cbq rate ${UPLINK}kbit \
allot 1600 prio 1 avpkt 1000

# bulk and default class 1:20 - gets slightly less traffic,
# and a lower priority:

/sbin/tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $((9*$UPLINK/10))kbit \
allot 1600 prio 2 avpkt 1000

# 'traffic we hate'

/sbin/tc class add dev $DEV parent 1:1 classid 1:30 cbq rate $((8*$UPLINK/10))kbit \
allot 1600 prio 2 avpkt 1000

# all get Stochastic Fairness:
/sbin/tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
/sbin/tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
/sbin/tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10

# start filters
# TOS Minimum Delay (ssh, NOT scp) in 1:10:
/sbin/tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
match ip tos 0x10 0xff flowid 1:10

# ICMP (ip protocol 1) in the interactive class 1:10 so we
# can do measurements & impress our friends:
/sbin/tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 \
match ip protocol 1 0xff flowid 1:10

# pablo.iranzo@uv.es provided a patch for the MLDonkey system
# The MLDonkey uses small UDP packets for source propogation
# which floods the wondershaper out.
/sbin/tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
match ip protocol 17 0xff \
match ip sport 4666 0xffff \
flowid 1:30

# prioritize small packets (<64 bytes)

/sbin/tc filter add dev $DEV parent 1: protocol ip prio 12 u32 \
match ip protocol 6 0xff \
match u8 0x05 0x0f at 0 \
match u16 0x0000 0xffc0 at 2 \
flowid 1:10


# some traffic however suffers a worse fate
for a in $NOPRIOPORTDST
do
/sbin/tc filter add dev $DEV parent 1: protocol ip prio 14 u32 \
match ip dport $a 0xffff flowid 1:30
done

for a in $NOPRIOPORTSRC
do
/sbin/tc filter add dev $DEV parent 1: protocol ip prio 15 u32 \
match ip sport $a 0xffff flowid 1:30
done

for a in $NOPRIOHOSTSRC
do
/sbin/tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \
match ip src $a flowid 1:30
done

for a in $NOPRIOHOSTDST
do
/sbin/tc filter add dev $DEV parent 1: protocol ip prio 17 u32 \
match ip dst $a flowid 1:30
done

# rest is 'non-interactive' ie 'bulk' and ends up in 1:20

/sbin/tc filter add dev $DEV parent 1: protocol ip prio 18 u32 \
match ip dst 0.0.0.0/0 flowid 1:20


# 这里是从网上参考别人的
# 不限制内网从本服务器下载。
# 注意如本服务器上有代理,用户可通过代理绕过带宽限制,
# 可取消以下三句限制从本服务器下载。
#/sbin/tc class add dev $DEV parent 1:1 classid 1:40 cbq bandwidth 100Mbit rate 95Mbit allot 1514 weight 20Kbit prio 5 maxburst 20 avpkt 1000 bounded
#/sbin/tc qdisc add dev $DEV parent 1:40 sfq quantum 1514b perturb 10
#/sbin/tc filter add dev $DEV parent 1:0 protocol ip prio 19 u32 match ip src 10.125.221.152 flowid 1:10


########## downlink #############
# slow downloads down to somewhat less than the real speed to prevent
# queuing at our ISP. Tune to see how high you can set it.
# ISPs tend to have *huge* queues to make sure big downloads are fast
#
# attach ingress policer:

/sbin/tc qdisc add dev $DEV handle ffff: ingress

# filter *everything* to it (0.0.0.0/0), drop everything that's
# coming in too fast:

/sbin/tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1

...全文
266 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
FTP服务器配置 VSFTP主配置文件路径:/etc/vsftpd/vsftpd.conf,重要参数: anonymous_enable=yes/no 是否允许匿名用户访问 anon_upload_enable=yes/no 是否允许匿名用户上传文件 anon_mkdir_write_enable=yes/no 是否允许匿名用户创建目录 anon_other_write_enable=yes/no 匿名用户和虚拟用户是否拥有删除权限 local_enable=yes/no 是否允许本地用户登陆 write_enable=yes/no 设置全局是否可写 anon_root=/var 指定匿名用户目录 chroot_local_user=yes 锁定所有用户到用户主目录 chroot_list_enable=yes/no 锁定列表中的用户到主目录,需要配合下一参数使用 chroot_list_file=/etc/vsftpd/chroot_list 指定存储被锁定用户的列表文件位置 chown_uploads=yes/no 匿名用户上传所有者指定功能,需要与下一参数配合使用 chown_username=用户名 指定匿名用户上传文件的所有者 max_clients=300 最大客户端连接数为300 anon_max_rate=30000 匿名用户和虚拟用户限速为30K/S local_max_rate=30000 本地用户限速为30K/S max_per_ip=10 每个IP最大连接数 listen_port=22 更改监听端口 实现如下要求:允许匿名用户登陆,匿名用户限速为60K/S,只允许下载。监听端口为22,最大连接数为10。新建用户ftp1,限速为200K/S,允许上传下载删除新建文件夹。进入目录/etc/vsftpd,用vi编辑器打开vsftpd.conf主配置文件: 直接添加以下选项: [root@LidadeFedora vsftpd]# service vsftpd restart 添加用户ftp1,设置登录脚本为 /sbin/nologin: vsftp默认目录为:/var/ftp,为方便测试,在/var/ftp下新建一个文件"testLocal",在"/var/ftp/pub"新建一个文件"testAnon"。 由于使用root用户新建文件,文件的所有者为root,所以需要把文件的权限设置为644其他用户才能读取该文件 设置/var/ftp/pub权限为777,表示所有用户均有读写权限. 由于端口22被ssh服务器占用,所以需要关闭ssh服务并重启vsftp服务。 客户端用Flashfxp测试:新建站点"VsftpTest",输入Vsftp服务器的IP地址,端口填22,用户名填ftp1,密码填你设置的密码,然后点击"连接"按钮: 由于没有使用选项:local_root,登陆本地用户时自动跳转到该用户的主目录.没有使用chroot_local_user=yes,所以本地用户可以浏览整个文件系统中他有权限读取的文件和文件夹: 切换到目录"/var/ftp/pub",该目录的权限为777,上传一个10M以上的文件,测试ftp1的上传速度: 新建文件夹和删除权限测试省略。下面测试匿名用户权限:勾选"匿名"选项并连接: 匿名用户登陆成功: 进入pub目录,尝试删除testAnon文件失败,说明这里是配置文件中的anon_other_write_enable=no生效了。最终权限等于配置文件中的权限和linux文件系统权限相或的结果。比如vsftp配置文件中允许匿名用户下载,但光这样是不够的,还需要被下载的文件或文件夹的能够被其他用户读取。 尝试上传文件失败,符合匿名用户只允许下载的要求: 最后测试匿名用户的下载速度: vsftp的配置

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧