proftpd+mysql+quota

类别:软件工程 点击:0 评论:0 推荐:
发现网上很多兄弟都在为安装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

---------------------------------------------------------------
步骤如下:
代码:
vi /etc/ld.so.conf
添加:/usr/local/mysql/lib

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/
vi proftpd-1.2.9/contrib/mod_sql_mysql.c
#include</usr/local/mysql/include/mysql.h>
修改mysql.h的实际路径
cd proftpd-1.2.9
./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
make
make install
cp proftpd-1.2.9/contrib/dist/rpm/proftpd.init.d /etc/rc.d/init.d/proftpd
vi /etc/rc.d/init.d/proftpd
修改:PATH="$PATH:/usr/local/proftpd/sbin"
chmod 755 /etc/rc.d/init.d/proftpd
chkconfig --level 3 proftpd on
groupadd -g 5500 ftpgroup
adduser -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser
然后配置你的Proftpd.conf
最后就是启动啦。/usr/local/proftpd/sbin/proftpd


-------------------------------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         "ltsnet"
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.
ServerIdent off
DisplayLogin welcome.msg
DefaultRoot ~
# 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 /home/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>

SQLAuthTypes Backend Plaintext
SQLAuthenticate users* groups*

SQLConnectInfo ftpdb@localhost root 123456
SQLUserInfo ftpuser userid passwd uid gid homedir shell
SQLGroupInfo ftpgroup groupname gid members
SQLHomedirOnDemand on
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "count=count+1,accessed=now() WHERE userid='%u'" ftpuser
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_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


建ftpdb库,在phpMyAdmin中导入ftpdb.sql就ok。
--------------------------------------ftpdb.sql---------------------------------
代码:
# 表的结构 `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`)
) TYPE=MyISAM COMMENT='ProFTP group table';

#
# 导出表中的数据 `ftpgroup`
#

INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpuser');

# --------------------------------------------------------

#
# 表的结构 `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 '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;

#
# 导出表中的数据 `ftpquotalimits`
#

INSERT INTO `ftpquotalimits` VALUES ('test', 'user', 'true', 'hard', '9e+06', '2000', '9e+09', 2000, 2000, 2000);

# --------------------------------------------------------

#
# 表的结构 `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'
) TYPE=MyISAM;

#
# 导出表中的数据 `ftpquotatallies`
#

INSERT INTO `ftpquotatallies` VALUES ('test', 'user', '2000', '2000', '2000', 2000, 2000, 2000);

# --------------------------------------------------------

#
# 表的结构 `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',
  `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' AUTO_INCREMENT=3 ;

#
# 导出表中的数据 `ftpuser`
#

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');



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数据库也能完全控制权限就好了。

本文地址:http://com.8s8s.com/it/it34753.htm