操作系统版本:Ubuntu8.10server(intrepid)
linux核心:2.6.27-7-server
MySQL 在安装操作系统时已经选择安装(或者安装完系统后进行在线安装:apt-get install mysql-server mysql-client)
一、安装proftpd
这里安装的是1.3.2(解决中文字符显示问题)
编译安装步骤如下:
1、切换到用户本地源目录:cd /usr/local/src
2、下载源文件:wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.2.tar.gz
3、解压:tar -zxvf proftpd-1.3.2.tar.gz
4、安装gcc编译套件:apt-get install build-essential
5、安装更新gcc:apt-get install gcc
6
- 、./configure --enable-shadow --enable-autoshadow --enable-dso --enable-nls --with-modules=mod_ifsession:mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql
- --with-includes=/usr/include/mysql --with-libraries=/usr/lib/
- (--with-includes=MySQL服务器includes所在的位置,用到mysql.h;
- --with-libraries=MySQL服务器libraries所在的位置,用到libmysqlclient.a)
7、make
8、make install
9、make clean(重新编译用,***次跳过,重复6-8步骤)
10、制作开机启动脚本:vi /etc/init.d/proftpd
粘贴如下代码:
- #!/bin/sh
- # ProFTPD files
- FTPD_BIN=/usr/local/sbin/proftpd
- FTPD_CONF=/usr/local/etc/proftpd.conf
- PIDFILE=/usr/local/var/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
11、给proftpd设置非root用户的可执行权限:chmod +x proftpd
12、安装启动服务管理程序:apt-get install sysv-rc-conf
13、sysv-rc-conf设置proftpd开机自启动
#p#
二、配置proftpd.conf文件
1、客户端支持GBK编码:UseEncoding UTF-8 GBK
2、加快登陆速度:IdentLookups off
UseReverseDNS off
3、定义登录欢迎消息文件:
DisplayLogin /usr/local/etc/ftplogin.msg
4、权限控制:(未解决中文登录名权限控制)
5、MySQL验证:
- #-------- load sql.mod for mysql authoritative --------#
- #配置FTP用户为MySQL数据库认证方式
- #SQLConnectInfo databaseName@hostName:port userName password
- SQLConnectInfo proftpd@localhost ftpuser 123456
- #Backend表示用户认证方式为MySQL数据库的认证方式
- #Plaintext表示明文认证方式,排在最前面的为***使用的方式
- SQLAuthTypes Backend Plaintext
- #校验数据表
- #SQLAuthenticate users groups usersetfast groupsetfast
- SQLAuthenticate users
- #指定ftp用户数据表的名字和其中的字段名,表名可自行定义,字段名不要改动。
- SQLUserInfo ftpusers userid passwd uid gid homedir shell
- #指定ftp用户组数据表的名字和其中的字段名,这个数据表是可选的,字段名不要改动。
- #SQLGroupInfo ftpGroup groupname gid members
- #指定是否必须为FTP用户指定一个系统shell,off表示不用指定,on表示必须指定。为了系统安全应该指定为off。
- RequireValidShell off
- #如果用户主目录不存在,则系统会根据此用户在用户数据表中的homedir字段的值新建一个目录
- #SQLHomedirOnDemand on
- SQLNegativeCache on
- SQLLogFile /var/log/proftpd.sql.log
- #用户登录欢迎窗口中显示登录用户已访问次数
- SQLNamedQuery getlogins SELECT "login_counts from ftpusers where userid='%u'"
- SQLNamedQuery updatelogins UPDATE "login_counts=login_counts+1 WHERE userid='%u'" ftpusers
- SQLShowInfo PASS "230" "You've logged on %{getlogins} times!"
- SQLLog PASS updatelogins
- #-------- load sql.mod for mysql authoritative --------#
6、磁盘配额:
- #-------- load qudes.mod for Quota limit --------#
- #打开磁盘限额引擎
- QuotaEngine on
- #设置磁盘限额
- QuotaDirectoryTally on
- #设置磁盘容量显示时的单位
- QuotaDisplayUnits Mb
- #设置磁盘限额日志文件
- QuotaLog "/var/log/proftpd.quota.log"
- #允许显示磁盘限额信息,ftp登录后可执行quote site quota命令查看当前磁盘使用情况
- QuotaShowQuotas on
- #指定磁盘限额模块使用的数据库信息
- 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
- #--------- load qudes.mod for Quota limit --------#
#p#
三、建立FTP用户认证相关表
1、默认root用户只能从本地登陆,新建admin用户:
- shell>mysql -u root -p
- password: ********
- mysql>GRANT ALL PRIVILEGES ON *.* TO admin@"%" IDENTIFIED BY "123456" WITH GRANT OPTION;
- mysql>GRANT ALL PRIVILEGES ON *.* TO admin@"localhost" IDENTIFIED BY "123456" WITH GRANT OPTION;
2、创建proftpd数据库:
- mysql>CREATE DATABASE proftpd;
3、建立一个访问proftpd库用户:ftpuser
- mysql>GRANT ALL PRIVILEGES ON proftpd.* TO ftpuser@"%" IDENTIFIED BY "123456";
- mysql>GRANT ALL PRIVILEGES ON proftpd.* TO ftpuser@"localhost" IDENTIFIED BY "123456";
4、建立用户验证表:
- shell>mysql -u ftpuser -p proftpd
- password: ********
- mysql>CREATE TABLE ftpusers (
- userid VARCHAR(30) NOT NULL UNIQUE,
- passwd VARCHAR(80) NOT NULL,
- uid INTEGER UNIQUE,
- gid INTEGER,
- homedir VARCHAR(255),
- shell VARCHAR(255)
- )DEFAULT CHARSET=gbk;
5、建立磁盘限额数据表
- 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
- )DEFAULT CHARSET=gbk;
- 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
- )DEFAULT CHARSET=gbk;
- #以上quotalimits表是FTP用户的磁盘限额配置信息,quotatallies表存放的是用户磁盘限额变动的信息。
- #quotatallies表不需要作修改,由程序自动记录
- #下面是quotalimits 表中各字段的含意:
- quota_type 磁盘限额的鉴别
- bytes_in_avail 上传***字节数,就是FTP用户空间容量
- bytes_out_avail 下载***字节数
- bytes_xfer_avail 总共可传输的文件的***字节数(上传和下载流量)
- files_in_avail 总共能上传文件的数目
- files_out_avail 能从服务器上下载文件的总数目
- files_xfer_avail 总共可传输文件的数目(上传和下载)
6、数据表数据初始化
6.1 建立用户:
如果想要一次增加一个新记录,可以使用INSERT语句:
- INSERT INTO ftpUsers (userid, passwd, uid, gid, homedir, shell) values ('centre', password('centre'), 2001,2000, '/home/ftp','/usr/sbin/nologin');
如果想要将文本文件“ftpusers.txt”装载到ftpusers表中,使用LOAD DATA语句:
- LOAD DATA LOCAL INFILE '/path/ftpusers.txt' INTO TABLE ftpusers CHARACTER SET 'gbk' LINES TERMINATED BY '\r\n';
6.2 建立磁盘配额:
test 用户512000000byte限制
- 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 ('test', 'user', 'true', 'hard', 512000000, 0,0,0,0,0);
【编辑推荐】