若需在CentOS上限制FileZilla Server的帶寬,可通過FileZilla Server自身配置(推薦,直接針對FTP服務)或系統級工具(如tc
、trickle
,適用于全局或特定進程)實現。以下是具體步驟:
FileZilla Server內置了帶寬限制功能,可全局或按用戶/組設置上傳/下載速度上限,操作簡便且針對性強。
登錄FileZilla Server管理界面
使用管理員賬號登錄FileZilla Server(默認端口:14147,若修改過需使用自定義端口)。
進入全局速度限制設置
在左側導航欄點擊Edit(編輯)→ Global Settings(全局設置),展開**Speed Limits(速度限制)**選項。
設置全局帶寬限制
保存并重啟服務
點擊OK保存配置,重啟FileZilla Server使設置生效(通過systemctl restart filezilla_server
命令)。
注:若需針對特定用戶/組設置,可進入Users(用戶)→ Groups(組),選擇對應組或用戶,在Speed Limits tab中單獨配置。
若需全局控制FTP流量(如不影響其他服務),可使用tc
(Traffic Control,Linux內核自帶)或trickle
(輕量級進程限速工具)。
tc
命令(精準控制FTP流量)tc
通過流量整形(Traffic Shaping)限制指定網絡接口的帶寬,適用于需要精細化管理的場景。
iproute
(含tc
工具)iproute
,若未安裝可通過sudo yum install iproute
安裝。eth0
(通過ip a
命令確認),限制FTP帶寬為1Mbps(下載)/512Kbps(上傳):# 清空現有隊列規則
sudo tc qdisc del dev eth0 root 2>/dev/null
# 添加HTB根隊列(默認類為1:10,帶寬1Mbps)
sudo tc qdisc add dev eth0 root handle 1: htb default 10
sudo tc class add dev eth0 parent 1: classid 1:1 htb rate 1mbit ceil 1mbit
sudo tc class add dev eth0 parent 1:1 classid 1:10 htb rate 1mbit ceil 1mbit
# 限制上傳帶寬(FTP數據端口為20,控制端口為21)
sudo tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dport 21 0xffff flowid 1:10 # 控制端口
sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip sport 20 0xffff flowid 1:10 # 數據端口
注:
dport 21
匹配FTP控制端口(命令傳輸),sport 20
匹配FTP數據端口(文件傳輸)。若使用PASV模式,需將dport
改為PASV端口范圍(如50000:60000
)。
trickle
工具(限制FileZilla進程帶寬)trickle
通過動態調整進程的網絡發送/接收速率,適用于臨時或輕量級限速。
trickle
sudo yum install trickle -y
trickle
啟動FileZilla Server-d 1024
)、上傳速度為512Kbps(-u 512
):sudo trickle -d 1024 -u 512 /usr/sbin/filezilla_server
注:若需開機自啟,可將上述命令添加到
/etc/rc.local
或創建Systemd服務單元(如/etc/systemd/system/filezilla_trickle.service
)。
tc
配置需謹慎:錯誤的隊列規則可能導致網絡中斷,建議在測試環境驗證后再應用于生產環境。tc
的dport
規則改為PASV端口范圍(在FileZilla Server的Global Settings→Passive Mode中設置),或在trickle
中限制所有FTP數據端口。通過以上方法,可有效限制CentOS上FileZilla Server的帶寬使用,優化網絡資源分配。