在Debian上设置FTP服务器的带宽限制,通常需要使用vsftpd(Very Secure FTP Daemon)服务器软件,并结合trickle或wondershaper等工具来实现带宽限制。以下是具体步骤:
trickle安装trickle:
sudo apt update
sudo apt install trickle
配置vsftpd:
编辑/etc/vsftpd.conf文件,确保以下配置项存在并正确设置:
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
创建启动脚本:
创建一个启动脚本,用于在启动vsftpd时使用trickle限制带宽。例如,创建文件/etc/init.d/vsftpd-trickle:
#!/bin/sh
### BEGIN INIT INFO
# Provides: vsftpd-trickle
# Required-Start: $local_fs $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start vsftpd with trickle bandwidth limiting
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="vsftpd with trickle bandwidth limiting"
NAME=vsftpd-trickle
DAEMON=/usr/sbin/vsftpd
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
--listen_port=21 --user=ftp --group=ftp --chroot_local_user=YES --allow_writeable_chroot=YES
trickle -d 100 -u 100 $DAEMON &
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
killall $DAEMON
killall trickle
echo "$NAME."
;;
restart|force-reload)
$0 stop
$0 start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
赋予脚本执行权限:
sudo chmod +x /etc/init.d/vsftpd-trickle
启动服务:
sudo service vsftpd-trickle start
wondershaper安装wondershaper:
sudo apt update
sudo apt install wondershaper
配置vsftpd:
编辑/etc/vsftpd.conf文件,确保以下配置项存在并正确设置:
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
创建启动脚本:
创建一个启动脚本,用于在启动vsftpd时使用wondershaper限制带宽。例如,创建文件/etc/init.d/vsftpd-wondershaper:
#!/bin/sh
### BEGIN INIT INFO
# Provides: vsftpd-wondershaper
# Required-Start: $local_fs $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start vsftpd with wondershaper bandwidth limiting
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="vsftpd with wondershaper bandwidth limiting"
NAME=vsftpd-wondershaper
DAEMON=/usr/sbin/vsftpd
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
--listen_port=21 --user=ftp --group=ftp --chroot_local_user=YES --allow_writeable_chroot=YES
wondershaper eth0 100 100 &
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
killall $DAEMON
killall wondershaper
echo "$NAME."
;;
restart|force-reload)
$0 stop
$0 start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
赋予脚本执行权限:
sudo chmod +x /etc/init.d/vsftpd-wondershaper
启动服务:
sudo service vsftpd-wondershaper start
ProFTPD,并结合SSL/TLS加密传输。通过以上步骤,您可以在Debian上成功设置FTP服务器的带宽限制。