[转载]Proftpd+mod_quotatab+mysql的安装笔记
文章作者:ghost关于mysql,如果你没有装,同样参见xxbin的笔记
在 [url]http://www.proftpd.org/[/url] 下载相关软件,使用太老的版本可能有安全问题,参见官方网站。有一个mod_mysql是不能用的,太老了,有很严重的安全问题,偶没有找到更新,所以用一个更优秀的模块mod_quotatab,在官方网站上有文档,介绍了它的特性,大概是支持基于文件和数据库的quota。这里采用mysql作为后台数据库。用户名和密码也保存在数据库中,避免为每一个用户建一个系统帐户,也提高了安全性,降低了管理的难度。文件为:
proftpd-1.2.9rc2p.tar.bz2
proftpd-mod-quotatab-1.2.11.tar.gz
tar xjvf proftpd-1.2.9rc2p.tar.bz2
tar xzvf proftpd-mod-quotatab-1.2.11.tar.gz
把模块中所有文件拷贝到proftpd的安装目录的modules目录下
cp mod_quotatab/* proftpd-1.2.9rc2/modules/
在configure之前,改动一个文件
vi proftpd-1.2.9rc2/contirb/mod_sql_mysql.c
找到 #include <mysql.h>
将其改为实际的路径,比如
#include </usr/lib/mysql/mysql.h>
存盘退出。
然后是编译:
cd proftpd-1.2.9rc2
./configure --with-modules=mod_tls:mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql --with-includes=/usr/local/ssl/include:/usr/include/mysql --with-libraries=/usr/local/ssl/lib:/usr/lib/mysql --enable-tunable-buffer-size --enable-sendfile
make
make install
安装就算完成了,主要是配置和测试,proftpd的配置文件为/usr/local/etc/proftpd.conf,下面的是偶的配置文件,仅供参考,一些注释是偶写的,偶英文不是太好,如果有错误不要笑:),各个选项都还算简单,看看就知道了, 修改之前,记得先备份。
[code]# This is a basic ProFTPD configuration file (rename it to
# 'proftpd.conf' for actual use. It establishes a single server
# and a single anonymous login. It assumes that you have a user/group
# "nobody" and "ftp" for normal operation and anon.
ServerName "FTP server of [email]ghost@netbuddy.org[/email]"
ServerType standalone
DefaultServer on
# Port 21 is the standard FTP port.
Port 21
# Umask 022 is a good standard umask to prevent new dirs and files
# from being group and world writable.
Umask 022
# To prevent DoS attacks, set the maximum number of child processes
# to 30. If you need to allow more than 30 concurrent connections
# at once, simply increase this value. Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd).
MaxInstances 50
# Set the user and group under which the server will run.
User nobody
Group nobody
# To cause every FTP user to be "jailed" (chrooted) into their home
# directory, uncomment this line.
#DefaultRoot ~
# Normally, we want files to be overwriteable.
<Directory />
AllowOverwrite on
</Directory>
# Display the welcome message
DisplayLogin welcome.msg
# A basic anonymous configuration, no upload directories. If you do not
# want anonymous users, simply delete this entire <Anonymous> section.
# 这段标记是匿名访问的配置,偶把它注释掉了,也就是不允许匿名访问,如果
# 你打算允许匿名访问,把前面的#去掉就好了
#<Anonymous ~ftp>
# User ftp
# Group ftp
# We want clients to be able to login with "anonymous" as well as "ftp"
# UserAlias anonymous ftp
# Limit the maximum number of anonymous logins
# MaxClients 10
# We want 'welcome.msg' displayed at login, and '.message' displayed
# in each newly chdired directory.
# DisplayLogin welcome.msg
# DisplayFirstChdir .message
# Limit WRITE everywhere in the anonymous chroot
# <Limit WRITE>
# DenyAll
# </Limit>
#</Anonymous>
# Do not display version infomation when user login
ServerIdent off
MaxLoginAttempts 3
TimeoutLogin 120
TimeoutIdle 600
TimeoutNoTransfer 900
TimeoutStalled 3600
# Connection number per host
MaxClientsPerHost 10
AllowStoreRestart on
UseReverseDNS off
RequireValidShell off
# Lock the user in own directory
DefaultRoot ~
# Datebase connect infomation
# ftp is database name, the ftp_user is user name ftp_password is password
# of the database
# 这里的ftp@localhost表明是本机上的mysql中的ftp数据库。ftp_user, ftp_password是
# 数据库的用户名和密码,你根据自己的设置改一下
SQLConnectInfo ftp@localhost ftp_user ftp_password
# The type of database authenticate
SQLAuthTypes Backend Plaintext
# The infomation of database tables
#
SQLUserInfo FTPUSERS userid passwd uid gid homedir shell
SQLGroupInfo FTPGRPS groupname gid members
# Databse authenticate
SQLAuthenticate users groups usersetfast groupsetfast
# If home directory is not exist, system will create one with user's home infomation
SQLHomedirOnDemand on
# Use disk quota
QuotaDirectoryTally on
# Disk quota unit "b" | "Kb" | "Mb" | "Gb"
QuotaDisplayUnits "Kb"
QuotaEngine on
# Disk quota log
QuotaLog "var/log"
# Display quota infomation, when login ftp account, use command
# "quote site QUOTA" to display the current user's disk quota
QuotaShowQuotas on
# SQL
SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail, bytes_xfer_avail,files_in_avail, files_out_avail, files_xfer_avail FROM quotalimits WHERE name = '%{0}' AND quota_type = '%{1}'"
SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_in_used, files_out_used, files_xfer_used FROM quotatallies WHERE name = '%{0}' AND quota_type = '%{1}'"
SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + %{0}, bytes_out_used = bytes_out_used + %{1}, bytes_xfer_used = bytes_xfer_used + %{2}, files_in_used = files_in_used + %{3}, files_out_used = files_out_used + %{4}, files_xfer_used = files_xfer_used + %{5} WHERE name = '%{6}' AND quota_type = '%{7}'" quotatallies
SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" quotatallies
QuotaLimitTable sql:/get-quota-limit
QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally[/code]
proftpd的启动脚本,保存为 /etc/rc.d/init.d/proftpd
[code]#!/bin/sh
# chkconfig: 345 85 15
# description: proftpd is a ftp daemon
# ProFTPD files
FTPD_BIN=/usr/local/sbin/proftpd
FTPD_CONF=/usr/local/etc/proftpd.conf
PIDFILE=/usr/local/var/proftpd/proftpd.pid
# If PIDFILE exists, does it point to a proftpd process?
if [ -f $PIDFILE ]; then
pid=`cat $PIDFILE`
fi
if [ ! -x $FTPD_BIN ]; then
echo "$0: $FTPD_BIN: cannot execute"
exit 1
fi
case $1 in
start)
if [ -n "$pid" ]; then
echo "$0: proftpd [PID $pid] already running"
exit
fi
if [ -r $FTPD_CONF ]; then
echo "Starting proftpd..."
$FTPD_BIN -c $FTPD_CONF
else
echo "$0: cannot start proftpd -- $FTPD_CONF missing"
fi
;;
stop)
if [ -n "$pid" ]; then
echo "Stopping proftpd..."
kill -TERM $pid
else
echo "$0: proftpd not running"
exit 1
fi
;;
restart)
if [ -n "$pid" ]; then
echo "Rehashing proftpd configuration"
kill -HUP $pid
else
echo "$0: proftpd not running"
exit 1
fi
;;
*)
echo "usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0[/code]
记得要
chmod +x proftpd
现在可以使用/etc/rc.d/init.d/proftpd stop/start/restart的方式来启动和停止服务了。
用chkconfig --add proftpd添加为自启动,开机时就会自动运行proftpd了,也可以用xinit超级服务器来运行,这个看看帮助就会了:)
服务是起来了,但是还暂时不能用,首先要先建立一个数据库,还要在数据库中添加表和记录。
数据库名你自己起一个, 偶的数据库名就叫ftp。
用mysql的客户端 /usr/local/mysql/bin/mysql -u root -p, xxbin推荐PhpMyAdmin, 偶常常使用Windows下的mysql客户端,比如DB-tools, MySQL-FRONT等等,很好用,类似于Microsoft SQL Server的Query Analyser。如果用mysql,记得在最后加";"号。
建立数据库
CREATE DATABASE FTP;
在数据库FTP中建立四张表
[code]USE FTP;
CREATE TABLE FTPUSERS (
userid TEXT NOT NULL,
passwd TEXT NOT NULL,
uid INT NOT NULL,
gid INT NOT NULL,
homedir TEXT,
shell TEXT
);
CREATE TABLE FTPGRPS (
groupname TEXT NOT NULL,
gid SMALLINT NOT NULL,
members TEXT NOT NULL
);
CREATE TABLE quotalimits (
name VARCHAR(30),
quota_type ENUM("user", "group", "class", "all") NOT NULL,
per_session ENUM("false", "true") NOT NULL,
limit_type ENUM("soft", "hard") NOT NULL,
bytes_in_avail FLOAT NOT NULL,
bytes_out_avail FLOAT NOT NULL,
bytes_xfer_avail FLOAT NOT NULL,
files_in_avail INT UNSIGNED NOT NULL,
files_out_avail INT UNSIGNED NOT NULL,
files_xfer_avail INT UNSIGNED NOT NULL
);
CREATE TABLE quotatallies (
name VARCHAR(30) NOT NULL,
quota_type ENUM("user", "group", "class", "all") NOT NULL,
bytes_in_used FLOAT NOT NULL,
bytes_out_used FLOAT NOT NULL,
bytes_xfer_used FLOAT NOT NULL,
files_in_used INT UNSIGNED NOT NULL,
files_out_used INT UNSIGNED NOT NULL,
files_xfer_used INT UNSIGNED NOT NULL
);[/code]
前两张表意思明确,偶就不多做解释了。quotatallies表不需要作修改,它记录了用户当前的磁盘使用情况,由程序自动记录。FTPGRPS中的members字段跟Linux的/etc/group文件一样,各个成员间用逗号","隔开。可以根据组或者用户来做磁盘限额。
quotalimits 表中一些字段的含意
quota_type 磁盘限额的鉴别,可以设置单个用户,也可以设置一个组中的全部用户,还可以设置全部用户;
bytes_in_avail 上传最大字节数,就是FTP用户空间容量;(设置这个字段的时候是以byte(字节)为单位,如果要限额在10M,那就是10240000,下面也一样)
bytes_out_avail 下载最大字节数,需要注意的是,这个字段中记录的是用户总共能从服务器上下载多少数据,数据是累计的;
bytes_xfer_avail 总共可传输的文件的最大字节数(上传和下载流量)需要注意的是,这个字段中记录的是用户总共能传输文件的最大字节数,数据是累计的;
files_in_avail 总共能上传文件的数目;
files_out_avail 能从服务器上下载文件的总数目;
files_xfer_avail 总共可传输文件的数目;(上传和下载)
不需要为每一个FTP用户建系统帐户,不是说一个系统帐户都不需要建立了。偶喜欢将FTP的根目录放在 /var/ftp下。
至少要建立一个系统组及用户
groupadd -g 3000 ftpgrp
useradd -u 3000 -g ftpgrp -d /var/ftp -s /sbin/nologin ftpuser
chown -R ftpuser:ftpgrp /var/ftp
chmod -R 755 /var/ftp
现在可以添加FTP用户了:
[code]use FTP
INSERT INTO FTPUSERS (userid, passwd, uid, gid, homedir, shell)
VALUES ('user1', '1234', '3000', '3000', '/var/ftp/user1', '' );
INSERT INTO FTPUSERS (userid, passwd, uid, gid, homedir, shell)
VALUES ('user2', '4321', '3000', '3000', '/var/ftp/user2', '' );[/code]
添加磁盘限额:
[code]INSERT INTO `quotalimits` ( `name` , `quota_type` , `per_session` , `limit_type` , `bytes_in_avail` , `bytes_out_avail` , `bytes_xfer_avail` , `files_in_avail` , `files_out_avail` , `files_xfer_avail` )
VALUES ('user1', 'user', 'false', 'soft', '10240000', '0', '2048000', '500', '0', '10');[/code]
表示对user1帐号给予10M空间,最多能上传500个文件到服务器上,文件传输流量为20M,只能传输10个文件。
这是基于用户,也可以基于组,在表FTPGRPS中添加记录
[code]INSERT INTO FTPGRPS (groupname, gid, members)
VALUES ('group1', '3000', 'user1,user2');[/code]
对应组添加磁盘配额
[code]INSERT INTO `quotalimits` ( `name` , `quota_type` , `per_session` , `limit_type` , `bytes_in_avail` , `bytes_out_avail` , `bytes_xfer_avail` , `files_in_avail` , `files_out_avail` , `files_xfer_avail` )
VALUES ('group1', 'group', 'false', 'soft', '10240000', '0', '2048000', '500', '0', '10');[/code]
OK, 现在可以进行测试了。
[url]ftp://ftp.yourdomain/[/url] 输入用户名和密码user1, 1234
用 quote SITE QUOTA 命令检查磁盘配额。
如果要支持匿名FTP, 还是需要添加系统帐户ftp的,Redhat Linux中应该有这个用户,没有就自己建一个,把它的用户目录指向你允许匿名FTP的目录就可以了。
呵呵,用php或JSP在数据库中添加记录是不是很容易的事情? 这样偶们就可以提供虚拟主机服务了。
页:
[1]