Pure-FTPd 是一款免费(BSD)的,安全的,高质量和符合标准的FTP服务器。 侧重于运行效率和易用性。 它提供了简单的答案,他满足了大众化的需求,包括普通用户以及主机供应商们。
一、实验环境
导入一下文件
前期的挂载光盘,建立
yum
环境,这里就不再一一详细介绍了
[root@localhost ~]# yum install httpd php php-mysql mysql-server mysql-devel mysql –y
启动服务,并设置开机启动
[root@localhost ~]# service httpd start
[root@localhost ~]# service mysqld start
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig httpd on
为增加安全,给mysql设置口令
[root@localhost ~]# mysqladmin -u root -p password '123456'
查看是否安装以下开发所用到的rpm包组:
[root@mail ~]# yum grouplist
Development Libraries
Development Tools
Legacy Software Development
X Software Development
方法:
# yum groupinstall "packge_group_name"
二、编译安装pureftp
解压缩
[root@localhost ~]# tar zxvf pure-ftpd-1.0.36.tar.gz -C /usr/local/src
[root@localhost ~]# cd /usr/local/src/pure-ftpd-1.0.36/
[root@localhost pure-ftpd-1.0.36]# ./configure \
>
--prefix=/usr/local/pureftpd \
>
--with-mysql \
>
--with-shadow \
>
--with-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 && make install
安装之后,发现没有配置文件,新建一个文件,存放配置文件
[root@localhost ~]# mkdir /usr/local/pureftpd/etc
Copy配置文件到指定位置
[root@localhost ~]# cd /usr/local/src/pure-ftpd-1.0.36/
[root@localhost pure-ftpd-1.0.36]# cd configuration-file/
[root@localhost configuration-file]# cp pure-ftpd.conf /usr/local/pureftpd/etc/
由于启动pureftpd需要调用pure-config.pl ,也需要copy到相应位置
[root@localhost configuration-file]# chmod 755 pure-config.pl
[root@localhost configuration-file]# cp pure-config.pl /usr/local/pureftpd/sbin
生成pure-ftpd的服务脚本
[root@localhost ~]# cd /usr/local/src/pure-ftpd-1.0.36/
[root@localhost pure-ftpd-1.0.36]# cd contrib
[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
指定文件的位置
17 prog=pure-config.pl
18 fullpath=/usr/local/pureftpd/sbin/$prog
19 pureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho
24 $fullpath /usr/local/pureftpd/etc/pure-ftpd.conf –daemonize
启动pureftpd,可以看到启动成功
[root@localhost ~]# service pureftpd start
Starting pure-config.pl: Running: /usr/local/pureftpd/sbin/pure-ftpd --daemonize -A -c50 -B -C8 -D -fftp -H -I15 -L10000:8 -m4 -s -U133:022 -u100 -k99 –Z
添加到服务启动列表,并设置自动启动
[root@localhost ~]# chkconfig --add pureftpd
[root@localhost ~]# chkconfig pureftpd on
三、配置匿名用户登录环境
1.配置虚拟用户登录环境
[root@localhost ~]# mkdir /ftproot
[root@localhost ~]# chmod -R 777 /ftproot
[root@localhost ~]# useradd virtualftp -d /ftproot -s /sbin/nologin -M
[root@localhost ~]# chown virtualftp:virtualftp /ftproot
2.修改配置文件
[root@localhost ~]# vim /usr/local/pureftpd/etc/pure-ftpd.conf
##修改内容如下
52 MaxClientsPerIP
2
##为了测试,设置每个ip最多打开2个连接
77 NoAnonymous
yes
##不允许匿名帐号登录
116 MySQLConfigFile
/usr/local/pureftpd/etc/pureftpd-mysql.conf
##mysql的配置文件,通过配置文件来调用mysql
336 CreateHomeDir
yes
##创建家目录
3.将mysql的配置文件copy到相应的位置
[root@localhost ~]# cp pureftpd-mysql.conf /usr/local/pureftpd/etc/
编辑配置文件
[root@localhost ~]# cd /usr/local/pureftpd/etc/
[root@localhost etc]# vim pureftpd-mysql.conf
32 MYSQLPassword
tmppasswd
##数据库密码
45 MYSQLCrypt
md5
##采用md5加密
4.创建数据库,编写数据库pureftp.sql文件,然后导入
[root@localhost ~]# vim pureftp.sql
- -- This mysql script is made by M.Mastenbroek 2002 - 2005
- -- For more info look at http://machiel.generaal.net
- -- Version 2.0
- --
- -- You don't need this script when you already have the database
- -- or when you use the install.php configuration script successfully.
- --
- -- Example how to execute this script from command line:
- --
- -- mysql -u root -ppassword -h 127.0.0.1 < script.mysql
- --
- --
- --
- -- Host: localhost Database: ftpusers
- -- -------------------------------------------------------
- -- Server version 3.23 or 4.x
- -- Script version 1.4.0
- --
- --
- --
- -- Create MySQL user called 'ftp'
- -- Login = ftp
- -- Password = tmppasswd
- -- Host = 127.0.0.1
- --
-
- INSERT INTO mysql.user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv) VALUES('localhost','ftp',PASSWORD('passwd'),'Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N');
-
-
- FLUSH PRIVILEGES;
-
- CREATE DATABASE ftpusers;
-
- USE ftpusers;
-
- --
- -- Table structure for table 'admin'
- --
-
- CREATE TABLE admin (
- Username varchar(35) NOT NULL default '',
- Password char(32) binary NOT NULL default '',
- PRIMARY KEY (Username)
- ) TYPE=MyISAM;
-
- --
- -- Data for table 'admin'
- --
-
-
- INSERT INTO admin VALUES ('admin',MD5('123'));
-
- --
- -- Table structure for table 'users'
- --
-
- 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`)
- ) TYPE=MyISAM;
-
- --
- -- Data for table 'users'
- --
导入数据库pureftp
[root@localhost ~]# mysql -u root -p < pureftp.sql
查看是否导入成功
[root@localhost ~]# mysql -u root -p
Enter password:
mysql> use ftpusers;
##查看数据库表
[root@localhost ~]# mysql -u root -p
Enter password:
##用root登录数据库,更改验证方式
mysql> grant all privileges on ftpusers.* to ftp@localhost identified by 'tmppasswd';
mysql> flush privileges;
mysql> \quit
Bye
[root@localhost ~]#
四、实现web后台管理
[root@localhost ~]# tar zxvf PureAdmin-0.3.tar.gz -C /var/www/html
[root@localhost ~]# cd /var/www/html
[root@localhost html]# mv PureAdmin-0.3 pureadmin
##修改一下文件名,方便修改
[root@localhost html]# cd pureadmin/
[root@localhost pureadmin]# vim config.php
3 $cfg['dbname']='ftpusers'; //mysql db name
##数据库的名字
4 $cfg['dbuser']='ftp';
//mysql user
##连接数据库的帐号
5 $cfg['dbpasswd']='tmppasswd';
//mysql password
##密码
10 $cfg['passwdtype']='MD5';
##加密方式
14 $cfg['dir']='/ftproot/'; //dir
##根目录
##其他项也可以自己修改
虚拟帐号域本地帐号映射
[root@localhost ~]# vim /usr/local/pureftpd/etc/pure-ftpd.conf
126 PureDB
/usr/local/pureftpd/pureftpd.pdb
##指明pure-pw的路径
[root@localhost ~]# echo PATH=$PATH:/usr/local/pureftpd/bin >>/etc/profile
##修改环境变量
[root@localhost ~]# . /etc/profile
##环境变量立即生效
[root@localhost ~]# pure-pw useradd user2 -u virtualftp -g virtualftp -d /ftproot/user2 -m
Password:
Enter it again:
##添加虚拟帐号user2
[root@localhost ~]# pure-pw mkdb /usr/local/pureftpd/pureftpd.pdb
##建立用户数据库
说明:今后每添加或修改用户数据库都应该执行一次mkdb
重新启动服务
[root@localhost ~]# service httpd restart
Stopping httpd: ^[[B
[ OK ]
Starting httpd:
[ OK ]
[root@localhost ~]# service mysqld restart
Stopping MySQL:
[ OK ]
Starting MySQL:
[ OK ]
[root@localhost ~]# service pureftpd restart
五、测试
1.用web方式登录
2.添加帐号
3.用帐号user1登录