亞寶論壇's Archiver

copyright 發表於 2009-6-13 04:32

proftp(增加多線程配置)連接數增減方法(紅字部份)

文件位置: [b][size=4]/etc/proftpd.conf[/size][/b]

proftpd實現虛擬用戶和quota(不用數據庫)和限速

需求:
(要保障FTP服務器的安全,特要求如下:
1、系統要求LINUX或UNIX。
2、虛擬用戶,不能是系統用戶。
3、可以限制上傳,下載速度。
4、可以限制迅雷多線程下載。
5、可以限制用戶目錄大小,以及上傳文件大小等。)

下面開始安裝配置proftpd

# wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.2.tar.gz
# tar zxvf proftpd-1.3.2
# cd proftpd-1.3.2
# ./configure --prefix=/usr/local/proftpd --with-modules=mod_quotatab:mod_quotatab_file
# make
# make install
# cp contrib/ftpasswd /usr/local/proftpd/bin/
# cp contrib/ftpquota /usr/local/proftpd/bin/
# vi /usr/local/proftpd/etc/proftpd.conf
ServerName                        "mz16.cn Ftp System"
ServerType                        standalone
DefaultServer                        on
Port                                21
# Don't use IPv6 support by default.
UseIPv6                                off
Umask                                022
# To prevent DoS attacks, set the maximum number of child processes
# to 30.  If you need to allow more than 30 concurrent connections
# at once, simply increase this value.  Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd).
MaxInstances                        30

#[b][color=Red][size=4]限制連接數
MaxClients 10[/size][/color][/b] "最大允許10個用戶同時訪問"

MaxHostsPerUser 1 #每個帳戶最多允許來源ip為1個, 對防止ftp帳號還是比較有用的。

MaxClientsPerUser 1 #每個帳戶在每個客戶端最多可以同時登陸1次,可以防止多線程軟件下載對服務器的破壞。(用迅雷下載,線程只能限定為1個。)

MaxClientsPerHost 1 #同一個客戶端只能最多1個帳號可以登陸

# 不顯示服務器相關信息, 如proftpd版本
ServerIdent          off
# 禁用反向域名解析
UseReverseDNS      off

User                                nobody
Group                        nobody

# To cause every FTP user to be "jailed" (chrooted) into their home
# directory, uncomment this line.
DefaultRoot ~       # 把用戶鎖定在自己的目錄下,根目錄無法訪問。

# Normally, we want files to be overwriteable.

AllowOverwrite                on        #設置文件可以被覆蓋
AllowForeignAddress     on      # 支持FXP
PassivePorts   49152 65534       # 支持被動模式
AllowRetrieveRestart on           # 允許下載續傳,默認即開啟
AllowStoreRestart on              # 允許上載續傳
RequireValidShell off   # 不要求有合法shell,直接效果是允許nologin用戶和虛擬用戶登錄
AuthOrder mod_auth_file.c mod_auth_unix.c
AuthUserFile /usr/local/proftpd/etc/passwd
TransferRate STOR 150 user tom    # 限制tom用戶上傳的速率限制在150Kbytes/s
TransferRate RETR 100 user tom    # 限制tom用戶下載的速率限制在100Kbytes/s
# Using a file-based limit table
QuotaLimitTable file:/usr/local/proftpd/etc/ftpquota.limittab
# Using a file-based tally table
QuotaTallyTable file:/usr/local/proftpd/etc/ftpquota.tallytab
QuotaDirectoryTally on
QuotaDisplayUnits Mb        # 顯示以MB為單位
QuotaEngine on
QuotaLog /usr/local/proftpd/etc/Quota.log
QuotaShowQuotas on
#QuotaOptions ScanOnLogin    # 這個選項如果去掉註釋,會先掃瞄用戶目錄的大小,比如用戶目錄限定為50M,已經使用了18M,那麼只能上傳小於32M的文件,否則會失敗。如果加上這個選項,會忽略掉用戶目錄大小,上傳只要小於50M,都可以上傳。建議註釋這條選項。

# Bar use of SITE CHMOD by default
<Limit SITE_CHMOD>
  AllowAll
</Limit>

<Directory /opt/tom/>
<Limit write>
AllowUser tom
DenyALL
</Limit>
</Directory>

# A basic anonymous configuration, no upload directories.  If you do not
# want anonymous users, simply delete this entire <Anonymous> section.
#<Anonymous ~ftp>
#  User                                ftp
#  Group                                ftp
#
#  # We want clients to be able to login with "anonymous" as well as "ftp"
#  UserAlias                        anonymous ftp
#
  # Limit the maximum number of anonymous logins
#  MaxClients                        10

  # We want 'welcome.msg' displayed at login, and '.message' displayed
  # in each newly chdired directory.
#  DisplayLogin                        welcome.msg
#  DisplayChdir                        .message

  # Limit WRITE everywhere in the anonymous chroot
#  <Limit WRITE>
#    DenyAll
#  </Limit>
#</Anonymous>

# 創建虛擬用戶
# /usr/local/proftpd/bin/ftpasswd --passwd --name=tom --uid=99 --gid=99 --home=/opt/tom/ --shell=/sbin/nologin --file=/usr/local/proftpd/etc/passwd
...
Password: <new password>
Re-type password: <new password>

之後會自動生成/usr/local/proftpd/etc/passwd

# chmod -R 777 /opt/tom
要注意,因為虛擬用戶並不在本地系統用戶中存在,所以要設置虛擬用戶可以訪問的所有目錄都允許其它用戶寫,這樣才能保證虛擬用戶正常增刪文件。

# cd /usr/local/proftpd/bin/
# ftpquota -create -type=tally -table-path=/usr/local/proftpd/etc/ftpquota.tallytab
# ftpquota -create -type=limit -table-path=/usr/local/proftpd/etc/ftpquota.limittab
# ftpquota --type=limit --table-path=/usr/local/proftpd/etc/ftpquota.limittab --add-record --quota-type=user --name=tom --units=Mb --bytes-upload=50 --bytes-xfer=1

# (上面意思是:限定tom用戶空間大小為50M,上傳文件大小為1M)

ftpquota 具體用法參照 ftpquota --help即可。

這樣都設置完了以後
啟動proftpd
再ftp上去的時候
用命令site quota就可以看當前用戶的quota信息

常用全局設置:
  DefaultRoot ~ # 限制每個FTP用戶在自己的目錄下,不可查看上一級目錄

  AllowRetrieveRestart on #下載時,允許斷點續傳

  AllowStoreRestart on #上傳時,允許斷點續傳

  ServerIdent off #屏蔽服務器版本信息

  TransferRate STOR RETR 速度(Kbytes/s) user 使用者 #設定用戶傳輸速率

  MaxHostsPerUser 1 #每個帳戶最多允許來源ip為1個, 對防止ftp帳號還是比較有用的。

  MaxClientsPerUser 1 #每個帳戶在每個客戶端最多可以同時登陸1次,可以防止多線程軟件下載對服務器的破壞。

  MaxClientsPerHost 1 #同一個客戶端只能最多1個帳號可以登陸

  WtmpLog on #是否要把ftp記錄在日誌中,如果不想可以設置成off屏蔽掉log日誌。

  TimeoutIdle 600 #客戶端idle時間設置,默認就是600秒

  DisplayLogin welcome.msg #設置ftp登陸歡迎信息文件

RootLogin on #允許root用戶登錄,默認是不允許的,安全起見不推薦此選項。


Iptables防火牆設置:

/etc/init.d/iptables stop
iptables -P INPUT DROP
# 打開主動模式21端口
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
# 打開被動模式49152~65534之間的端口
iptables -A INPUT -p tcp --dport 49152:65534 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT

頁: [1]

Powered by Ahpal Archiver 7.0.0  © 2001-2010 ahpal.com