Proftpd+Mysql+Quota的配置

运维 系统运维
有很多人都在为安装proftpd+mysql+quota的种种问题苦恼。本文正好解决了这个棘手的问题。一下就是Proftpd+Mysql+Quota的配置。

Proftpd+Mysql+Quota配置:这篇文章整理而来,包括Proftpd+Mysql+Quota的配置。依照本文步骤逐步实行。mysql/php/apache安装就免了,需要说明的是我的mysql是使用源码安装!

  相关软件:

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

  proftpd-1.2.9.tar.gz

  proftpd-mod-quotatab-1.2.11.tar.gz

  ftpdb.sql

  proftpd.conf

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

  步骤如下:

  代码:

  1.   vi /etc/ld.so.conf  
  2.  

  添加:/usr/local/mysql/lib

  1.   tar zvxf proftpd-1.2.9.tar.gz  
  2.  
  3.   tar zvxf proftpd-mod-quotatab-1.2.11.tar.gz  
  4.  
  5.   cp mod_quotatab/*.c proftpd-1.2.9/contrib/  
  6.  
  7.   cp mod_quotatab/*.h proftpd-1.2.9/contrib/  
  8.  
  9.   vi proftpd-1.2.9/contrib/mod_sql_mysql.c  
  10.  
  11.   #include  
  12.  

  修改mysql.h的实际路径

  1.   cd proftpd-1.2.9  
  2.  
  3.   ./configure \--prefix=/usr/local/proftpd \--with-modules=mod_sql:mod_sql_mysql:mod_quotatab\:mod_quotatab_sql:mod_ratio \--with-includes=/usr/local/mysql/include \--with-libraries=/usr/local/mysql/lib  
  4.  
  5.   make  
  6.  
  7.   make install  
  8.  
  9.   cp proftpd-1.2.9/contrib/dist/rpm/proftpd.init.d /etc/rc.d/init.d/proftpd  
  10.  
  11.   vi /etc/rc.d/init.d/proftpd  
  12.  

  修改:PATH="$PATH:/usr/local/proftpd/sbin"

  1.   chmod 755 /etc/rc.d/init.d/proftpd  
  2.  
  3.   chkconfig --level 3 proftpd on  
  4.  
  5.   groupadd -g 5500 ftpgroup  
  6.  
  7.   adduser -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser  
  8.  

#p#

  然后配置你的Proftpd.conf

  最后就是启动啦。/usr/local/proftpd/sbin/proftpd

  -------------------------------Proftpd.conf----------------------------------

  代码:

  1.   # This is a basic ProFTPD configuration file (rename it to  
  2.  
  3.   # 'proftpd.conf' for actual use. It establishes a single server  
  4.  
  5.   # and a single anonymous login. It assumes that you have a user/group  
  6.  
  7.   # "nobody" and "ftp" for normal operation and anon.  
  8.  
  9.   ServerName "ltsnet"  
  10.  
  11.   ServerType standalone  
  12.  
  13.   DefaultServer on  
  14.  
  15.   # Port 21 is the standard FTP port.  
  16.  
  17.   Port 21  
  18.  
  19.   # Umask 022 is a good standard umask to prevent new dirs and files  
  20.  
  21.   # from being group and world writable.  
  22.  
  23.   Umask 022  
  24.  
  25.   # To prevent DoS attacks, set the maximum number of child processes  
  26.  
  27.   # to 30. If you need to allow more than 30 concurrent connections  
  28.  
  29.   # at once, simply increase this value. Note that this ONLY works  
  30.  
  31.   # in standalone mode, in inetd mode you should use an inetd server  
  32.  
  33.   # that allows you to limit maximum number of processes per service  
  34.  
  35.   # (such as xinetd).  
  36.  
  37.   MaxInstances 30  
  38.  
  39.   # Set the user and group under which the server will run.  
  40.  
  41.   User nobody  
  42.  
  43.   Group nobody  
  44.  
  45.   # To cause every FTP user to be "jailed" (chrooted) into their home  
  46.  
  47.   # directory, uncomment this line.  
  48.  
  49.   ServerIdent off  
  50.  
  51.   DisplayLogin welcome.msg  
  52.  
  53.   DefaultRoot ~  
  54.  
  55.   # Normally, we want files to be overwriteable.  
  56.  
  57.     
  58.  
  59.   AllowOverwrite on  
  60.  
  61.     
  62.  
  63.   # A basic anonymous configuration, no upload directories. If you do not  
  64.  
  65.   # want anonymous users, simply delete this entire section.  
  66.  
  67.     
  68.  
  69.   User ftp  
  70.  
  71.   Group ftp  
  72.  
  73.   # We want clients to be able to login with "anonymous" as well as "ftp"  
  74.  
  75.   UserAlias anonymous ftp  
  76.  
  77.   # Limit the maximum number of anonymous logins  
  78.  
  79.   MaxClients 10  
  80.  
  81.   # We want 'welcome.msg' displayed at login, and '.message' displayed  
  82.  
  83.   # in each newly chdired directory.  
  84.  
  85.   DisplayLogin welcome.msg  
  86.  
  87.   DisplayFirstChdir .message  
  88.  
  89.   # Limit WRITE everywhere in the anonymous chroot  
  90.  
  91.     
  92.  
  93.   DenyAll  
  94.  
  95.     
  96.  

  

  1.   SQLAuthTypes Backend Plaintext  
  2.  
  3.   SQLAuthenticate users* groups*  
  4.  
  5.   SQLConnectInfo ftpdb@localhost root 123456  
  6.  
  7.   SQLUserInfo ftpuser userid passwd uid gid homedir shell  
  8.  
  9.   SQLGroupInfo ftpgroup groupname gid members  
  10.  
  11.   SQLHomedirOnDemand on  
  12.  
  13.   SQLLog PASS updatecount  
  14.  
  15.   SQLNamedQuery updatecount UPDATE "countcount=count+1,accessed=now() WHERE userid='%u'" ftpuser  
  16.  
  17.   SQLLog STOR,DELE modified  
  18.  
  19.   SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser  
  20.  
  21.   QuotaEngine on  
  22.  
  23.   QuotaDirectoryTally on  
  24.  
  25.   QuotaDisplayUnits Mb  
  26.  
  27.   QuotaShowQuotas on  
  28.  
  29.   QuotaLog "/var/log/quota"  
  30.  
  31.   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}'"  
  32.  
  33.   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}'"  
  34.  
  35.   SQLNamedQuery update-quota-tally UPDATE "bytes_in_usedbytes_in_used = bytes_in_used + %{0}, bytes_out_usedbytes_out_used = bytes_out_used+ %{1}, bytes_xfer_usedbytes_xfer_used = bytes_xfer_used + %{2}, files_in_usedfiles_in_used = files_in_used + %{3}, files_out_usedfiles_out_used = files_out_used + %{4}, files_xfer_usedfiles_xfer_used = files_xfer_used + %{5} WHERE name = '%{6}' AND quota_type = '%{7}'" ftpquotatallies  
  36.  
  37.   SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" ftpquotatallies  
  38.  
  39.   QuotaLimitTable sql:/get-quota-limit  
  40.  
  41.   QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally  
  42.  

#p#

  建ftpdb库,在phpMyAdmin中导入ftpdb.sql就ok。

  --------------------------------------ftpdb.sql---------------------------------

  代码:

  1.   # 表的结构 `ftpgroup`  
  2.  
  3.   #  
  4.  
  5.   CREATE TABLE `ftpgroup` (  
  6.  
  7.   `groupname` varchar(16) NOT NULL default '',  
  8.  
  9.   `gid` smallint(6) NOT NULL default '5500',  
  10.  
  11.   `members` varchar(16) NOT NULL default '',  
  12.  
  13.   KEY `groupname` (`groupname`)  
  14.  
  15.   ) TYPE=MyISAM COMMENT='ProFTP group table';  
  16.  
  17.   #  
  18.  
  19.   # 导出表中的数据 `ftpgroup`  
  20.  
  21.   #  
  22.  
  23.   INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpuser');  
  24.  
  25.   # --------------------------------------------------------  
  26.  
  27.   #  
  28.  
  29.   # 表的结构 `ftpquotalimits`  
  30.  
  31.   #  
  32.  
  33.   CREATE TABLE `ftpquotalimits` (  
  34.  
  35.   `namevarchar(30) default NULL,  
  36.  
  37.   `quota_type` enum('user','group','class','all'NOT NULL default 'user',  
  38.  
  39.   `per_session` enum('false','true'NOT NULL default 'false',  
  40.  
  41.   `limit_type` enum('soft','hard'NOT NULL default 'soft',  
  42.  
  43.   `bytes_in_avail` float NOT NULL default '0',  
  44.  
  45.   `bytes_out_avail` float NOT NULL default '0',  
  46.  
  47.   `bytes_xfer_avail` float NOT NULL default '0',  
  48.  
  49.   `files_in_avail` int(10) unsigned NOT NULL default '0',  
  50.  
  51.   `files_out_avail` int(10) unsigned NOT NULL default '0',  
  52.  
  53.   `files_xfer_avail` int(10) unsigned NOT NULL default '0' 
  54.  
  55.   ) TYPE=MyISAM;  
  56.  
  57.   #  
  58.  
  59.   # 导出表中的数据 `ftpquotalimits`  
  60.  
  61.   #  
  62.  
  63.   INSERT INTO `ftpquotalimits` VALUES ('test''user''true''hard''9e+06''2000''9e+09', 2000, 2000, 2000);  
  64.  
  65.   # --------------------------------------------------------  
  66.  
  67.   #  
  68.  
  69.   # 表的结构 `ftpquotatallies`  
  70.  
  71.   #  
  72.  
  73.   CREATE TABLE `ftpquotatallies` (  
  74.  
  75.   `namevarchar(30) NOT NULL default '',  
  76.  
  77.   `quota_type` enum('user','group','class','all'NOT NULL default 'user',  
  78.  
  79.   `bytes_in_used` float NOT NULL default '0',  
  80.  
  81.   `bytes_out_used` float NOT NULL default '0',  
  82.  
  83.   `bytes_xfer_used` float NOT NULL default '0',  
  84.  
  85.   `files_in_used` int(10) unsigned NOT NULL default '0',  
  86.  
  87.   `files_out_used` int(10) unsigned NOT NULL default '0',  
  88.  
  89.   `files_xfer_used` int(10) unsigned NOT NULL default '0' 
  90.  
  91.   ) TYPE=MyISAM;  
  92.  
  93.   #  
  94.  
  95.   # 导出表中的数据 `ftpquotatallies`  
  96.  
  97.   #  
  98.  
  99.   INSERT INTO `ftpquotatallies` VALUES ('test''user''2000''2000''2000', 2000, 2000, 2000);  
  100.  
  101.   # --------------------------------------------------------  
  102.  
  103.   #  
  104.  
  105.   # 表的结构 `ftpuser`  
  106.  
  107.   #  
  108.  
  109.   CREATE TABLE `ftpuser` (  
  110.  
  111.   `id` int(10) unsigned NOT NULL auto_increment,  
  112.  
  113.   `userid` varchar(32) NOT NULL default '',  
  114.  
  115.   `passwd` varchar(32) NOT NULL default '',  
  116.  
  117.   `uid` smallint(6) NOT NULL default '5500',  
  118.  
  119.   `gid` smallint(6) NOT NULL default '5500',  
  120.  
  121.   `homedir` varchar(255) NOT NULL default '',  
  122.  
  123.   `shell` varchar(16) NOT NULL default '/sbin/nologin',  
  124.  
  125.   `countint(11) NOT NULL default '0',  
  126.  
  127.   `accessed` datetime NOT NULL default '0000-00-00 00:00:00',  
  128.  
  129.   `modified` datetime NOT NULL default '0000-00-00 00:00:00',  
  130.  
  131.   PRIMARY KEY (`id`)  
  132.  
  133.   ) TYPE=MyISAM COMMENT='ProFTP user table' AUTO_INCREMENT=3 ;  
  134.  
  135.   #  
  136.  
  137.   # 导出表中的数据 `ftpuser`  
  138.  
  139.   #  
  140.  
  141.   INSERT INTO `ftpuser` VALUES (1, 'test''123456', 5500, 5500, '/home/test''/sbin/nologin', 36, '2004-09-28 13:07:41''2004-09-28 13:07:42');  
  142.  

  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: - 允许传输的文件数(包括上传/下载)

  按这些步骤来安装,应该没问题。

  老实说用mysql和quota模块来验证用户和设置磁盘限额,但我总觉得还是不够完善,因为在这个方法中,数据库表里还没有相应的权限的字段,所以说相应用户的权限还是得用实际得用户即mysql对应得uid和gid来控制权限,要是mysql数据库也能完全控制权限就好了,以上就是Proftpd+Mysql+Quota的完全配置。

责任编辑:zhaolei 来源: CSDN
相关推荐

2011-03-08 15:47:57

Proftpdmysqlquota

2011-02-25 14:48:25

ProftpdMySQL

2011-03-03 13:00:21

2011-02-22 10:08:46

ProFTPD配置

2011-02-22 14:50:53

ProFTPD

2011-02-24 13:15:59

2011-02-25 16:39:34

proftpd配置文件

2011-02-23 11:15:21

DebianProFTPd

2011-02-25 12:30:01

ProFtpd配置

2011-02-24 13:42:34

2011-03-03 09:40:58

2011-02-24 14:34:57

2011-02-24 14:47:48

ProFTPD

2011-02-23 10:43:17

2011-03-03 13:16:32

Proftpd配置文件

2011-03-08 17:04:10

ProFTPDUbuntu

2011-03-07 17:15:52

ProFTPD配置

2011-02-22 16:24:30

2011-03-01 15:30:52

用MySQLProftpd

2011-02-25 15:55:25

unixProftpd
点赞
收藏

51CTO技术栈公众号