利用Proftpd1.3 + Mysql5.0 + Quota搭建FTP服务

测试平台:Red Hat Enterprise Linux 5 经过测试成功!

1.安装MySql5.0(包括服务器端,客户端以及devel包等等)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2.安装Proftpd1.3

./configure --prefix=/usr/local/proftpd --with-modules=mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql --with-includes=/usr/include/mysql --with-libraries=/usr/lib/mysql

make

make install

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3.创建数据库

-- phpMyAdmin SQL Dump
-- version 2.8.2
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2006 年 11 月 06 日 22:39
-- 服务器版本: 5.0.24
-- PHP 版本: 5.1.4
--
-- 数据库: `ftpusers`
--

-- --------------------------------------------------------

--
-- 表的结构 `ftpgroup`
--

CREATE TABLE `ftpgroup` (
  `groupname` varchar(16) NOT NULL default '',
  `gid` smallint(6) NOT NULL default '5500',
  `members` varchar(16) NOT NULL default '',
  KEY `groupname` (`groupname`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='ProFTP group table';

-- --------------------------------------------------------

--
-- 表的结构 `ftpquotalimits`
--

CREATE TABLE `ftpquotalimits` (
  `name` varchar(30) default NULL,
  `quota_type` enum('user','group','class','all') NOT NULL default 'user',
  `per_session` enum('false','true') NOT NULL default 'false',
  `limit_type` enum('soft','hard') NOT NULL default 'hard',
  `bytes_in_avail` float NOT NULL default '0',
  `bytes_out_avail` float NOT NULL default '0',
  `bytes_xfer_avail` float NOT NULL default '0',
  `files_in_avail` int(10) unsigned NOT NULL default '0',
  `files_out_avail` int(10) unsigned NOT NULL default '0',
  `files_xfer_avail` int(10) unsigned NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- 表的结构 `ftpquotatallies`
--

CREATE TABLE `ftpquotatallies` (
  `name` varchar(30) NOT NULL default '',
  `quota_type` enum('user','group','class','all') NOT NULL default 'user',
  `bytes_in_used` float NOT NULL default '0',
  `bytes_out_used` float NOT NULL default '0',
  `bytes_xfer_used` float NOT NULL default '0',
  `files_in_used` int(10) unsigned NOT NULL default '0',
  `files_out_used` int(10) unsigned NOT NULL default '0',
  `files_xfer_used` int(10) unsigned NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- 表的结构 `ftpuser`
--

CREATE TABLE `ftpuser` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `userid` varchar(32) NOT NULL default '',
  `passwd` varchar(32) NOT NULL default '',
  `uid` smallint(6) NOT NULL default '5500',
  `gid` smallint(6) NOT NULL default '5500',
  `homedir` varchar(255) NOT NULL default '',
  `shell` varchar(16) NOT NULL default '/sbin/nologin',
  `count` int(11) NOT NULL default '0',
  `host` varchar(30) NOT NULL default '000-000-000-000',
  `lastlogin` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=latin1 COMMENT='ProFTP user table';

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

4. proftpd.conf  内容如下

# This is a basic ProFTPD configuration file (rename it to
# 'proftpd.conf' for actual use.  It establishes a single server
# and a single anonymous login.  It assumes that you have a user/group
# "nobody" and "ftp" for normal operation and anon.
ServerName   "FTP Server"
ServerType   standalone
DefaultServer   on
# Port 21 is the standard FTP port.
Port    21
# Umask 022 is a good standard umask to prevent new dirs and files
# from being group and world writable.
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
# Set the user and group under which the server will run.
User    nobody
Group    nobody

# To cause every FTP user to be "jailed" (chrooted) into their home
# directory, uncomment this line.
DefaultRoot ~   !users

# Normally, we want files to be overwriteable.
AllowOverwrite  on
# Bar use of SITE CHMOD by default
<Limit SITE_CHMOD>
  DenyAll
</Limit>
# 最大的用户数
MaxClients      200
# 服务器的欢迎信息
DisplayLogin      welcome.msg
DisplayFirstChdir    .message
# 连接时的MSG
DisplayConnect /usr/local/proftpd/etc/connect.msg
DisplayGoAway /usr/local/proftpd/etc/goway.msg
# 输入quit命令后的MSG
DisplayQuit /usr/local/proftpd/etc/quit.msg
MaxHostsPerUser 20
MaxClientsPerUser 20
# 对不起,一个IP只允许一个连接
MaxClientsPerHost 20

RootLogin off
RequireValidShell off
UseReverseDNS     off
IdentLookups      off
TimeoutStalled    6000
TimeoutLogin      900
TimeoutIdle       600
TimeoutNoTransfer 600
# 让proftp支持现在流行的FXP传输方式,默认是不支持的
AllowForeignAddress on
# 端口也可自己指定
# PassivePorts 49152 65534
# 允许断点续传是默认支持的,不用设置
# 这里有一个技巧,你可以控制FTP中任一个目录有"断点续传"的功能,请设置下面一行,(例:)

AllowStoreRestart      on
AllowRetrieveRestart   on

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

#-------- load sql.mod for mysql authoritative --------#
# Backend表示用户认证方式为MySQL数据库的认证方式 
# Plaintext表示明文认证方式,排在最前面的为最先使用的方式
SQLAuthTypes Backend Plaintext
# 数据库的鉴别
SQLAuthenticate users* groups*
# 数据库联接的信息
# ftpdb是数据库名,localhost是主机名
# proftpd是连接数据库的用户名,password是密码
#(如果没有密码留空)  数据库@mysql服务器 数据库帐户 密码
SQLConnectInfo databsename@localhost mysqlusername password

# 指定用来做用户认证的表的有关信息
SQLUserInfo ftpuser userid passwd uid gid homedir shell
SQLGroupInfo ftpgroup groupname gid members
# 如果用户主目录不存在,则系统会根据此用户在用户数据表中的homedir字段的值新建一个目录
SQLHomedirOnDemand on
SQLNegativeCache   on
# Update count every time user logs in
SQLLogFile /var/log/proftpd.sql.log
SQLNamedQuery getcount SELECT "count from ftpuser where userid='%u'"
SQLNamedQuery getlastlogin SELECT "lastlogin from ftpuser where userid='%u'"
SQLNamedQuery updatelogininfo UPDATE "count=count+1,host='%h',lastlogin=current_timestamp() WHERE userid='%u'"

ftpuser
SQLShowInfo PASS "230" "You've logged on %{getcount} times, last login at %{getlastlogin}"
SQLLog PASS updatelogininfo
#-------- load sql.mod for mysql authoritative --------# 

#-------- load qudes.mod for Quota limit --------#
#打开磁盘限额引擎
QuotaEngine on
# 设置磁盘限额
QuotaDirectoryTally on
# 设置磁盘容量显示时的单位
QuotaDisplayUnits Mb
# 允许显示磁盘限额信息,ftp登录后可执行quote site quota命令查看当前磁盘使用情况
QuotaShowQuotas on
# 设置磁盘限额日志文件
QuotaLog "/var/log/proftpd.quota.log"
# 指定磁盘限额模块使用的数据库信息
SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail,

bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail FROM ftpquotalimits WHERE name = '%{0}' AND

quota_type = '%{1}'"
SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used,

files_in_used, files_out_used, files_xfer_used FROM ftpquotatallies WHERE name = '%{0}' AND quota_type = '%{1}'"
SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + %{0}, bytes_out_used = bytes_out_used + %

{1}, bytes_xfer_used = bytes_xfer_used + %{2}, files_in_used = files_in_used + %{3}, files_out_used = files_out_used

+ %{4}, files_xfer_used = files_xfer_used + %{5} WHERE name = '%{6}' AND quota_type = '%{7}'" ftpquotatallies
SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" ftpquotatallies
QuotaLimitTable sql:/get-quota-limit
QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally
#--------- load qudes.mod for Quota limit --------#
# Logging options
# Debug Level
# emerg, alert, crit (empfohlen), error, warn. notice, info, debug
#
SyslogLevel emerg
SystemLog /var/log/proftpd.system.log
TransferLog /var/log/proftpd.xferlog
# Some logging formats
#
LogFormat default "%h %l %u %t "%r" %s %b"
LogFormat auth "%v [%P] %h %t "%r" %s"
LogFormat write "%h %l %u %t "%r" %s %b"
# Log file/dir access
# ExtendedLog /var/log/proftpd.access_log WRITE,READ write
# Record all logins
ExtendedLog /var/log/proftpd.auth_log AUTH auth
# Paranoia logging level....
ExtendedLog /var/log/proftpd.paranoid_log ALL default
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

5.说明:

ftpquotatallies 表不需要作修改,它记录了用户当前的磁盘使用情况,由程序自动记录,要注意的是ftpquotalimits 表中一些字段的含意quota_type 磁盘限额的鉴别,可以设置单各用户,也可以设置一各组中的全部用户,还可以设置全部用户

bytes_in_avail 字段表示上传最大字节数,就是FTP用户空间容量 (设置个字段的时候是以byte(字节)为单位,如果要限额在10M,那就是10240000,下面也一样)

bytes_out_avail 字段表示下载最大字节数,需要注意的是,这个字段中记录的是用户总共能从服务器上下载多少数据,数据是累计的.

bytes_xfer_avail 字段表示总共可传输的文件的最大字节数(上传和下载流量)需要注意的是,这个字段中记录的是用户总共能传输文件的最大字节数,数据是累计的.
files_in_avail INT 字段表示总共能上传文件的数目
files_out_avail INT 字段表示能从服务器上下载文件的总数目
files_xfer_avail INT 字段表示总共可传输文件的数目(上传和下载)

 

示例:

加入用户
INSERT INTO ftpuser (userid, passwd, uid, gid, homedir, shell ) VALUES ( 'test', 'test', '5003', '5003', '/home/ftp', '/sbin/nologin' );

如果要加密密码,则:
INSERT INTO ftpuser (userid, passwd, homedir,) VALUES ( 'test', 'test', '/ftproot/test');

在系统上执行 chown nobody.nobody /ftproot  或者 chmod 777 /ftproot 否则无法上传文件

启用限额
INSERT INTO ftpquotalimits (name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail ) VALUES ( 'test', 'user', 'false', 'hard', '10240000', '0', '0', '0', '0', '0' );
将test帐号给予10M空间,最多能上传500个文件到服务器上,文件传输流量为20M,只能传输10个文件,不需要设置的部分用0代替就可以了。

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

6. cd /usr/local/proftpd/sbin

     ./proftpd

     OK啦..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值