AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 764777
Accepted
Abc Xyz
Abc Xyz
Asked: 2016-03-20 04:17:58 +0800 CST2016-03-20 04:17:58 +0800 CST 2016-03-20 04:17:58 +0800 CST

流量控制 - 使用 scp 批量下载使 sshd 滞后

  • 772

我的目标是使用 tc、IMQ 接口和 iptables 限制每个系统用户的带宽。现在我遇到了批量下载(即 scp)的问题,这会在 ssh 服务器等交互式程序上造成延迟。

这是我的配置:

# UPLOAD # OUTBOUND #
tc qdisc add dev imq0 root handle 1:0 htb default 11
  tc class add dev imq0 parent 1:0 classid 1:1  htb rate 700kbit ceil 700kbit
  tc class add dev imq0 parent 1:1 classid 1:10 htb rate 450kbit ceil 700kbit prio 0
  tc class add dev imq0 parent 1:1 classid 1:11 htb rate 250kbit ceil 250kbit prio 1
  tc filter add dev imq0 parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10
  tc filter add dev imq0 parent 1:0 prio 1 protocol ip handle 11 fw flowid 1:11

# DOWNLOAD # INBOUND #
tc qdisc add dev imq1 root handle 2:0 htb default 11
  tc class add dev imq1 parent 2:0 classid 2:2  htb rate 7000kbit ceil 7000kbit
  tc class add dev imq1 parent 2:1 classid 2:10 htb rate 4500kbit ceil 7000kbit prio 0
  tc class add dev imq1 parent 2:1 classid 2:11 htb rate 2500kbit ceil 2500kbit prio 1
  tc filter add dev imq1 parent 2:0 prio 0 protocol ip handle 10 fw flowid 2:10
  tc filter add dev imq1 parent 2:0 prio 1 protocol ip handle 11 fw flowid 2:11

iptables -t mangle -A PREROUTING -i eth0 -j IMQ --todev 1
iptables -t mangle -A PREROUTING -j CONNMARK  --restore-mark

iptables -t mangle -N IMQ-OUT
iptables -t mangle -A POSTROUTING -o eth0 -j IMQ-OUT
  iptables -t mangle -A IMQ-OUT -p tcp -m length --length :64 -j MARK --set-mark 10
  iptables -t mangle -A IMQ-OUT -p tcp -m length --length :64 -j RETURN
  iptables -t mangle -A IMQ-OUT -m owner --uid-owner root -j MARK --set-mark 10
  iptables -t mangle -A IMQ-OUT -m owner --uid-owner root -j RETURN
  iptables -t mangle -A IMQ-OUT -m owner --uid-owner test1 -j MARK --set-mark 11
  iptables -t mangle -A IMQ-OUT -m owner --uid-owner test1 -j RETURN
iptables -t mangle -A POSTROUTING -j CONNMARK  --save-mark
iptables -t mangle -A POSTROUTING -o eth0 -j IMQ --todev 0

执行配置后分类和过滤:

tc class show dev imq0
class htb 1:11 parent 1:1 prio 1 rate 250000bit ceil 700000bit burst 1599b cburst 1599b 
class htb 1:10 parent 1:1 prio 0 rate 450000bit ceil 700000bit burst 1600b cburst 1599b 
class htb 1:1 root rate 700Kbit ceil 700Kbit burst 1600b cburst 1600b

tc filter show dev imq0
filter parent 1: protocol ip pref 1 fw 
filter parent 1: protocol ip pref 1 fw handle 0xb classid 1:11 
filter parent 1: protocol ip pref 49152 fw 
filter parent 1: protocol ip pref 49152 fw handle 0xa classid 1:10

试图像这样用 sfq 添加 qdisc

#  tc qdisc add dev imq0 parent 1:10 handle 10:0 sfq perturb 10
#  tc qdisc add dev imq0 parent 1:11 handle 11:0 sfq perturb 10
#  tc qdisc add dev imq1 parent 2:10 handle 10:0 sfq perturb 10
#  tc qdisc add dev imq1 parent 2:11 handle 11:0 sfq perturb 10

但它的作用是冻结我的电脑(需要重新启动)。

我是这个主题的新手,任何帮助表示赞赏。

tc
  • 2 2 个回答
  • 252 Views

2 个回答

  • Voted
  1. setenforce 1
    2016-03-20T04:44:59+08:002016-03-20T04:44:59+08:00

    您可以使用 connbytes tc 选项。它将计算连接、上传和下载的总字节数。

    例如,scp 问题可以这样解决:

    iptables -t mangle -A IMQ-OUT -p tcp --dport 22 -m connbytes --connbytes 10000000: --connbytes-dir both --connbytes-mode bytes -m owner --uid-owner root -j MARK --set-mark 11
    
    iptables -t mangle -A IMQ-OUT -p tcp !  --dport 22  -m owner --uid-owner root -j MARK --set-mark 10
    iptables -t mangle -A IMQ-OUT -p udp -m owner --uid-owner root -j MARK --set-mark 10
    iptables -t mangle -A IMQ-OUT -p icmp -m owner --uid-owner root -j MARK --set-mark 11
    

    将上面的行代替这一行:

    iptables -t mangle -A IMQ-OUT -m owner --uid-owner root -j MARK --set-mark 10
    

    虽然,您需要注意“restore-mark”和“save-mark”,但您不希望恢复 TCP/22 10 标记,您希望 connbyte 计数并在标记之前做出决定。

    然后,您可以通过以下方式更改此行:

    iptables -t mangle -A PREROUTING -j CONNMARK  --restore-mark
    

    变成:

    iptables -t mangle -A PREROUTING -p tcp ! --dport 22 -j CONNMARK  --restore-mark
    iptables -t mangle -A PREROUTING -p udp -j CONNMARK  --restore-mark
    iptables -t mangle -A PREROUTING -p icmp -j CONNMARK  --restore-mark
    
    • 1
  2. Best Answer
    Abc Xyz
    2016-03-23T06:14:18+08:002016-03-23T06:14:18+08:00

    我正在研究这个问题,所以:

    我必须添加另一个 tc 类来下载和上传,让我们称它们为交互式类并添加过滤器

    tc filter add dev imq0 protocol ip parent 1:0 prio 1 u32 match ip tos 0x10 0xff  flowid 1:12
    tc filter add dev imq1 protocol ip parent 2:0 prio 1 u32 match ip tos 0x10 0xff  flowid 2:12
    

    并更改为较低的优先级

    tc filter add dev imq0 parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10
    tc filter add dev imq0 parent 1:0 prio 0 protocol ip handle 11 fw flowid 1:11
    tc filter add dev imq1 parent 2:0 prio 0 protocol ip handle 10 fw flowid 2:10
    tc filter add dev imq1 parent 2:0 prio 0 protocol ip handle 11 fw flowid 2:11
    

    现在非批量流量到 up1:12 down2:12,不再有滞后问题。

    • 0

相关问题

  • 基于 linux 的整形器能够处理多少流量

  • 使用 Linux 调整出站流量以控制下载速度

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve