RedHat平台下pureftpd搭建

来源:互联网 发布:大兴灭门案 知乎 编辑:程序博客网 时间:2024/05/29 02:09

 

RedHat平台下pureftpd搭建

一、系统:

CentOS 5.3

 

二、软件以及下载地址

pure-ftpd-1.0.24.tar.gz

ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.24.tar.gz

 

三、说明:用来控制用户的ftp上传功能,仅允许ftp用户在自己的目录文件下操作其网站。前提:CentOS 5.3具有搭建好的LAMP环境。

   

四、搭建环境

1、编译安装pureftp 源代码http://www.pureftpd.org/

[root@localhost src]$ wget ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.24.tar.gz

--16:21:29--  ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.24.tar.gz

           => `pure-ftpd-1.0.24.tar.gz.1'

正在解析主机 ftp.pureftpd.org... 91.121.49.42

Connecting to ftp.pureftpd.org|91.121.49.42|:21... 已连接。

正在以 anonymous 登录 ... 登录成功!

==> SYST ... 完成。    ==> PWD ... 完成。

==> TYPE I ... 完成。  ==> CWD /pub/pure-ftpd/releases ... 完成。

==> SIZE pure-ftpd-1.0.24.tar.gz ... 560565

==> PASV ... 完成。    ==> RETR pure-ftpd-1.0.24.tar.gz ... 完成。

长度:560565 (547K)

 

100%[=======================================>] 560,565     10.5K/s   in 28s

 

16:22:04 (19.3 KB/s) - `pure-ftpd-1.0.24.tar.gz.1' saved [560565]

 

[root@localhost src]$tar zxvf pure-ftpd-1.0.24.tar.gz

pure-ftpd-1.0.24/

pure-ftpd-1.0.24/aclocal.m4

… …

pure-ftpd-1.0.24/configuration-file/pure-config.py.in

pure-ftpd-1.0.24/configuration-file/pure-ftpd.conf.in

 

[root@localhost pure-ftpd-1.0.24]#

 ./configure --prefix=/usr/local/pureftpd --with-cookie --with-throttling --with-ratios --with-quotas --with-sysquotas --with-largefile --with-welcomemsg --with-upload_script_ --with-virtualhosts --with-virtualroot --with-virtualchroot --with-diraliases --with-peruserlimits --with-language=simplified-chinese --with-mysql=/usr/local/mysql --with-paranoidmsg --with-altlog --with-puredb

如果出现类似configure: error: Your MySQL client libraries aren't properly installed 的错误,mysql目录下的 include/mysql下的mysql.h文件以及lib/mysql下的全部文件,连接(直接复制过去或许也可) /usr/lib 目录下.

如果编译安装pure-ftpd出现configure: error: Your MySQL client libraries aren't properly installed错误,解决办法:
[root@jowei pure-ftpd-1.0.22]#vi /etc/profile
在最后添加
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib/mysql

如果出现你安装的Mysqlrpm包形式的,则直接用 --with-mysql 将其路径删除即可。

[root@jowei pure-ftpd-1.0.22]# ./etc/profile
然后再进行./configure ......

 

出现下面这个表示配置成功

configure: WARNING: unrecognized options: --with-largefile, --with-upload_script_, --with-virtualroot

configure: +--------------------------------------------------------+

configure: | You can subscribe to the Pure-FTPd users mailing-list  |

configure: | to ask for help and to stay informed of new releases.  |

configure: | Go to http://www.pureftpd.org/ml/ now!                 |

configure: +--------------------------------------------------------+

 

[root@localhost pure-ftpd-1.0.22]# make;make install

 

2、建立配置文件

[root@localhost pure-ftpd-1.0.22]# mkdir -m 755 /usr/local/pureftpd/etc

[root@localhost pure-ftpd-1.0.22]#

cp pureftpd-mysql.conf /usr/local/pureftpd/etc/
[root@localhost pure-ftpd-1.0.22]#

cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/etc/
[root@localhost pure-ftpd-1.0.22]# cp configuration-file/pure-config.pl /usr/local/pureftpd/bin/
[root@localhost pure-ftpd-1.0.22]#

chmod 755 /usr/local/pureftpd/bin/pure-config.pl

[root@localhost pure-ftpd-1.0.22]#

cp contrib/redhat.init /etc/init.d/pureftpd

[root@localhost pure-ftpd-1.0.22]# chmod 755 /etc/init.d/pureftpd

[root@localhost pure-ftpd-1.0.22]# chown root:root /etc/init.d/pureftpd //设置root权限

[root@localhost pure-ftpd-1.0.22]# chkconfig --add pureftpd

//加入系统启动

[root@localhost pure-ftpd-1.0.22]# chkconfig pureftpd on //开机启动

[root@localhost pure-ftpd-1.0.22]# vi /etc/init.d/pureftpd  //修改pureftpd一下几项

# Path to the pure-ftp binaries.

prog=pure-config.pl
fullpath=/usr/local/pureftpd/sbin/$prog                  //
修改此处
pureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho          //
修改pure-ftpwho路径

start() {
echo -n $"Starting $prog: "
$fullpath /usr/local/pureftpd/etc/pure-ftpd.conf --daemonize      //
修改pure-ftpd.conf路径

RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
echo
}


五、建立mysql认证数据库表

[root@jowei pureftpd]# mysql -u root -p
Enter password:         ----
输入mysql  root用户密码进入

mysql> create database pureftpd;
mysql> grant all on pureftpd.* to pureftpd@localhost identified by 'pureftpd';
mysql> use pureftpd

mysql> CREATE TABLE users (
id int(32) unsigned NOT NULL auto_increment,
User varchar(16) NOT NULL default '*',
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 '-1',
QuotaSize smallint(5) NOT NULL default 0,
QuotaFiles int(11) NOT NULL default 0,
ULBandwidth smallint(5) NOT NULL default 0,
DLBandwidth smallint(5) NOT NULL default 0,
ULRatio smallint(6) NOT NULL default 0,
DLRatio smallint(6) NOT NULL default 0,
comment tinytext NOT NULL,
ipaccess varchar(15) NOT NULL default '*',
status enum('0','1') NOT NULL default '0',
create_date datetime NOT NULL default '0000-00-00 00:00:00',
modify_date datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id,User),
UNIQUE KEY User (User)
) TYPE=MyISAM AUTO_INCREMENT=5;

 

建立用户

你可以用下面建立的test用户登录到/var/pureftp
INSERT INTO users VALUES (1,'test1', '123456', '2000', '2000', '/var/pureftp', 0, 0, 0, 0, 0, 0, '*', '*', '1', '2009-7-11 09:20:33', '2009-7-11 09:20:33');

INSERT INTO users VALUES (1,'test2', '123456', '2000', '2000', '/var/pureftp', 0, 0, 0, 0, 0, 0, '*', '*', '1', '2009-7-11 09:20:33', '2009-7-11 09:20:33');

 /var/pureftp   ftp登陆的文件目录

六、建立用于pureftpd认证用户的系统信息

 你可以自己向下面这样建立一个用户做pureftpd验证但是我下面直接用的是root

[root@localhost /]# groupadd -g 2000 pureftp
[root@localhost /]# useradd -u 2000 -g pureftp -d /var/pureftp -s /sbin/nologin pureftp

 

五、修改pureftpd的配置文件

[root@localhost var]# vi /usr/local/pureftpd/etc/pure-ftpd.conf

############################################################
#                                                                                       #
#          Configuration file for pure-ftpd wrappers                     #
#                                                                                       #
############################################################

#
如果你想要使用配置文件代替命令行选项来运行 Pure-FTPd ,请运行下面的命令:

#
# /usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
#
# RPM
缺省使用另外一个配置文件:

# /etc/sysconfig/pure-ftpd
#
#
请不要忘了浏览一下 http://www.pureftpd.org/documentation.html

#
文档,查看全部的选项列表。


#
限制所有用户在其主目录中


   ChrootEveryone               yes


#
如果前一个指令被设置为了 "no",下面组的成员(GID)就不受主目录的限制了。而其他的用户还是

#
会被限制在自己的主目录里。如果你不想把任何用户限制在自己的主目录里,只要注释掉
ChrootEveryone
#
TrustedGID 就可以了。


# TrustedGID                     100

#
兼容ie等比较非正规化的ftp客户端


   BrokenClientsCompatibility   no

#
服务器总共允许同时连接的最大用户数


   MaxClientsNumber             50

#
做为守护(doemon)进程运行
(Fork in background)

   Daemonize                    yes

#
同一IP允许同时连接的用户数(Maximum number of sim clients with the same IP address


   MaxClientsPerIP              8

#
如果你要记录所有的客户命令,设置这个指令为 "yes"

# This directive can be duplicated to also log server responses.

   VerboseLog                   no

#
即使客户端没有发送 '-a' 选项也列出隐藏文件( dot-files )


   DisplayDotFiles              yes

#
不允许认证用户 - 仅作为一个公共的匿名FTP


   AnonymousOnly                no

#
不允许匿名连接,仅允许认证用户使用。


   NoAnonymous                  no

# Syslog facility (auth, authpriv, daemon, ftp, security, user, local*)
#
缺省的功能( facility ) "ftp" "none" 将禁止日志。


   SyslogFacility               ftp

#
定制用户登陆后的显示信息(Display fortune cookies


# FortunesFile               /usr/share/fortune/zippy

#
在日志文件中不解析主机名。日志没那么详细的话,就使用更少的带宽。在一个访问量很大

#
的站点中,设置这个指令为 "yes" ,如果你没有一个能工作的DNS的话。


   DontResolve                  yes

#
客户端允许的最大的空闲时间(分钟,缺省15分钟)


   MaxIdleTime                  15

# LDAP
配置文件 (参考
README.LDAP)

# LDAPConfigFile                 /etc/pureftpd-ldap.conf

# MySQL
配置文件 (参考
README.MySQL)

MySQLConfigFile               
/usr/local/pureftpd/etc/pureftpd-mysql.conf #关键部分,你整合mysql就靠它了

# Postgres
配置文件 (参考 README.PGSQL)

# PGSQLConfigFile                /etc/pureftpd-pgsql.conf

# PureDB
用户数据库 (参考
README.Virtual-Users)

# PureDB                         /etc/pureftpd.pdb

# pure-authd
socket 路径(参考
README.Authentication-Modules)

# ExtAuth                        /var/run/ftpd.sock

#
如果你要启用 PAM 认证方式, 去掉下面行的注释。


# PAMAuthentication              yes

#
如果你要启用 简单的 Unix系统 认证方式(/etc/passwd), 去掉下面行的注释。


# UnixAuthentication             yes

#
请注意,LDAPConfigFile, MySQLConfigFile, PAMAuthentication

# UnixAuthentication
这些指令只能被使用一次,不过,他们能被混合在一起用。例如:如果你使用了

# MySQLConfigFile
UnixAuthentication,那么 SQL 服务器将被访问。如果因为用户名未找

#
到而使 SQL 认证失败的话,就会在/etc/passwd /etc/shadow 中尝试另外一种认证,如果因

#
为密码错误而使 SQL 认证失败的话,认证就会在此结束了。认证方式由它们被给出来的顺序而被链

#
接了起来。


# 'ls'
命令的递归限制。第一个参数给出文件显示的最大数目。第二个参数给出最大的子目录深度。


   LimitRecursion               2000 8

#
允许匿名用户创建时间:2009-11-11 15:38:00新目录?


   AnonymousCanCreateDirs       no

#
如果系统被 loaded 超过下面的值,匿名用户会被禁止下载。


   MaxLoad                      4

#
被动连接响应的端口范围。
- for firewalling.

# PassivePortRange           30000 50000

#
强制一个IP地址使用被动响应( PASV/EPSV/SPSV replies)。
- for NAT.
# Symbolic host names are also accepted for gateways with dynamic IP
# addresses.

# ForcePassiveIP                 192.168.0.1

#
匿名用户的上传/下载的比率。


# AnonymousRatio                 1 10

#
所有用户的上传/下载的比率。

# This directive superscedes the previous one.

# UserRatio                  1 10

#
不接受所有者为 "ftp" 的文件的下载。例如:那些匿名用户上传后未被本地管理员验证的文件。


   AntiWarez                    yes

#
服务监听的IP 地址和端口。(缺省是所有IP地址和21端口
)

# Bind                       127.0.0.1,21

#
匿名用户的最大带宽(KB/s)。


# AnonymousBandwidth             8

#
所有用户的最大带宽(KB/s),包括匿名用户。

# Use AnonymousBandwidth *or* UserBandwidth, both makes no sense.

# UserBandwidth              8

#
新建目录及文件的属性掩码值。<文件掩码>;:<目录掩码
>; .
# 177:077 if you feel paranoid.

   Umask                        133:022

#
认证用户允许登陆的最小组IDUID


   MinUID                       100

#
仅允许认证用户进行 FXP 传输。


   AllowUserFXP                 yes

#
对匿名用户和非匿名用户允许进行匿名 FXP 传输。


   AllowAnonymousFXP            no

#
用户不能删除和写点文件(文件名以 '.' 开头的文件),即使用户是文件的所有者也不行。

#
如果 TrustedGID 指令是 enabled ,文件所属组用户能够访问点文件(dot-files)


   ProhibitDotFilesWrite        no

#
禁止读点文件(文件名以 '.' 开头的文件)
(.history, .ssh...)

   ProhibitDotFilesRead         no

#
永不覆盖文件。当上传的文件,其文件名已经存在时,自动重命名,如:
file.1, file.2, file.3, ...

   AutoRename                   no

#
不接受匿名用户上传新文件( no = 允许上传
)

   AnonymousCantUpload          no

#
仅允许来自以下IP地址的非匿名用户连接。你可以使用这个指令来打开几个公网IP来提供匿名FTP

#
而保留一个私有的防火墙保护的IP来进行远程管理。你还可以只允许一内网地址进行认证,而在另外

#
一个IP上提供纯匿名的FTP服务。


#TrustedIP                   10.1.1.1


#
如果你要为日志每一行添加 PID   去掉下面行的注释。


# LogPID                      yes

#
使用类似于Apache的格式创建一个额外的日志文件,如:

# fw.c9x.org - jedi [13/Dec/1975] "GET /ftp/linux.tar.bz2" 200 21809338
#
这个日志文件能被 www 流量分析器处理。


# AltLog                      clf:/var/log/pureftpd.log


#
使用优化过的格式为统计报告创建一个额外的日志文件。


# AltLog                      stats:/var/log/pureftpd.log


#
使用标准的W3C格式创建一个额外的日志文件。(与大部分的商业日志分析器兼容)


# AltLog                      w3c:/var/log/pureftpd.log

#
不接受 CHMOD 命令。用户不能更改他们文件的属性。


# NoChmod                      yes


#
允许用户恢复和上传文件,却不允许删除他们。


# KeepAllFiles                 yes


#
用户主目录不存在的话,自动创建。


# CreateHomeDir                yes

#
启用虚拟的磁盘限额。第一个数字是最大的文件数。

#
第二个数字是最大的总的文件大小(单位:Mb)

#
所以,1000:10 就限制每一个用户只能使用 1000 个文件,共10Mb


# Quota                        1000:10

#
如果你的 pure-ftpd 编译时加入了独立服务器( standalone )支持,你能够改变 pid 文件

#
的位置。缺省位置是 /var/run/pure-ftpd.pid


# PIDFile                      /var/run/pure-ftpd.pid

#
如果你的 pure-ftpd 编译时加入了 pure-uploadscript 支持,这个指令将会使
pure-ftpd
#
发送关于新上传的情况信息到 /var/run/pure-ftpd.upload.pipe,这样
pure-uploadscript
#
就能读然后调用一个脚本去处理新的上传。


# CallUploadScript yes

#
这个选项对允许匿名上传的服务器是有用的。当 /var/ftp /var 里时,需要保留一定磁盘空间

#
来保护日志文件。当所在磁盘分区使用超过百分之 X 时,将不在接受新的上传。


   MaxDiskUsage                99

#
如果你不想要你的用户重命名文件的话,就设置为 'yes'


# NoRename yes

#
'customer proof' : 工作区(workaround)反对普通的客户错误,类似于:'chmod 0 public_html' 的错误。

#
那是一个有效的命令,不过,将导致无知的客户所定他们自己的文件,将使你的技术支持忙于愚蠢的的问题中。

#
如果你确信你所有的用户都有基本的Unix知识的话,这个特性将没什么用了。不过,如果你是一个主机提供商

#
的话,启用它。


CustomerProof yes

#
每一个用户的并发限制。只有在添加了 --with-peruserlimits 编译选项进行编译后,这个指令才起

#
作用。(大部分的二进制的发布版本就是例子
)
#
格式是 : <每一个用户最大允许的进程>;:<最大的匿名用户进程
>;
#
例如: 3:20 意思是同一个认证用户最大可以有3个同时活动的进程。而且同时最多只能有20个匿名用户进程。


# PerUserLimits 3:20

 

 六、修改pureftpd-mysql.conf的配置文件

[root@localhost var]# vi /usr/local/pureftpd/etc/pureftpd-mysql.conf

 

##############################################

#                                            #

# Sample Pure-FTPd Mysql configuration file. #

# See README.MySQL for explanations.         #

#                                            #

##############################################

 

 

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

 

MYSQLServer     localhost

#服务器地址

 

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

 

MYSQLPort       3306

 

#服务器端口

# Optional : define the location of mysql.sock if the server runs on this host.

 

MYSQLSocket     /tmp/mysql.sock

#这里换成你的真实地址

 

# Mandatory : user to bind the server as.

 

MYSQLUser       root

#登录服务器用户名

 

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

 

MYSQLPassword   123456

#登录服务器密码

 

# Mandatory : database to open.

MYSQLDatabase   pureftpd

#配置文件所在的数据库

 

# Mandatory : how passwords are stored

# Valid values are : "cleartext", "crypt", "md5" and "password"

# ("password" = MySQL password() function)

# You can also use "any" to try "crypt", "md5" *and* "password"

 

MYSQLCrypt      cleartext

#验证方式

 

# In the following directives, parts of the strings are replaced at

# run-time before performing queries :

#

# /L is replaced by the login of the user trying to authenticate.

# /I is replaced by the IP address the user connected to.

# /P is replaced by the port number the user connected to.

# /R is replaced by the IP address the user connected from.

# /D is replaced by the remote IP address, as a long decimal number.

#

# Very complex queries can be performed using these substitution strings,

# especially for virtual hosting.

 

 

# Query to execute in order to fetch the password

 

MYSQLGetPW      SELECT Password FROM users WHERE User="/L" AND  status="1"

#登录服务器的用户密码验证字段,status="1"为此用户必需为激活模式.

 

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

 

MYSQLGetUID     SELECT Uid FROM users WHERE User="/L"

#用户的UID

 

# Optional : default UID - if set this overrides MYSQLGetUID

 

#MYSQLDefaultUID 1000

 

 

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

 

MYSQLGetGID     SELECT Gid FROM users WHERE User="/L"

 

#用户的Gid

# Optional : default GID - if set this overrides MYSQLGetGID

 

#MYSQLDefaultGID 1000

 

 

# Query to execute in order to fetch the home directory

 

MYSQLGetDir     SELECT Dir FROM users WHERE User="/L"

#用户的主目录

 

# Optional : query to get the maximal number of files

# Pure-FTPd must have been compiled with virtual quotas support.

 

MySQLGetQTAFS  SELECT QuotaFiles FROM users WHERE User="/L"

 

#用户的最大文件数量

# Optional : query to get the maximal disk usage (virtual quotas)

# The number should be in Megabytes.

# Pure-FTPd must have been compiled with virtual quotas support.

 

MySQLGetQTASZ  SELECT QuotaSize FROM users WHERE User="/L"

#用户的最大磁盘空间

 

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

 

MySQLGetRatioUL SELECT  ULBandwidth FROM users WHERE User="/L"

MySQLGetRatioDL SELECT  DLBandwidth FROM users WHERE User="/L"

#上边两项为,用户上传与下载的速度,单位 Kb/s

 

# Optional : bandwidth throttling.

# The server has to be compiled with throttling support.

# Values are in KB/s .

 

# MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User="/L"

# MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User="/L"

 

# Enable ~ expansion. NEVER ENABLE THIS BLINDLY UNLESS :

# 1) You know what you are doing.

# 2) Real and virtual users match.

 

# MySQLForceTildeExpansion 1

 

 

# If you upgraded your tables to transactionnal tables (Gemini,

# BerkeleyDB, Innobase...), you can enable SQL transactions to

# avoid races. Leave this commented if you are using the

# traditionnal MyIsam databases or old (< 3.23.x) MySQL versions.

 

# MySQLTransactions On



六、运行pureftpd

 

启动pureftpd

[root@localhost ~]# /etc/init.d/pureftpd start 或者下面也可以
[root@localhost ~]#/usr/local/pureftpd/bin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf

 

原创粉丝点击