centos中proftpd mysql的安装与配置
proftpd安装
官方网站:http://www.proftpd.org
cd /web/soft/
wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.4c.tar.gz
tar xzvf proftpd-1.3.4c
cd proftpd-1.3.4c
./configure --prefix=/web/server/proftpd --with-modules=mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql --with-includes=/usr/include/mysql --with-libraries=/usr/lib64/mysql
vi Makefile
#在MAIN_LIBS= 后面加上-lpthread
make
make install
说明:
--with-modules=mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql
这句是让编译ProFTPD 支持MySQL的模块,并有磁盘限额支持;
--with-includes=
这是来指定MySQL服务器includes所在的位置;在这里我设置的是/usr/include/mysql,因为我的MySQL服务器的includes的确在这个目录;你可以根据自己的机器环境来调整;
--with-libraries=
这是来指定MySQL服务器libraries所在的位置;在这里我设置的是/usr/lib64/mysql,因为我的MySQL服务器的libraries的确在这个目录;你可以根据自己的机器环境来调整;
--prefix=
这是用来指定要把ProFTPD安装在哪个位置,在这里我把ProFTPD安装在了 /web/server/proftpd 目录下,您不必自己建目录 /web/server/proftpd ,在安装的时候这个目录会自动生成;当然您也可以自己来指定ProFTPD的安装位置;当我们不需要proftpd的时候,就可以直接删除proftpd目录;这样做好象是有点方便;
创建Proftpd启动脚本
cp contrib/dist/rpm/proftpd.init.d /etc/rc.d/init.d/proftpd
chmod 755 /etc/rc.d/init.d/proftpd
建立相应的用户和用户组
groupadd -g 5500 ftpgroup
useradd -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser
ProFTPD认证中的MySQL数据库
#创建mysql数据库
CREATE DATABASE `ftpdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
#创建mysql用户
CREATE USER 'proftpd'@'localhost' IDENTIFIED BY '123456';
GRANT USAGE ON * . * TO 'proftpd'@'localhost' IDENTIFIED BY '123456' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
#赋给用户权限
GRANT SELECT , INSERT , UPDATE ON `ftpdb` . * TO 'proftpd'@'localhost';
#创建数据表
use ftpdb;
CREATE TABLE `ftpgroup` (
`groupname` varchar(16) NOT NULL default '',
`gid` smallint(6) NOT NULL default '5500',
`members` varchar(16) NOT NULL default '',
KEY `groupname` (`groupname`)
) COMMENT='ProFTP group table';
INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpuser');
CREATE TABLE `ftpquotalimits` (
`name` varchar(30) default NULL,
`quota_type` enum('user','group','class','all') NOT NULL default 'user',
`per_session` enum('false','true') NOT NULL default 'false',
`limit_type` enum('soft','hard') NOT NULL default 'soft',
`bytes_in_avail` float NOT NULL default '0',
`bytes_out_avail` float NOT NULL default '0',
`bytes_xfer_avail` float NOT NULL default '0',
`files_in_avail` int(10) unsigned NOT NULL default '0',
`files_out_avail` int(10) unsigned NOT NULL default '0',
`files_xfer_avail` int(10) unsigned NOT NULL default '0'
) ;
CREATE TABLE `ftpquotatallies` (
`name` varchar(30) NOT NULL default '',
`quota_type` enum('user','group','class','all') NOT NULL default 'user',
`bytes_in_used` float NOT NULL default '0',
`bytes_out_used` float NOT NULL default '0',
`bytes_xfer_used` float NOT NULL default '0',
`files_in_used` int(10) unsigned NOT NULL default '0',
`files_out_used` int(10) unsigned NOT NULL default '0',
`files_xfer_used` int(10) unsigned NOT NULL default '0'
);
CREATE TABLE `ftpuser` (
`id` int(10) unsigned NOT NULL auto_increment,
`userid` varchar(32) NOT NULL default '',
`passwd` varchar(32) NOT NULL default '',
`uid` smallint(6) NOT NULL default '5500',
`gid` smallint(6) NOT NULL default '5500',
`homedir` varchar(255) NOT NULL default '',
`shell` varchar(16) NOT NULL default '/sbin/nologin',
`count` int(11) NOT NULL default '0',
`host` varchar(30) NOT NULL default '000-000-000-000',
`lastlogin` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) COMMENT='ProFTP user table';
ProFTPD的配置文件proftpd.conf
vi /web/server/proftpd/etc/proftpd.conf
ServerName "ProFTPD Default Installation"
ServerType standalone
ServerAdmin [email]admin@wwllcchf.com[/email]
DefaultServer on
Port 21
Umask 022
# 注最多30个ip同时登录使用ftp;
MaxInstances 30
# 设置最大的尝试登陆的次数,如果超过自动断开连接
MaxLoginAttempts 5
# 设置运行Proftpd服务的系统用户和组
User nobody
Group nobody
# 匿名用户 这里不使用,前面加"#"注消
#
# User ftp
# Group ftp
# 删除了anonymous登录的设置
AllowOverwrite on
#AllowStoreRestart on #允许断点续上传
#AllowRetrieveRestart on #允许断点续下载
#AllowForeignAddress on #要允许 FXP ,则为on
# 最大的用户数
MaxClients 100
# 服务器的欢迎信息
DisplayLogin welcome.msg
DisplayFirstChdir .message
# 连接时的MSG
DisplayConnect /web/server/proftpd/etc/connect.msg
#DisplayGoAway /web/server/proftpd/etc/goway.msg
# 输入quit命令后的MSG
DisplayQuit /web/server/proftpd/etc/quit.msg
MaxHostsPerUser 1
MaxClientsPerUser 2
# 对不起,一个IP只允许一个连接
MaxClientsPerHost 1
RootLogin off
RequireValidShell off
UseReverseDNS off
IdentLookups off
TimeoutStalled 600
TimeoutLogin 900
TimeoutIdle 600
TimeoutNoTransfer 600
# 让proftp支持现在流行的FXP传输方式,默认是不支持的
AllowForeignAddress on
# 端口也可自己指定
PassivePorts 49152 65534
# 允许断点续传是默认支持的,不用设置
# 这里有一个技巧,你可以控制FTP中任一个目录有"断点续传"的功能,请设置下面一行,(例:)
AllowStoreRestart on
AllowRetrieveRestart on
# 屏蔽服务器版本信息
ServerIdent off
# 设置ftpuser组只能访问自己的目录
DefaultRoot ~ ftpgroup
#-------- load sql.mod for mysql authoritative --------#
# Backend表示用户认证方式为MySQL数据库的认证方式
# Plaintext表示明文认证方式,排在最前面的为最先使用的方式
SQLAuthTypes Backend Plaintext
# 数据库的鉴别
SQLAuthenticate users* groups*
# 数据库联接的信息
# ftpdb是数据库名,localhost是主机名
# proftpd是连接数据库的用户名,password是密码
#(如果没有密码留空)
SQLConnectInfo ftpdb@localhost proftpd 123456
# 指定用来做用户认证的表的有关信息
SQLUserInfo ftpuser userid passwd uid gid homedir shell
SQLGroupInfo ftpgroup groupname gid members
# 如果用户主目录不存在,则系统会根据此用户在用户数据表中的homedir字段的值新建一个目录
SQLHomedirOnDemand on
SQLNegativeCache on
# Update count every time user logs in
SQLLogFile /var/log/proftpd.sql.log
SQLNamedQuery getcount SELECT "count from ftpuser where userid='%u'"
SQLNamedQuery getlastlogin SELECT "lastlogin from ftpuser where userid='%u'"
SQLNamedQuery updatelogininfo UPDATE "count=count+1,host='%h',lastlogin=current_timestamp() WHERE userid='%u'" ftpuser
SQLShowInfo PASS "230" "You've logged on %{getcount} times, last login at %{getlastlogin}"
SQLLog PASS updatelogininfo
#-------- load sql.mod for mysql authoritative --------#
#-------- load qudes.mod for Quota limit --------#
#打开磁盘限额引擎
QuotaEngine on
# 设置磁盘限额
QuotaDirectoryTally on
# 设置磁盘容量显示时的单位
QuotaDisplayUnits Mb
# 允许显示磁盘限额信息,ftp登录后可执行quote site quota命令查看当前磁盘使用情况
QuotaShowQuotas on
# 设置磁盘限额日志文件
QuotaLog "/var/log/proftpd.quota.log"
# 指定磁盘限额模块使用的数据库信息
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 ftpquotalimits \
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 ftpquotatallies \
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}'" ftpquotatallies
SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" ftpquotatallies
QuotaLimitTable sql:/get-quota-limit
QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally
#--------- load qudes.mod for Quota limit --------#
# Logging options
# Debug Level
# emerg, alert, crit (empfohlen), error, warn. notice, info, debug
#
SyslogLevel emerg
SystemLog /var/log/proftpd.system.log
TransferLog /var/log/proftpd.xferlog
# Some logging formats
#
LogFormat default "%h %l %u %t "%r" %s %b"
LogFormat auth "%v [%P] %h %t "%r" %s"
LogFormat write "%h %l %u %t "%r" %s %b"
# Log file/dir access
# ExtendedLog /var/log/proftpd.access_log WRITE,READ write
# Record all logins
ExtendedLog /var/log/proftpd.auth_log AUTH auth
# Paranoia logging level....
ExtendedLog /var/log/proftpd.paranoid_log ALL default
启动proftpd
/web/server/proftpd/sbin/proftpd
旧版本配置文件文件会出现以下错误
Fatal: unknown configuration directive 'SQLHomedirOnDemand'
Fatal: unknown configuration directive 'DisplayFirstChdir'
将DisplayFirstChdir替换为DisplayChdir
将SQLHomedirOnDemand替换为CreateHome
我在启动proftpd的时候出现以下错误
cch proftpd[26830]: warning: unable to determine IP address of 'cch'
cch proftpd[26830]: error: no valid servers configured
cch proftpd[26830]: Fatal: error processing configuration file '/web/server/proftpd/etc/proftpd.conf'
根据错误提示,是主机名和IP解析没法对应。
解决方法:
1,在配置文件/web/server/proftpd/etc/proftpd.conf里面增加 IP;
DefaultAddress 127.0.0.1
2,修改主机名 /etc/hosts
vi /etc/hosts 127.0.0.1 cch
/web/server/proftpd/sbin/proftpd --configtest 检测配置文件是否正确
补充说明:mysql> DESCRIBE quotalimits;
+------------------+------------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------------------------+------+-----+---------+-------+
| name | varchar(30) | YES | | NULL | |
| quota_type | enum('user','group','class','all') | | | user | |
| per_session | enum('false','true') | | | false | |
| limit_type | enum('soft','hard') | | | soft | |
| bytes_in_avail | float | | | 0 | |
| bytes_out_avail | float | | | 0 | |
| bytes_xfer_avail | float | | | 0 | |
| files_in_avail | int(10) unsigned | | | 0 | |
| files_out_avail | int(10) unsigned | | | 0 | |
| files_xfer_avail | int(10) unsigned | | | 0 | |
+------------------+------------------------------------+------+-----+---------+-------+
这个表里的各个参数分别代表:
name 应该这样理解,既能表示单个用户,也能表示用户组名;如果我们在quota_type(限额类型)中使用group来认证的话,那就得在这里设置组名,这样整组都具有统一的磁盘限额的特性;当然您要在ftpgroups表中插入组纪录;并且在member字段中得把用户一个一个的列进去,这是后话了;先自己研究一下,只是插入纪录的事;我们只说最简单的单个用户的磁盘限额;默认值可以为空NULL,如果为空则针对所在有quota_type中设置的类型,比如在quota_type中设置为user ,就是针对所有ftpusers 中的用户起作用;如果是group名,也是对ftpgroups 所有组作用;
quota_type 磁盘限额类型,可以设置为用户,也可以设置为用户组group ;如果您的name写的是用户组,那在这里就得设置为group来认定;默认为user认证;
per_session 默认为false;
limit_type 默认为soft;
bytes_in_avail 用户占用空间大小,也就是家目录的空间最大可以让用户占用多少,单位是byte;默认为0,0是不受限制,以下同理;
bytes_out_avail 注;所有下载文件的总和,默认为0;
bytes_xfer_avail 注;一个用户上传下载流量总和,默认为0
files_in_avail 注:限制上传文件总数,默认为0;
files_out_avail 注;限制下载文件个数总计,默认为0
files_xfer_avail 注:允许下载和上传的文件总和我,默认为0;
在数据库ftpuser添加一个虚拟用户"test",
mysql> insert into ftpuser (id,userid,passwd,uid,gid,homedir,shell) values ('1', 'test','test','5500','5500','/home/test','/sbin/nologin');
十佳人物