不同主机配置不同的downSpeedVal教程
云计算
不同主机配置不同的downSpeedVal教程
2025-04-18 00:04
ubuntu
以下是为不同主机配置不同下载速度限制(downSpeedVal
)的详细教程,适用于常见下载工具及系统级流量控制场景:
一、使用 aria2
配置不同主机的下载速度 🚀
aria2
是一款轻量级多协议下载工具,支持按任务或主机设置限速。
1. 安装 aria2
sudo yum install aria2 -y # CentOS/RHEL
sudo apt install aria2 -y # Debian/Ubuntu
2. 配置多主机限速
编辑配置文件 /etc/aria2/aria2.conf
或用户目录下的 aria2.conf
:
# 全局默认限速(KB/s)
max-overall-download-limit = 0 # 0 表示不限速
# 为特定主机设置限速(示例)
[[Download]]
enabled=true
dir=/downloads
# 主机1(IP或域名)限速 1MB/s(即 1024KB/s)
server=192.168.1.100
max-download-limit=1024
[[Download]]
enabled=true
dir=/downloads
# 主机2限速 512KB/s
server=example.com
max-download-limit=512
3. 启动或重启 aria2
aria2c --conf-path=/path/to/aria2.conf # 启动
sudo systemctl restart aria2 # 系统服务重启
二、通过 iptables
实现基于IP的流量控制 🛡️
使用 iptables
和 tc
(流量控制工具)为不同IP设置下载速度限制。
1. 安装工具
sudo yum install iproute-tc -y # CentOS
sudo apt install iproute2 -y # Debian/Ubuntu
2. 配置限速规则
假设需限制 192.168.1.100
下载速度为 1MB/s,192.168.1.101
为 512KB/s:
# 清除原有规则(谨慎操作)
tc qdisc del dev eth0 root
# 创建根队列
tc qdisc add dev eth0 root handle 1: htb default 10
# 定义主类(总带宽)
tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit
# 为IP1(192.168.1.100)创建子类,限速1MB/s(即 8Mbit)
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 8mbit
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.1.100 flowid 1:10
# 为IP2(192.168.1.101)创建子类,限速512KB/s(即4Mbit)
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 4mbit
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.1.101 flowid 1:11
3. 验证配置
tc -s qdisc show dev eth0
tc -s class show dev eth0
三、使用 Transmission
设置不同种子的限速 🌐
Transmission
是BT下载工具,支持按任务或全局设置限速。
1. 安装 Transmission
sudo yum install transmission-daemon -y # CentOS
sudo apt install transmission-daemon -y # Debian/Ubuntu
2. 配置多任务限速
编辑配置文件 /etc/transmission-daemon/settings.json
:
{
"speed-limit-down": 0, // 全局默认下载限速(KB/s)
"speed-limit-down-enabled": false,
"alt-speed-down": 512, // 备用限速(如非高峰时段)
"speed-limit-mode": 0 // 0=全局,1=备用
}
3. 按任务设置限速
通过 Web 界面(http://IP:9091
):
- 进入任务详情页。
- 勾选“使用备用速度限制”或手动输入单任务限速值。
四、使用 wget
或 curl
的临时限速 🔄
对于单次下载任务,可通过命令行参数临时设置速度。
1. wget
限速示例
wget --limit-rate=1m http://example.com/file.zip # 限速1MB/s
wget --limit-rate=512k http://another.com/largefile.iso # 限速512KB/s
2. curl
限速示例
curl --limit-rate 1M -O http://example.com/file.zip
curl --rate-limit 512K -O http://another.com/largefile.iso
五、注意事项与故障排查 ⚠️
- 配置生效验证:
- 使用
iftop
或 nload
实时监控带宽使用情况。
- 确保防火墙(如
firewalld
)未拦截相关端口。
- 优先级与冲突:
- 若全局限速与单任务限速同时存在,以较低值为准。
tc
规则需避免与其他网络管理工具冲突。
- 持久化配置:
tc
规则重启后失效,可通过脚本加入 rc.local
或 systemd 服务实现开机启动。
六、总结 📌
- aria2:适合复杂场景,支持多任务/主机精细控制。
- iptables+tc:系统级限速,适用于服务器流量管理。
- Transmission/wget/curl:轻量级工具,适合单任务或临时需求。
根据实际需求选择方案,建议先在测试环境中验证配置,避免影响正常网络服务。
标签:
- downSpeedVal