首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>服务器类>FTP服务器>资讯:CentOS5环境下安装PureFTPd

CentOS5环境下安装PureFTPd

www.jz123.cn  2008-08-19   来源:   中国建站    袁袁整理    我要投递新闻

前几天为了让公司内的FTP,决定在centos5下装支持虚拟用户带磁盘限额的FTP软件。在安装PureFTPd以前,要做好以下准备工作:

 安装PureFTPd
1.下面我们开始安装PureFTPd,同样以FreeBSD的Ports方式安装。

以下为引用的内容:
#tar zxfv pure-ftpd-1.0.21.tar.gz -C /usr/local/
#cd /usr/local/pure-ftpd-1.0.21/
#./configure \
--prefix=/usr/local/pureftpd \
--with-mysql \
--with-puredb \
--with-paranoidmsg \
--with-peruserlimits \
--with-shadow \
--with-welcomemsg \
--with-uploadscript \
--with-quotas \
--with-cookie \
--with-pam \
--with-virtualhosts \
--with-virtualroot \
--with-virtualchroot \
--with-diraliases \
--with-sysquotas \
--with-ratios \
--with-ftpwho \
--with-throttling \
--with-largefile \
--with-language=simplified-chinese \
--with-altlog \
--with-iplogging \
--without-usernames
#make
# make check
# make install

下面配置pureftpd:
# mkdir –pv /usr/local/pureftpd/etc
#cp pureftpd-mysql.conf /usr/local/pureftpd/etc
# cp configuration-file/pure-config.pl /usr/local/pureftpd/sbin/ (生成配置文件)
# cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/etc/
# chmod 755 /usr/local/pureftpd/sbin/pure-config.pl

# cd contrib
编辑 redhat.init 文件。找到语句
找到语句: "pureftpwho=/usr/local/sbin/pure-ftpwho",
将其改为: "pureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho"
找到语句: ”$fullpath /usr/local/etc/pure-ftpd.conf –daemonize”
将其改为: ”$fullpath /usr/local/pureftpd/etc/pure-ftpd.conf –daemonize”
执行以下命令将文件 redhat.init 复制到 /etc 目录中重命名为 pure-ftpd,并将其设置为可执行。
# cp redhat.init /etc/rc.d/init.d/pureftpd
# chmod u+x /etc/rc.d/init.d/pureftpd

# /sbin/chkconfig --add pureftpd ( 将 pure-ftpd 服务添加到系统中 )
# /sbin/chkconfig –level 2345 pureftpd on
#serv        ice pureftpd start
解释:
注明:)
在README中[ADVANCED COMPILATION]的段落中,有对上面的使用的
      详细说明.在这里对常用的做简略的解释.
      --without-standalone 不能以standalone的方式执行ftpd.
      --without-inetd           不能以inetd的方式执行ftpd.
      --without-iplogging           做log?不将IP 地址给log下?.
      --without-shadow           不做shadow.除非是用PAM, LDAP or SQL.不然极不建议拿掉.
      --without-usernames           文件列表只会列出UID & GID,不列出实际user or group name.
      --without-humor           嘿嘿嘿....
      --without-ascii           不支持7-bits transfers(ASCII).
      --with-paranoidmsg           唔....不知该怎么说.算是可以给特定人的信息吧.
      --with-sysquotas           吃系统的quota设定.
      --with-minimal           最小化安砚.
      --with-pam
      --with-puredb
      --with-ldap
      --with-mysql
      --with-pgsql           以上五种都是存储资料的格式?.看你比较习惯什么.
      --with-altlog           留log了....
      --with-cookie           使用者进站看到的东东.类似进站画面.
      --with-ratios           上下传比.
      --with-throttling           频宽可设限.
      --with-ftpwho           可用pure-ftpwho?看线上使用者.像是Serv-u的线上状态.
      --with-uploadscript   当一个文件被完整上传完后自动呼叫某一script去对这个文件处理.当然.这个script得你自己写.
      --with-largefile           支持下载超过2G的文件.
      --with-virtualhosts           跟http的virtualhost有异曲同工之妙.
      --with-virtualchroot           配合上面的chroot.
      --with-diraliases           跟Serv-U上面的link功能一样.
      --with-nonroot           不需root权限.一般user即可启动ftpd.
      --with-quotas           使用quota.(非系统下的quota)
      --with-peruserlimits         每个账号最多可登入几次:Anonymous最多可同?登入几次
      --with-everything          所有功能全上.
      --with-language=simplified-chinese           显示出来的信息的语言.缺省为英语.


安装完后,就会在/usr/local目录下生成一个pureftpd目录,我们要使用的文件都在这个目录中。

2.下面我们开始配置pure-ftpd.conf文件

在这里我全使用默认值,修改下面内容以支持MYSQL。(注:Pureftpd可以同时支持ldap,mysql,pgsql,puredb认证)

以下为引用的内容:
# MySQL configuration file (see README.MySQL)
MySQLConfigFile /usr/local/pureftpd/etc/pureftpd-mysql.conf

修改不然无法执行 #service pureftpd stop)
# If your pure-ftpd has been compiled with standalone support, you can change
# the location of the pid file. The default is /var/run/pure-ftpd.pid
#PIDFile                     /var/run/pure-ftpd.pid
#去掉上面的注释
PIDFile                     /var/run/pure-ftpd.pid
修改不允许名登陆
NoAnonymous                 yes
# Allow FXP transfers for authenticated users.
AllowUserFXP                yes
# Allow users to resume and upload files, but *NOT* to delete them.
KeepAllFiles                yes
# Automatically create home directories if they are missing
CreateHomeDir               yes


3.配置文件详解(摘自网上陈景峰所著《Pure-FTPd + LDAP + MySQL + PGSQL + Virtual-Users + Quota How To》)

ChrootEveryone yes

chroot每一个用户,等同于Proftpd 中的DefaultRoot~ , 可以限制用户在某个地方活动,增强服务器的安全性。使用过wu-ftpd的使用都应该知道cd /会发生什么!

以下为引用的内容:
TrustedGID 50
#以上两者要一起用
BrokenClientsCompatibility no
MaxClientsNumber 50
#最大链接数
Daemonize yes
#Fork in background 以守护进程方式在后台运行
MaxClientsPerIP 5
#每个ip最多链接数,最好设小点。
VerboseLog no
#是否要把所有client端的指令都log下来
DisplayDotFiles no
#显示开头的文件
AnonymousOnly no
#是否只让匿名登录
NoAnonymous no
#不开放匿名登入
SyslogFacility ftp
#应该是对日志做一下过滤 (auth, authpriv, daemon, ftp, security, user, local*)可以让日志只记录想要的信息
DontResolve yes
#不反向解释客户端的ip
MaxIdleTime 5
#最大闲置?殓
#LDAPConfigFile /usr/local/pureftpd/etc/pureftpd-ldap.conf
#使用LDAP认证,
MySQLConfigFile /usr/local/pureftpd/etc/pureftpd-mysql.conf
#使用MySQL认证
#PGSQLConfigFile /usr/local/pureftpd/etc/pureftpd-pgsql.conf
#使用PGSQL认证
#PureDB /ftp/etc/pureftpd.pdb
#使用者资料的DB存放地点 [由于我是用PureFTPD的?建DB.固有此选项]
#ExtAuth /var/run/ftpd.sock
#pure-authd socket 路径 (详细请看 README.Authentication-Modules)
#PAMAuthentication yes
#开启PAM认证
#UnixAuthentication yes
#如果你想要有简单的Unix(/etc/passwd)的认证的?
FortunesFile /usr/local/pureftpd/etc/.welcome
#显示的欢迎信息文件,你可以创建该文件,输入一些文字,然后你重启你的FTP服务,就会有意外的发现。
LimitRecursion 2000 8
#ls最多列出3000个文件.最深8层
AnonymousCanCreateDirs no
#匿名用户可以创建目录
MaxLoad 4
#当system load超过4?.使用者将不能再下载
PassivePortRange 30000 50000
#被动连接应答范围
ForcePassiveIP 192.168.0.1
#不会译:(
AnonymousRatio 1 10
#Anonymous连接上传/下载比率
UserRatio 1 10
#用户上传/下载比率(注:如果使用ldap,mysql,pgsql,pam不要启用该功能,否则你在ldap等中设置的Ratio无校)
AntiWarez no
#上传的文件不能被下载(owner is ftp).等到local admin确认
Bind 127.0.0.1,8021
#要绑定和ip/port,在你的系统中有两个FTP Server这样你其中一个FTP就要使用其它端口。
#格式-> 127.0.0.1,21 如果只写port表All ip,port
AnonymousBandwidth 8
#Anonymous 带宽,单位KB/s
UserBandwidth 8
#用户带宽,单位KB/s
Umask 133:022
#上传文件的Umask.(<umask for files>:<umask for dirs> )
MinUID 1000
# UID至少多少才能登录
AllowUserFXP yes
#支不支持FXP
AllowAnonymousFXP no
#Anonymous支不支持FXP
ProhibitDotFilesWrite no
ProhibitDotFilesRead no
#(”.”)开头的文件能不能被读/写,UNIX Like下以点开头的文件是隐藏文件ls –a才能列出
#Pureftpd Quota模式下做产生” .ftpquota”文件。
AutoRename no
#上传文件若有相同文件名自动改名(file.1,file.2...)
AnonymousCantUpload no
#匿名用户上传文件
#TrustedIP 10.1.1.1
#锁IP.
LogPID
#Log文件添加PID
AltLog stats:/ftp/etc/log/pureftpd.log
#log存放地点,注日志有几种常用的格式
#clf 类似apache格式,stats UNIX log格式,w3c 标准W3C格式,可能是HTML格式
NoChmod yes
#不给Chmod指令的权限
KeepAllFiles no
#使用者可续传.但不可?除文件
CreateHomeDir yes
#如果user的home不存在自动建立(我把这个设为YES)
Quota 1000:10
#Quota <文件数>:<容量Megabytes >,FTP限制10M空间,可以上传1000个文件(注:如果使用ldap,mysql,pgsql,pam不要启用该功能,否则你在ldap等中设置的Quota无校)
PIDFile /ftp/etc/log/pure-ftpd.pid
#记录pure-ftpd的PID文件
CallUploadScript yes    
#呼叫UploadScript
MaxDiskUsage 99
#当硬盘使用率到多少?将停止上传
NoRename yes
#用户不能重命名文件名
CustomerProof yes
PerUserLimits 3:20
#<每个账号最多可登入几次:Anonymous最多可同?登入几次>

4. 创建Mysql数据库中的FTP虚拟用户管理数据库ftpusers将以下内容存为script.mysql文件

以下为引用的内容:
INSERT INTO mysql.user (Host, User, Password, Select_priv, Insert_priv, Update
_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Proces
s_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv) VALUES
('127.0.0.1','ftp',PASSWORD('123456'),'Y','Y','Y','Y','N','N','N','N','N','N
','N','N','N','N');

FLUSH PRIVILEGES;

CREATE DATABASE ftpusers;

USE ftpusers;

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

INSERT INTO admin VALUES ('Administrator',MD5('123456'));

CREATE TABLE users (
User char(16) NOT NULL default '',
Password char(32) binary NOT NULL default '',
Uid int(11) NOT NULL default '2000',
Gid int(11) NOT NULL default '2000',
Dir char(12 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',
status enum('0','1') NOT NULL default '1',
ipaccess varchar(15) NOT NULL default '*',
comment tinytext NOT NULL,
PRIMARY KEY (User),
UNIQUE KEY User (User)
) TYPE=MyISAM;

INSERT INTO `users` VALUES ('kevin',MD5('123456'),1001,2000,'/home/kevin',500,30,
80,5);
 


先在Mysql数据库建立一个对数据库有操作权限的用户ftp,密码为123456。
再创建新数据库ftpusers,并新建两个表admin和users,往admin表中加入管理用户帐号,往users表中加入新的FTP用户kevin,密码为123456。

然后我们运行以下命令来生成数据库ftpusers。

# mysql -u root -ppassword < script.mysql
注意,-p是输入密码,它和后面你输入的password中没有空格。

5.修改/usr/local/pureftpd/etc/pureftpd-mysql.conf配置文件,内容如下所示:

以下为引用的内容:
MYSQLServer localhost
#MYSQL服务器的IP
MYSQLPort 3306
#MYSQL 端口号
MYSQLSocket /var/lib/mysql/mysql.sock
#使用UNIX.sock本地连接
注:MYSQLServer 与 MYSQLSocket 选择一种即可

MYSQLUser ftp
#MYSQLUser 数据用户名
MYSQLPassword 123456
#MYSQL数据库用户的密码
MYSQLDatabase ftpusers
#FTP数据数据库
MYSQLCrypt md5
#密码加密方式"cleartext", "crypt", "md5" and "password"
# cleartext 明文,crypt,md5,password是Backend password(‘your-passwd’)函数(MYSQL数据库所使用的password()函数)
MYSQLGetPW SELECT Password FROM users WHERE User="\L"
# 密码字段,我使用users表中的Password做为密码字段
MYSQLGetUID SELECT Uid FROM users WHERE User="\L"
#UID用户ID字段
MYSQLDefaultUID 1000
#默认的UID (注:如何开启该选项,MYSQLGetUID将失去作用)
MYSQLGetGID SELECT Gid FROM users WHERE User="\L"
#GID组ID字段
MYSQLDefaultGID 1000
#默认的GID (注:如何开启该选项,MYSQLGetGID将失去作用)
MYSQLGetDir SELECT Dir FROM users WHERE User="\L"
#FTP用户目录如/home/web/www-9812-net
MySQLGetQTAFS SELECT QuotaFiles FROM users WHERE User="\L"
#磁盘限额,文件数限制。如1000,允许用户上传1千个文件
MySQLGetQTASZ SELECT QuotaSize FROM users WHERE User="\L"
#磁盘限额,FTP用户空间限制(单位为M),如:100M
MySQLGetRatioUL SELECT ULRatio FROM users WHERE User="\L"
MySQLGetRatioDL SELECT DLRatio FROM users WHERE User="\L"
#上传/下载比率。MySQLGetRatioUL为上传比,MySQLGetRatioDL下载比。如:1:5
MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User="\L"
MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User="\L"
#下传/下载带宽(单位KB/s)。MySQLGetBandwidthUL上传带宽,MySQLGetBandwidthDL下载带宽。如上传500KB/s,下载50KB/s
MySQLForceTildeExpansion 1
MySQLTransactions On
#不会翻译
 


修改好该配置文件后,我们继续。

6.运行PureFTPd

======== 配置匿名用户登录环境 ============

由于 pure-ftpd 将 FTP 匿名用户(anonymous)映射到名为 ftp 的系统帐户,因此 ftp 系统帐户主目录就是 FTP 匿名用户的主目录。
如果需要 FTP 服务器允许匿名登录系统,就需要建立一个名为 ftp 的系统帐户,而且该帐户的主目录需要存在,否则使用匿名用户登录时会出现登录失败并提示“ No control connection for command:No such file or diretory”的错误。

默认 pure-ftpd 安装的时候已经建立了 ftp 帐户,但该帐户默认的主目录 /var/ftp 不存在,所以还要使用命令为其建立目录,同时使得 ftp 系统帐户对主目录有写入权限。

以下为引用的内容:
#groupadd -g 1000 ftp
#ueradd -g ftp -u 1000 -s /sbin/nologin –d /var/ftp -M ftp
# mkdir /var/ftp
# chown ftp:ftp /var/ftp
操作完后我们就添加一个ftp帐号属于ftp组,用户id和组id都是1000

启动PureFTPd
# service pureftpd start
测试FTP是否正常了。
# ftp 你的IP
Connected to 127.0.0.1.
220---------- 欢迎来到 Pure-FTPd ----------
220-您是第1个使用者,最多可达50个连接
220-现在是本地时间 09:02。服务器端口: 21。
220 在15分钟内没有活动,您将被断线。
Name (127.0.0.1:kevin):kevin
Password:
230-使用者kevin 有以下组的权限: ftp
230-这个服务器支持FXP传输
230-OK. 目前限制的目录是 /
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>


恭喜你,你的FTP服务已经正常工作了。


上一篇:用端口碰撞技术实现服务器远程管理 下一篇:菜鸟也能搭建FTP服务器

评论总数:0 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图