一、基本原理
Pure-FTPd 是一款免费(BSD)的,安全的,高质量和符合标准的FTP服务器。 侧重于运行效率和易用性。 它提供了简单的答案,他满足了大众化的需求,包括普通用户以及主机供应商们。
实现功能:通过web管理ftp用户,实现新增、删除、密码修改、上传/下载限速、磁盘限额、文件数量等。
二、准备工作
(1)下载所需软件包
#wget ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.36.tar.gz
(2)下载phpweb管理组件
wget http://www.yiyou.org/docs/PureAdmin_03_php/PureAdmin-0.3.tar.gz
wget http://www.yiyou.org/docs/PureAdmin_03_php/pureftp.sql
wget http://www.yiyou.org/docs/PureAdmin_03_php/pureftpd-mysql.conf
(3)源码安装需具备以下4个开发环境
[root@localhost ~]# yum grouplist
开发工具
开发库
老的软件开发
X 软件开发
(4)将所需文件拷到root目录下
二、安装与配置
(1)apache,php,mysql安装
[root@localhost Server]# yum install -y httpd php php-mysql mysql mysql-server mysql-devel
[root@localhost Server]# service httpd start
[root@localhost Server]# service mysqld start
[root@localhost Server]# mysqladmin -u root -p password '123456'
(2)源码安装pure-ftpd
[root@localhost pureftp]# tar -zxvf pure-ftpd-1.0.36.tar.gz -C /usr/local/src/
[root@localhost pureftp]# cd /usr/local/src/pure-ftpd-1.0.36/
[root@localhost pure-ftpd-1.0.36]# ./configure \
> --prefix=/usr/local/pureftpd \ //安装目录
> --with-mysql \ //ftp服务器支持mysql验证
> --with-shadow \ //支持本地的
> --with-pam \ //支持pam进行身份验证
> --with-welcomemsg \ //欢迎信息
> --with-uploadscript \ //上传之后可以支持的脚本
> --with-cookie \ //缓存
> --with-virtualchroot \ //支持软连接
> --with-virtualhosts \ //支持虚拟主机
> --with-diraliases \ //支持目录别名
> --with-quotas \ //配额
> --with-puredb \ //用来存放虚拟账号和本地账号映射关系的数据库
> --with-sysquotas \ //跟配额相关的
> --with-ratios \
> --with-ftpwho \
> --with-throttling \ //溢值
> --with-language=simplified-chinese //支持简体中文
[root@localhost pure-ftpd-1.0.36]# make
[root@localhost pure-ftpd-1.0.36]# make install
新建一个etc目录
[root@localhost pure-ftpd-1.0.36]# mkdir /usr/local/pureftpd/etc
拷贝conf配置文件到etc目录下
[root@localhost pure-ftpd-1.0.36]# cd configuration-file/
[root@localhost configuration-file]# ll
总计 84
-rw-r--r-- 1 root root 11073 08-31 01:43 Makefile
-rw-r--r-- 1 1000 games 67 03-16 09:01 Makefile.am
-rw-r--r-- 1 1000 games 9982 03-22 04:17 Makefile.in
-rw-r--r-- 1 root root 4696 08-31 01:43 pure-config.pl
-rw-r--r-- 1 1000 games 4689 03-16 09:01 pure-config.pl.in
-rw-r--r-- 1 root root 7717 08-31 01:43 pure-config.py
-rw-r--r-- 1 1000 games 7679 2011-04-17 pure-config.py.in
-rw-r--r-- 1 root root 11211 08-31 01:43 pure-ftpd.conf
-rw-r--r-- 1 1000 games 11189 03-16 09:01 pure-ftpd.conf.in
[root@localhost configuration-file]# cp pure-ftpd.conf /usr/local/pureftpd/etc/
Pure-config.pl是可执行的,赋予权限并拷到sbin目录
设置权限
[root@localhost configuration-file]# chmod 755 pure-config.pl
[root@localhost configuration-file]# cp pure-config.pl /usr/local/pureftpd/sbin
[root@localhost configuration-file]# cd ..
[root@localhost pure-ftpd-1.0.36]# cd contrib/
[root@localhost contrib]# ls
Makefile Makefile.in pure-vpopauth.pl suse.init
Makefile.am pure-stat.pl redhat.init xml_python_processors.txt
[root@localhost contrib]# cp redhat.init /etc/init.d/pureftpd
控制脚本是可执行的
[root@localhost contrib]# chmod 755 /etc/init.d/pureftpd
[root@localhost contrib]# vim /etc/init.d/pureftpd
[root@localhost contrib]# service pureftpd start
[root@localhost contrib]# mkdir /ftproot
[root@localhost contrib]# chmod -R 777 /ftproot //这不不做可以能会引起登录时报421错误
[root@localhost contrib]# useradd virtualftp -d /ftproot -s /sbin/nologin -M //创建接下来的虚拟用户对应的系统用户
[root@localhost contrib]# chown virtualftp:virtualftp /ftproot
[root@localhost contrib]# vim /usr/local/pureftpd/etc/pure-ftpd.conf
保证配置文件有以下几项
chrootEveryone yes //限定在自己的家目录
77 NoAnonymous yes //不允许匿名登录
115 MySQLConfigFile /usr/local/pureftpd/etc/pureftpd-mysql.conf //使用mysql验证与apache整合
335 CreateHomeDir yes //允许用户登录后自动创建家目录
Bind 127.0.0.1,21 监听本机回环 <可选>
Bind 192.168.0.254,21 监听本机IP <自行添加的,非必须>
[root@localhost pureftp]# cp pureftpd-mysql.conf /usr/local/pureftpd/etc/
[root@localhost pureftp]# vim /usr/local/pureftpd/etc/pureftpd-mysql.conf
修改一下2行
32 MYSQLPassword tmppasswd //mysql密码
45 MYSQLCrypt md5 //加密方式,这里用md5
[root@localhost pureftp]# vim pureftp.sql
22 -- Login = ftp 此为登录数据库的用户
23 -- Password = tmppasswd 此为登录数据库的密码
31 CREATE DATABASE ftpusers; 创建名为ftpusers的库
50 INSERT INTO admin VALUES ('admin',MD5('123')); 此为登录web用的用户密码,可自行修改
导入数据,导入前可能需要修改此sql文件的15行:前2个减号空一格
15-- -------------------------------------------------------
[root@localhost pureftp]# mysql -u root -p < pureftp.sql
Enter password:
[root@localhost pureftp]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ftpusers |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use ftpusers;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------+
| Tables_in_ftpusers |
+--------------------+
| admin |
| users |
+--------------------+
2 rows in set (0.00 sec)
mysql> select * from admin;
+----------+----------------------------------+
| Username | Password |
+----------+----------------------------------+
| admin | 202cb962ac59075b964b07152d234b70 |
+----------+----------------------------------+
1 row in set (0.00 sec)
mysql> grant all privileges on ftpusers.* to ftp@localhost identified by 'tmppasswd';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
[root@localhost pureftp]# tar -zxvf PureAdmin-0.3.tar.gz -C /var/www/html/
[root@localhost pureftp]# cd /var/www/html/
[root@localhost html]# mv PureAdmin-0.3 pureadmin
[root@localhost html]# cd pureadmin/
[root@localhost pureadmin]# vim config.php
<?php
$cfg['dbhost']='localhost'; //mysql host
$cfg['dbname']='ftpusers'; //mysql db name 所用的库<与前面导入的sql中要一致>
$cfg['dbuser']='ftp'; //mysql user 登录mysql的帐号
$cfg['dbpasswd']='tmppasswd'; //mysql password 登录mysql的密码
//ftp config
$cfg['page']=10; 每页显示的用户数量
//ftp passwd type : TEXT/CRYPT/MD5
$cfg['passwdtype']='MD5'; 认证模式<要与pureftpd-mysql.conf中一致>
//ftp default
$cfg['uid']=500; //uid 映射虚拟用户的UID,即刚创建的virtualftp用户
$cfg['gid']=500; //gid 同上
$cfg['dir']='/ftproot/'; //dir 默认家目录
$cfg['qf']=0; //quotafiles 文件个数限制,0为不限制
$cfg['qs']=100; //quotasize 总文件大小
$cfg['ul']=0; //ULBandwidth 上传速率限制
$cfg['dl']=200; //DLBandwidth 下载速率限制
$cfg['ur']=0; //ULRatio 上传比
$cfg['dr']=0; //DLRatio 下载比
$cfg['status']=1; //status 状态,1为激活;0为禁止
$cfg['ip']= '*'; //ipaddress 可访问IP,*为所有
?>
http://localhost/pureadmin
登录:用户admin ; 密码123456 ;验证码不用
创建的虚拟用户家目录,会在虚拟用户第一次登录时自动创建
登陆成功后新建一个user1用户并保存
登陆数据库查看user1用户
[root@localhost pureadmin]# mysql -u root -p
Enter password:
mysql> use ftpusers
mysql> show tables;
+--------------------+
| Tables_in_ftpusers |
+--------------------+
| admin |
| users |
+--------------------+
2 rows in set (0.00 sec)
mysql> select * from users ;
+-------+----------------------------------+------+------+----------------+------------+-----+--------+---------+---------+
| User | Password | Uid | Gid | Dir | QuotaFiles | Quot| Status | ULRatio | DLRatio |
+-------+----------------------------------+------+------+----------------+------------+-----+--------+---------+---------+
| user1 | 74be16979710d4c4e7c6647856088456 | 1000 | 1000 | /ftproot/user1 | 0 | | 1 | 0 | 0 |
+-------+----------------------------------+------+------+----------------+------------+-----+--------+---------+---------+
1 row in set (0.00 sec)
修改配置文件
[root@localhost ftproot]# vim /usr/local/pureftpd/etc/pure-ftpd.conf
125 PureDB /usr/local/pureftpd/pureftpd.pdb
设置环境变量
[root@localhost pureftpd]# echo PATH=$PATH:/usr/local/pureftpd/bin/ >>/etc/profile
[root@localhost pureftpd]# . /etc/profile
添加用户user2举例
[root@localhost pureftpd]# pure-pw useradd user2 -u virtualftp -g virtualftp -d /ftproot/user2 -m
Password:
Enter it again:
说明:
User2是用户名,-u virtualftp是其实际的linux用户,-d指定起始目录,并锁定于该目录。如果不锁定,则用-D;如果需要不同的权限,可以建立新的linux用户与组
如果用的系统自带的ftp用户,这样的话还需修改配置文件pure-ftpd.conf中的MinUID为ftp用户的UID 14,否则登录时会出现530错误;所以这里建议创建另一个非系统自带的用户做映射
建立用户数据库:
[root@localhost pureftpd]# pure-pw mkdb /usr/local/pureftpd/pureftpd.pdb
说明:今后每添加或修改用户数据库都应该执行一次mkdb
新建user3和user4用户
[root@localhost pureftpd]# cd /ftproot/
[root@localhost ftproot]# ll //自动创建了目录user3,user4
总计 8
drwxr-xr-x 2 virtualftp virtualftp 4096 08-31 03:48 user2
drwxr-xr-x 2 1000 1000 4096 08-31 03:49 user3
主机测试
[root@localhost ftproot]# cd user3
新建一个f1文件
[root@localhost user3]# touch f1
实现了web创建、管理虚拟用户