献给大家的新年礼物哦, 国内关于proftp设置的文档实在太少,只能看着官方文档慢慢学习,特把学习经验分享给大家,祝大家新年快乐:)
原文地址:http://www.5ilinux.com/blog/archives/000082.html
转载请注明出处和署名,并请保持一致
proftp学习笔记(一)
这几天,公司终于放假了,终于可以安下心来好好学些proftp+mysql+quota。
安装proftp之前,必须先做一个工作,假如你的mysql是自己编译的,那就必须先修改/etc/ld.so.conf,否则后面运行proftp会报错。
vi /etc/ld.so.conf
添加下面一行:
/usr/local/mysql/lib/mysql
wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.2.9.tar.gz
wget http://www.castaglia.org/proftpd/modules/proftpd-mod-quotatab-1.2.11.tar.gz
tar zvxf proftpd-1.2.9.tar.gz
tar zvxf proftpd-mod-quotatab-1.2.11.tar.gz
cp mod_quotatab/*.c proftpd-1.2.9/contrib/
cp mod_quotatab/*.h proftpd-1.2.9/contrib/
./configure \
--prefix=/usr/local/proftpd \
--with-modules=mod_sql:mod_sql_mysql:mod_quotatab\
:mod_quotatab_sql \
--with-includes=/usr/local/mysql/include/mysql \
--with-libraries=/usr/local/mysql/lib/mysql
make
make install
/usr/local/proftpd/sbin/proftpd
vi /usr/local/proftpd/etc/proftpd.conf
AllowRetrieveRestart on
AllowStoreRestart on
cp proftpd-1.2.9/contrib/dist/rpm/proftpd.init.d /etc/rc.d/init.d/proftpd
chmod 755 /etc/rc.d/init.d/proftpd
/usr/local/proftpd/sbin/ftpshut
ftpshut [ -l min ] [ -d min ] time [ warning-message ... ]
ftpshut -l 20 -d 10 +30 "FTP Server Will shutdown at time"
ftpshut -R
#全局设置
设置项目1 参数1
设置项目2 参数2
#某个目录的设置
<Directory "路径名">
...
...
</Directory>
#关于匿名用户的设置
<Anonymous "匿名登陆的目录">
...
...
<Limit 限制动作>
...
...
</Limit>
</Anonymous>
CMD:Change Working Directory 改变目录
MKD:MaKe Directory 建立目录的权限
RNFR: ReName FRom 更改目录名的权限
DELE:DELEte 删除文件的权限
RMD:ReMove Directory 删除目录的权限
RETR:RETRieve 从服务端下载到客户端的权限
STOR:STORe 从客户端上传到服务端的权限
READ:可读的权限,不包括列目录的权限,相当于RETR,STAT等
WRITE:写文件或者目录的权限,包括MKD和RMD
DIRS:是否允许列目录,相当于LIST,NLST等权限,还是比较实用的
ALL:所有权限
LOGIN:是否允许登陆的权限
AllowUser 针对某个用户允许的Limit
DenyUser 针对某个用户禁止的Limit
AllowGroup 针对某个用户组允许的Limit
DenyGroup 针对某个用户组禁止的Limit
AllowAll 针对所有用户组允许的Limit
DenyAll 针对所有用户禁止的Limit
TransferRate STOR|RETR 速度(Kbytes/s) user 使用者
group add ftpusers
useradd -d /home/kaoyan -g ftpusers -s /bin/fales kaoyan
useradd -d /home/kaoyan -g ftpusers -s /bin/fales upload
chown -R kaoyan:upload /home/kaoyan
chmod -R 775 /home/kaoyan
ServerName "Frank's FTP Server"
ServerType standalone
DefaultServer on
Port 21
Umask 022
MaxInstances 30 #最多有30个proftpd的PID
User nobody
Group nobody
TimeoutStalled 10
MaxClients 10 #最多允许10个用户在线
MaxClientsPerHost 1 "对不起,一个IP只允许一个连接"
AllowStoreRestart on
#允许断点续传(上传),断点续续(下载)是默认支持的,不用设置
DisplayLogin welcome.msg #欢迎词文件
ServerIdent off #屏蔽服务器版本信息
DefaultRoot ~ ftpusers #设置ftpusers组只能访问自己的目录
<Directory />
AllowOverwrite on
</Directory>
<Directory /home/kaoyan>
<Limit WRITE> #不允许写
DenyUser kaoyan
</Limit>
<Limit RMD RNFR DELE RETR> #不允许删除,改名,下载
DenyUser upload
</Limit>
TransferRate RETR 50 user kaoyan
TransferRate STOR 100 user upload
</Directory>
<Anonymous ~kaoyan>
...
...
</Anonymous>
<><Anonymous ~upload>
...
...
</Anonymous>
%T 目前的时间
%F 所在硬盘剩下的容量
%C 目前所在的目录
%R Client 端的主机名称
%L Server 端的主机名称
%U 使用者帐户名称
%M 最大允许连接人数
%N 目前的服务器连接人数
%E FTP服务器管理员的 email
%i 本次上传的文件数量
%o 本次下载的文件数量
%t 本次上传+下载的文件数量
欢迎您%U, 这是Frank的测试FTP服务器;
目前时间是:%T;
本服务器最多允许%M个用户连接数;
目前服务器上已有%N个用户连接数;
目前你所在的目录是%C;
目录所在的硬盘还剩下%F字节。
AllowForeignAddress on
PassivePorts 49152 65534 #端口也可自己指定喜欢的
RootLogin on
<Limit LOGIN>
Order deny,allow
Deny from 10.1.1.
Allow from all
</Limit>
<VirtualHost 210.51.0.124>
ServerName "Frank FTP Server"
Port 5555
...
<Directory 目录>
...
<Limit 动作>
...
</Limit>
...
</Directory>
</VirtualHost>
touch /home/kaoyan/ratio.dat
touch /home/kaoyan/ratio.tmp
chmod -R 666 /home/kaoyan
Ratios on
SaveRatios on
RatioFile /home/kaoyan/ratio.dat
RatioTempFile /home/kaoyan/ratio.tmp
UserRatio ftp1 0 0 2 1000
#UserRatio "使用者帐户" fileratio filequota byteratio bytequota
# fileratio :以文件为基础的比率,通常不限制,故为 0
# filequota :预设置能下载多少文件,不限制时为 0
# byteratio :就是上传/下载的比例,如果数字为2,表示1:2
# bytequota :预设置能下载多少 KBytes 的文件
#上面设置的就是1:2的比率,默认只允许下载1M的文件
groupadd -g 5500 ftpgroup
adduser -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser
mysql mysql -uroot -ppassword
create database ftpdb
grant select, update on ftpdb.* to proftpd@localhost identified by 'password'
use ftpdb
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`)
) TYPE=MyISAM COMMENT='ProFTP group table';
INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpuser');
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 'soft',
`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'
) TYPE=MyISAM;
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'
) TYPE=MyISAM;
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',
`accessed` datetime NOT NULL default '0000-00-00 00:00:00',
`modified` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='ProFTP user table';
ServerName "Frank's FTP Server" ServerType standalone DefaultServer on
Port 21
Umask 022
MaxInstances 30
MaxLoginAttempts 3
User nobody
Group nobody
MaxHostsPerUser 1 "Sorry, you may not connect more than one time."
MaxClientsPerUser 2 "Only one such user at a time."
MaxClientsPerHost 3 "Sorry, you may not connect more than one time."
RootLogin off
RequireValidShell off
TimeoutStalled 10
MaxClients 10
AllowForeignAddress on
AllowStoreRestart on
ServerIdent off
DefaultRoot ~ ftpgroup
SQLAuthTypes Backend Plaintext
#Backend表示用户认证方式为MySQL数据库的认证方式
#Plaintext表示明文认证方式,排在最前面的为最先使用的方式
SQLAuthenticate users* groups*
# databasename@host database_user user_password
SQLConnectInfo ftpdb@localhost proftpd password
SQLUserInfo ftpuser userid passwd uid gid homedir shell
SQLGroupInfo ftpgroup groupname gid members
SQLHomedirOnDemand on
#如果用户主目录不存在,则系统会根据此用户在用户数据表中的homedir字段的值新建一个目录
# Update count every time user logs in
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "count=count+1,accessed=now() WHERE userid='%u'" ftpuser
# Update modified everytime user uploads or deletes a file
SQLLog STOR,DELE modified
SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser
QuotaEngine on
QuotaDirectoryTally on
QuotaDisplayUnits Mb
QuotaShowQuotas on
QuotaLog "/var/log/quota"
SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avai
l, 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_i
n_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}'" ftpquota
tallies
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
INSERT INTO `ftpuser` VALUES (1, 'test', 'ftppasswd', 5500, 5500, '/home/test', '/sbin/nologin');
quotalimits表
name: - 用户帐号
quota type: - user, group, class, all (we use user)
per_session: - true or false (we use true)
limit_type: - 硬限制 or 软限制 (我们一般用硬限制)
bytes_in_avail: - 允许上传的字节数
bytes_out_avail: - 允许下载的字节数
bytes_xfer_avail: - 允许传输的字节数(包括上传/下载)
files_in_avail: - 允许上传的文件数
files_out_avail: - 允许下载的文件数
files_xfer_avail: - 允许传输的文件数(包括上传/下载)