前言:
本文的描述平台为Red Hat Linux/x86 8.0 (Psyche),适用于Red Hat Linux/x86 9.0 (Shrike)。
一、软件获取(本文以proftpd-1.2.7、mod_quota-1.28和MySQL-3.23.56为例)
1. ProFTPD
proftpd-1.2.7.tar.gz
proftpd-1.2.7-1.i386.rpm
proftpd-standalone-1.2.7-1.i386.rpm
下载: http://www.mysql.com/
二、安装ProFTPD
1. 卸载wu-ftpd
rpm -e anonftp
rpm -e wu-ftpd
2. 安装ProFTPD
rpm -ivh proftpd-1.2.7-1.i386.rpm
rpm -ivh proftpd-standalone-1.2.7-1.i386.rpm
3. 编译ProFTPD
tar -zxvf proftpd-1.2.7.tar.gz
cp mod_quota.c_for_1.2.7 ./proftpd-1.2.7/contrib/mod_quota.c
vi ./proftpd-1.2.7/contrib/mod_quota.c
# 将其中的“/* #define QUOTA_MYSQL *' target="_blank">http://www.proftpd.org
proftpd.conf 配置详情:http://www.proftpd.org/docs/configuration.html
2. mod_quota v1.28
mod_quota.c_for_1.2.7
下载: ftp://pooh.urbanrage.com/pub/c/
3. MySQL
MySQL-3.23.56-1.i386.rpm
MySQL-client-3.23.56-1.i386.rpm
MySQL-devel-3.23.56-1.i386.rpm
MySQL-shared-3.23.56-1.i386.rpm
下载: http://www.mysql.com/
二、安装ProFTPD
1. 卸载wu-ftpd
rpm -e anonftp
rpm -e wu-ftpd
2. 安装ProFTPD
rpm -ivh proftpd-1.2.7-1.i386.rpm
rpm -ivh proftpd-standalone-1.2.7-1.i386.rpm
3. 编译ProFTPD
tar -zxvf proftpd-1.2.7.tar.gz
cp mod_quota.c_for_1.2.7 ./proftpd-1.2.7/contrib/mod_quota.c
vi ./proftpd-1.2.7/contrib/mod_quota.c
# 将其中的“/* #define QUOTA_MYSQL */ ”改为“#define QUOTA_MYSQL”
cd ../proftpd-1.2.7
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var/run --mandir=/usr/man --with-libraries=/usr/lib/mysql --with-includes=/usr/include/mysql --with-modules=mod_sql:mod_sql_mysql:mod_quota
make
make install
三、安装MySQL和建立数据库
1. 安装MySQL
rpm -ivh MySQL-3.23.56-1.i386.rpm
rpm -ivh MySQL-client-3.23.56-1.i386.rpm
rpm -ivh MySQL-devel-3.23.56-1.i386.rpm
rpm -ivh MySQL-shared-3.23.56-1.i386.rpm
2. 建立数据库
#建立数据库proftpd
CREATE DATABASE proftpd;
#选定使用的数据(proftpd)
USE proftpd
#建立组表
DROP TABLE IF EXISTS `groups`;
CREATE TABLE `groups` (
`groupname` varchar(255) binary NOT NULL default '',
`gid` int(11) NOT NULL default '0',
`members` text NOT NULL,
PRIMARY KEY (`groupname`)
)TYPE=MyISAM;
#建立用户表
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`userid` varchar(255) binary NOT NULL default '',
`passwd` varchar(255) binary NOT NULL default '',
`uid` int(11) default NULL,
`gid` int(11) default NULL,
`homedir` varchar(255) default NULL,
`shell` varchar(255) default NULL,
`count` int(11) default NULL,
`used` double(10,1) default '0.0',
`quota` double(10,1) default '104857600.0',
PRIMARY KEY (`userid`)
) TYPE=MyISAM;
#建立数据库用户及初始化用户密码(数据库用户名:proftpd , 密码: 12345678)
grant all privileges on proftpd.* to proftpd@localhost identified by '12345678';
flush privileges;
四、设置proftpd ( 配置文件 /etc/proftpd.conf )
#将“User nobody”改为“User ftp”
User ftp
#将“Group nogroup”改为“Group ftp”
Group ftp
#关闭proftpd的反向解析查询, 从而加速ftp连线登录
UseReverseDNS off
#将用户限制自己的目录下
DefaultRoot ~
#不使用shell
RequireValidShell no
#打开磁盘配额限制
Quotas on
QuotaCalc on
#硬性限制,将上传超出配额限制的文件删除
QuotaType hard
#默认的配额(100MB)
DefaultQuota 102400
#将默认的单位由“byte”改为“KB”
QuotaBlockSize 1024
QuotaBlockName "K bytes"
#Disable ident protocol (RFC1413)
IdentLookups off
#MySQL的连接参数:数据库@主机名 用户名 密码
SQLConnectInfo proftpd@localhost proftpd 12345678
#指定认证方式
SQLAuthenticate users
#用户密码类型(本文的设置把持Backend、Crypt加密密码和不加密码)
SQLAuthTypes Backend Crypt Plaintext
#用户表信息:表名“user”, 字段名“passwd uid gid 用户目录 shell”
SQLUserInfo users userid passwd uid gid homedir shell
#组表信息: 表名 组名字段 组值字段 成员字段
SQLGroupInfo groups groupname gid members
#用户登录后,将用户的登录次数+1
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "count=count+1 WHERE userid='%u'" users
#用户登录后,显示已经登录过的次数
SQLNamedQuery count SELECT "count FROM users WHERE userid='%u'"
SQLShowInfo PASS "230" "You've logged on %{count} times, %u"
#如果用户目录不存在,自动创建用户目录
SQLHomedirOnDemand on
#Quota信息的表名
SQLQuotaTable users
#MySQL的连接参数: 主机名 用户名 密码 数据库
SQLQuotaInfo localhost proftpd 12345678 proftpd
#用户的字段名
SQLQuotaName userid
#用户已经使用空间的字段名
SQLQuotaUsed used
#用户磁盘配额的字段名
SQLQuotaQuota quota
||||||五、测试
1. 启动Proftd
/etc/rc.d/init.d/proftpd start
2. 建立测试用户
测试用户: test
密码(加密): 87654321
uid: 14
gid: 50
目录:/home/ftp/test
shell: /sbin/nologin
已登录数: 0
已使用空间: 0
磁盘限额: 100MB
方法一: 命令行方式创建
shell> mysql -u proftpd -p
mysql> USE proftpd
mysql> INSERT INTO users VALUES ("test", PASSWORD( "87654321" ) , 14, 50, "/home/ftp/test", "/sbin/nologin", 0, 0, 10240000);
方法二: 用phpMyAdmin方式创建(在选定proftpd数据库的情况执行下列SQL语句)
INSERT INTO users VALUES ("test", PASSWORD( "87654321" ) , 14, 50, "/home/ftp/test", "/sbin/nologin", 0, 0, 10240000);
ceiba
2003-05-18
补充: 常用设置参数
ServerIdent on ftp.abc.com # ftp登录时,显示指的域名ftp.abc.com, 而不显示默认的主机名(域名)
UseReverseDNS off # 关闭proftpd的反向解析查询, 从而加速ftp连线登录
DefaultRoot ~ # 把ftp用户强制限定在自己目录下 — 加强系统安全
TimesGMT off # 关闭GMT与本地时区绑定 — 使用目录和文件的时间显示与系统一致
调试proftpd:
/usr/sbin/proftpd -c /etc/proftpd.conf -d 5 -n
参考:
Proftpd+mysql+quota的实现方法
http://www.eduhr.com/edu/2002-12-30/149.htm
以下是/etc/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 "ProFTPD Default Installation"
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 ftp
Group ftp
# To cause every FTP user to be "jailed" (chrooted) into their home
# directory, uncomment this line.
UseReverseDNS off
TimesGMT off
DefaultRoot ~
RequireValidShell no
Quotas on
QuotaCalc on
QuotaType hard
DefaultQuota 102400
QuotaBlockSize 1024
QuotaBlockName "K bytes"
IdentLookups off
SQLConnectInfo proftpd@localhost proftpd 12345678
SQLAuthenticate users
SQLAuthTypes Backend Crypt Plaintext
SQLUserInfo users userid passwd uid gid homedir shell
SQLGroupInfo groups groupname gid members
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "count=count+1 WHERE userid='%u'" users
SQLNamedQuery count SELECT "count FROM users WHERE userid='%u'"
SQLShowInfo PASS "230" "You've logged on %{count} times, %u"
SQLHomedirOnDemand on
SQLQuotaTable users
SQLQuotaInfo localhost proftpd 12345678 proftpd
SQLQuotaName userid
SQLQuotaUsed used
SQLQuotaQuota quota
# Normally, we want files to be overwriteable.
<Directory />
AllowOverwrite on
</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
DisplayFirstChdir .message
# Limit WRITE everywhere in the anonymous chroot
<Limit WRITE>
DenyAll
</Limit>
</Anonymous>