LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1183|回复: 1

pureftpd+mysql+quota+pureftpd_php_manager实现磁盘配额

[复制链接]
发表于 2004-11-13 04:30:11 | 显示全部楼层 |阅读模式
本文主要讲述的是安装pureftpd的过程,目标是实现ftpd服务,并且具备磁盘配额,用户实时添加等功能,并不一定适合大形网站,并有可能存在某些安全隐患,只能作交流于参考!
参考大量文献后,总结而来,虽不能算100%原创,但转载时,仍请注明出自 LinuxSir.org,非常感激您的合作! .
一,系统支持
系统中需要安装有 Mysql+Apache+PHP+(Dns可选).
二,准备软件
Ftpd Server :
pure-ftpd-1.0.20.tar.gz
pureftpd_php_manager:
pureftpd_php_manager.tar.gz

三,定制安装
1:解压缩
到下载的两个文件所在目录.
#cd download
#tar zxvf pure-ftpd-1.0.20.tar.gz
#tar zxvf pureftpd_php_manager.tar.gz
2:编译
#cd pure-ftpd-1.0.20

#./configure \
--prefix=/usr/local/pureftpd \
--with-mysql=/usr/local/mysql \
--with-paranoidmsg \
--with-shadow \
--with-welcomemsg \
--with-uploadscript \
--with-quotas \
--with-cookie \
--with-pam \
--with-virtualhosts \
--with-virtualroot \
--with-diraliases \
--with-sysquotas \
--with-ratios \
--with-ftpwho \
--with-throttling
--with-mysql=/usr/local/mysql \ 此处的 /usr/local/mysql 请改为你的mysql实际安装路径.如果出现类似configure: error: Your MySQL client libraries aren't properly installed 的错误,请将mysql目录下的 include/mysql下的mysql.h文件以及lib/mysql下的全部文件,连接(直接复制过去或许也可)到 /usr/lib 目录下
3:安装
#make
#make check
#make install
#cd configuration-file
#chmod u+x pure-config.pl
#cp pure-config.pl /usr/local/sbin/
#cp pure-ftpd.conf /usr/local/etc/
将pureftpd_php_manager目录拷贝到网站目录下
cp -R pureftpd_php_manager /opt/www/pureftpd_php_manager

四,配置服务
1:编辑/usr/local/etc/pure-ftpd.conf文件
找到
#CreateHomeDir               yes
改为
CreateHomeDir               yes
#作用是,用户登录,如果主目录不存在,便自动建立.
#此处的设置并不是变大就可以让新建立的文件拥有更多的权限,而是相反,比如这里设置的133:022对应的上传成功后的文件属性为755:644,特别更正此处。
Umask                       133:022
#设定新文件的默认属性.此处作用不确定.有待商榷!
找到
# MySQLConfigFile               /etc/pureftpd-mysql.conf
#改为
MySQLConfigFile               /usr/local/etc/pureftpd-mysql.conf
#设定ftpd服务的参数取得为pureftpd-mysql.conf
文件设置
#######################
存盘退出.
2:编辑/usr/local/etc/pureftpd-mysql.conf文件
它的大概样子是这样的

  1. ##############################################
  2. #                                            #
  3. # Sample Pure-FTPd Mysql configuration file. #
  4. # See README.MySQL for explanations.         #
  5. #                                            #
  6. ##############################################


  7. # Optional : MySQL server name or IP. Don't define this for unix sockets.

  8. MYSQLServer     localhost
  9. #服务器地址

  10. # Optional : MySQL port. Don't define this if a local unix socket is used.

  11. MYSQLPort       3306

  12. #服务器端口
  13. # Optional : define the location of mysql.sock if the server runs on this host.

  14. MYSQLSocket     /opt/mysql/var/mysql.sock
  15. #这里换成你的真实地址

  16. # Mandatory : user to bind the server as.

  17. MYSQLUser       root
  18. #登录服务器用户名

  19. # Mandatory : user password. You must have a password.

  20. MYSQLPassword   123456
  21. #登录服务器密码

  22. # Mandatory : database to open.
  23. MYSQLDatabase   ftpd
  24. #配置文件所在的数据库

  25. # Mandatory : how passwords are stored
  26. # Valid values are : "cleartext", "crypt", "md5" and "password"
  27. # ("password" = MySQL password() function)
  28. # You can also use "any" to try "crypt", "md5" *and* "password"

  29. MYSQLCrypt      cleartext
  30. #验证方式

  31. # In the following directives, parts of the strings are replaced at
  32. # run-time before performing queries :
  33. #
  34. # \L is replaced by the login of the user trying to authenticate.
  35. # \I is replaced by the IP address the user connected to.
  36. # \P is replaced by the port number the user connected to.
  37. # \R is replaced by the IP address the user connected from.
  38. # \D is replaced by the remote IP address, as a long decimal number.
  39. #
  40. # Very complex queries can be performed using these substitution strings,
  41. # especially for virtual hosting.


  42. # Query to execute in order to fetch the password

  43. MYSQLGetPW      SELECT Password FROM users WHERE User="\L" AND  status="1"
  44. #登录服务器的用户密码验证字段,status="1"为此用户必需为激活模式.

  45. # Query to execute in order to fetch the system user name or uid

  46. MYSQLGetUID     SELECT Uid FROM users WHERE User="\L"
  47. #用户的UID

  48. # Optional : default UID - if set this overrides MYSQLGetUID

  49. #MYSQLDefaultUID 1000


  50. # Query to execute in order to fetch the system user group or gid

  51. MYSQLGetGID     SELECT Gid FROM users WHERE User="\L"

  52. #用户的Gid
  53. # Optional : default GID - if set this overrides MYSQLGetGID

  54. #MYSQLDefaultGID 1000


  55. # Query to execute in order to fetch the home directory

  56. MYSQLGetDir     SELECT Dir FROM users WHERE User="\L"
  57. #用户的主目录

  58. # Optional : query to get the maximal number of files
  59. # Pure-FTPd must have been compiled with virtual quotas support.

  60. MySQLGetQTAFS  SELECT QuotaFiles FROM users WHERE User="\L"

  61. #用户的最大文件数量
  62. # Optional : query to get the maximal disk usage (virtual quotas)
  63. # The number should be in Megabytes.
  64. # Pure-FTPd must have been compiled with virtual quotas support.

  65. MySQLGetQTASZ  SELECT QuotaSize FROM users WHERE User="\L"
  66. #用户的最大磁盘空间

  67. # Optional : ratios. The server has to be compiled with ratio support.

  68. MySQLGetRatioUL SELECT  ULBandwidth FROM users WHERE User="\L"
  69. MySQLGetRatioDL SELECT  DLBandwidth FROM users WHERE User="\L"
  70. #上边两项为,用户上传与下载的速度,单位 Kb/s

  71. # Optional : bandwidth throttling.
  72. # The server has to be compiled with throttling support.
  73. # Values are in KB/s .

  74. # MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User="\L"
  75. # MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User="\L"

  76. # Enable ~ expansion. NEVER ENABLE THIS BLINDLY UNLESS :
  77. # 1) You know what you are doing.
  78. # 2) Real and virtual users match.

  79. # MySQLForceTildeExpansion 1


  80. # If you upgraded your tables to transactionnal tables (Gemini,
  81. # BerkeleyDB, Innobase...), you can enable SQL transactions to
  82. # avoid races. Leave this commented if you are using the
  83. # traditionnal MyIsam databases or old (< 3.23.x) MySQL versions.

  84. # MySQLTransactions On
复制代码

保存退出
请按您的实际情况修改.或者直接找错后复制过去.
3:修改:/opt/www/pureftpd_php_manager/pureftp.config.php文件
  1. ######################
  2. ####### SETUP ########
  3. ######################


  4.         // 设置pureftpd-mysql.conf的位置,这个要注意,不要写错哦
  5.         $PUREFTP_CONFIG_FILE    = '/usr/local/etc/pureftpd-mysql.conf';

  6.         // The location where all the Forms directed to. (Mayby no change needed)
  7.         $SELF_URL                               = 'index.php';

  8.         // The location of your pure-ftpdwho binary  (set this to chmod 4711)
  9.         $FTP_WHO                                = "/usr/local/sbin/pure-ftpwho";

  10. #######################
  11. # DEFAULT NEW-USER PARAMS #
  12. #######################
  13.    $DB_TABLE='users';                 #新增加变量,定义数据表名
  14.    $DefaultUser = "ftpuser";                  # 默认用户
  15.         $DefaultPass = "passwd";                   # 默认初始用户密码
  16.         $DefaultUid = "48";                      # 默认的uid(设置为apache的uid,你的或许不是48,为PHP建立的目录能够正常使用而设置)
  17.        $DefaultGid = "48";                          # 默认的gid(设置为apache的gid,你的或许不是48,为PHP建立的目录能够正常使用而设置)
  18.        $DefaultDir = "/var/ftproot/ftpusershome";     # 默认的用户主目录
  19.         $DefaultUL = "0";                          # 默认用户上传速率限制(KB/S)
  20.         $DefaultDL = "0";                          # 默认用户下载速率限制(KB/S)
  21.         $Defaultip = "*";                               # 设置用户可以从哪些IP登陆
  22.         $DefaultQS = "50";                         # 用户默认的quota
  23.         $Defaultcmt = "";                               # 默认备注信息
  24.         $DefaultQF = "0";                          # 默认文件数目quota
  25.         $PWC = "55";                               # Vorsatz fuerr Crypt Password
复制代码

保存退出
4:修改/opt/www/pureftpd_php_manager/index.php文件
找到
  1. echo '<tr><th>UID</th><td class=TD><input type="text" name="requireduid" value="'.stripslashes($USERARRAY['Uid']).'" class="input"></td></tr>';
复制代码

改为
  1. echo '<tr><th></th><td class=TD><input type="hidden" name="requireduid" value="'.stripslashes($USERARRAY['Uid']).'" class="input"></td></tr>';
复制代码

找到
  1. echo '<tr><th>UID</th><td class=TD><input type="text" name="requireduid" value="'.stripslashes($USERARRAY['Uid']).'" class="input"></td></tr>';
复制代码

改为
  1. echo '<tr><th></th><td class=TD><input type="hidden" name="requiredgid" value="'.stripslashes($USERARRAY['Gid']).'" class="input"></td></tr>';
复制代码

找到
  1.                         $SQL        = "UPDATE `$DB_TABLE` SET status='$status'".$PW_QUERY.",Uid='$Uid',Gid='$Gid',Dir='$Dir',ULBandwidth='$ULThrottle',DLBandwidth='$DLThrottle',comment='$comment',ipaccess='$ipaccess',QuotaSize='$QuotaSize',QuotaFiles='$QuotaFiles' WHERE User LIKE '$User' LIMIT 1";
复制代码

将Dir='$Dir'改为Dir='$userdir'
在其上边增加
[PHP]$userdir='/opt/ftp/'.$User;
                        if(!@opendir($userdir)){
                        mkdir($userdir, 0755);
                        @chgrp($userdir,"ftpusers");
                        @chown($userdir,"ftpusers");
////////$userdir为你希望的目录
                        }[/PHP]
找到
  1.                         $Q                = DB_QUERY("INSERT INTO `$DB_TABLE` SET User='$User',status='$status'".$PW_QUERY.",Uid='$Uid',Gid='$Gid',Dir='$Dir',ULBandwidth='$ULThrottle',DLBandwidth='$DLThrottle',comment='$comment',ipaccess='$ipaccess',QuotaSize='$QuotaSize',QuotaFiles='$QuotaFiles'");
复制代码

将Dir='$Dir'改为Dir='$userdir'
在其上边增加
[PHP]$userdir='/opt/ftp/'.$User;
                        if(!@opendir($userdir)){
                        mkdir($userdir, 0755);
                        @chgrp($userdir,"ftpusers");
                        @chown($userdir,"ftpusers");
////////$userdir为你希望的目录
                        }[/PHP]
五,创建启动服务环境

1:创见用户和组
#groupadd ftpusers
#useradd ftpusers -g ftpusers
2创建数据库,以及数据表.
mysql>DROP TABLE IF EXISTS ftpd;
      CREATE TABLE users (
      User varchar(16) NOT NULL default '',
      status enum('0','1') NOT NULL default '0',
      Password varchar(64) NOT NULL default '',
      Uid varchar(11) NOT NULL default '-1',
      Gid varchar(11) NOT NULL default '-1',
      Dir varchar(128) NOT NULL default '',
      ULBandwidth smallint(5) NOT NULL default '0',
      DLBandwidth smallint(5) NOT NULL default '0',
      comment tinytext NOT NULL,
      ipaccess varchar(15) NOT NULL default '*',
      QuotaSize smallint(5) NOT NULL default '0',
      QuotaFiles int(11) NOT NULL default 0,
      PRIMARY KEY (User),
      UNIQUE KEY User (User)
      ) TYPE=MyISAM;
或者使用phpmyadmin创见上边的数据表和数据库数据库名为ftpd.
六,启动服务
1:启动服务需要给定一些参数,以告知服务配置文件的位置.
#/usr/local/pureftpd/sbin/pure-ftpd -l mysql:/usr/local/etc/pureftpd-mysql.conf &
服务正常启动的话,恭喜你,接近成功了.
2:登录后台管理页面(强烈建议您,为此页面增加验证功能)
http://localhost/pureftpd_php_manager/index.php
增加一个用户.
用刚刚增加的用户登录吧,您发现了什么呢?是否实现了所要的功能?如果是,那恭喜您.
参考文献:参考文献:

PureFTPd 系列中文文档之 README.MySQL PureFTPd 系列中文文档之PureFTPd 配置文件
最后祝您成功!
发表于 2005-8-23 17:24:48 | 显示全部楼层
按照上面的作··却发现数据库验证不了…………
提示为530 Authentication failed, sorry ftp: Login failed
怎么回事呢?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表