ubuntu12.04 LTS上配置pure-ftpd+mysql+pureadmin,使用mysql认证

初始化用户和组

groupadd  -g 2001 ftpgroup
useradd  -u 2001 -g ftpgroup  -d /dev/null -s /sbin/nologin ftpuser

安装pure-ftpd和 mysql组件

apt-get install pure-ftpd pure-ftpd-mysql

修改mysql的连接配置文件

emacs /etc/pure-ftpd/db/mysql.conf  

MYSQLSocket       /var/lib/mysql/mysql.sock  # mysql.sock文件
MYSQLUser          ftpuser                           # mysql用户名
MYSQLPassword   ftppass                           # mysql密码
MYSQLDatabase   ftpname                          # mysql数据库名
MYSQLCrypt         md5                               #加密方式,这里用md5加密

MYSQLGetPW      SELECT Password FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MYSQLGetUID     SELECT Uid FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MYSQLGetGID     SELECT Gid FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MYSQLGetDir     SELECT Dir FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MySQLGetQTAFS  SELECT QuotaFiles FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MySQLGetQTASZ  SELECT QuotaSize FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MySQLGetRatioUL SELECT ULRatio FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MySQLGetRatioDL SELECT DLRatio FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User="\L" AND Status="1" AND (Ipaddress = "*" OR Ipaddress LIKE "\R")

数据库部分
初始化虚拟用户的数据库,包括管理员的用户


mysql> create database pureftpd;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on pureftpd.* to 'vsftpd_user'@'localhost' identified by 'vsftpd_pass';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> use pureftpd;

CREATE TABLE `users` (
 `User` varchar(16) NOT NULL default '',
 `Password` varchar(32) binary NOT NULL default '',
 `Uid` int(11) NOT NULL default '14',
 `Gid` int(11) NOT NULL default '5',
 `Dir` varchar(128) NOT NULL default '',
 `QuotaFiles` int(10) NOT NULL default '500',
 `QuotaSize` int(10) NOT NULL default '30',
 `ULBandwidth` int(10) NOT NULL default '80',
 `DLBandwidth` int(10) NOT NULL default '80',
 `Ipaddress` varchar(15) NOT NULL default '*',
 `Comment` tinytext,
 `Status` enum('0','1') NOT NULL default '1',
 `ULRatio` smallint(5) NOT NULL default '1',
 `DLRatio` smallint(5) NOT NULL default '1',
 PRIMARY KEY  (`User`),
 UNIQUE KEY `User` (`User`)
);

CREATE TABLE admin (
 Username varchar(35) NOT NULL default '',
 Password char(32) binary NOT NULL default '',
 PRIMARY KEY  (Username)
);

INSERT INTO admin VALUES('admin',MD5('passwd'));
commit;

下载并在apache里配置
http://machiel.generaal.net/index.php?subject=user_manager_pureftpd

emacs /var/www/ftp_manage/htdocs/config.php
  $LANG = "Chinese";                  // See the directory language for the available languages.

  $LocationImages =  "images";        // Location of images

  $DBHost = "127.0.0.1";              // Ip-address of MySQL server
                                      // (Don?t change this if you are using the default database)

  $DBLogin = "vsftpd_user";                   // Username of MySQL user

  $DBPassword = "vsftpd_pass";          // Password of MySQL user

  $DBDatabase = "pureftpd";           // Name of database

  $FTPAddress = "xsudo.com:21";   // Domain name or ip-address of your ftp server

  $DEFUserID = "2001"; // nobody     // Default user id of virtual ftp user.

  $DEFGroupID = "2001";   // guest      // Default group is of virtual ftp user.

  $UsersFile = "/etc/passwd";        // The unix user file

  $GroupFile = "/etc/group";         // The unix group file


echo yes > /etc/pure-ftpd/conf/DontResolve

# 屏蔽系统用户登录

echo no > /etc/pure-ftpd/conf/UnixAuthentication
echo no > /etc/pure-ftpd/conf/PAMAuthentication


echo 10 > /etc/pure-ftpd/conf/MaxClientsNumber
echo 10 >  /etc/pure-ftpd/conf/MaxClientsPerIP 
# 重启生效
service pure-ftpd-mysql restart

这些最后都会变成参数
比如启动以后就会变成

usr/sbin/pure-ftpd-mysql -l mysql:/etc/pure-ftpd/db/mysql.conf -l pam -H -8 UTF-8 -C 5 -O clf:/var/log/pure-ftpd/transfer.log -c 10 -u 1000 -E -B

-C就是maxclientsperip
-H就是dontresolve yes

参考
http://zhumeng8337797.blog.163.com/blog/static/100768914201010492823557/
http://machiel.generaal.net/index.php?subject=user_manager_pureftpd