T086学习网 | 站长学院 | 技术文档 | 成语 | 歇后语 | 帝国时代 | 代码收藏 | IP地址查询 | 生活百科 | 生日密码 | CSS压缩 | 用户评论 | 欣欣百宝箱

ProFTPD 支持MySQL数据库添加虚拟用户认证及Quotas(磁盘限额)

【 来源:LinuxSir.Org作者:北南南北 更新时间:2006-10-10 | 字体:
[导读]作者:北南南北来自:LinuxSir.Org摘要:本文讲述了ProFTPD 支持MySQL数据库认证,比如添加虚拟用户、用户空间大小的限制(磁盘限额 Quotas);本文是实践文档; 目录 0、前言 1、什么是ProFTPD; 2、ProFTPD的编译和...

3、ProFTPD认证中的MySQL数据库

3.1、创建一个ProFTPD的数据库proftpd;

首先您应该会把MySQL数据库服务器打开,以MySQL的超级管理员root进入创建名为proftpd的数据库;


[root@localhost ~]# mysql -uroot -p
Enter password: 注:在这里请您输入MySQL的管理密码;
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 41 to server version: 4.1.11
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>create database proftpd;
mysql>Grant select,insert,update,delete,create,drop,index,alter,create temporary tables,lock tables on proftpd.* to proftpd@localhost Identified by "123456";
mysql>quit

说明:

create database proftpd; 这行是创建名为proftpd的数据库;
Grant 这行是为proftpd 数据库授权,让用户名为proftpd,密码为123456(这只是一个例子,密码自己定义),这个用来管理proftpd这个数据库;
quit 这行是退出mysql界面;

3.2、导入proftpd数据库;

下面是一个现成的数据库,你只需要导入就行了,比较简单;把下面的代码拷贝下来,然后另存为 proftpd.sql;然后通过下面的命令来导入;

[root@localhost ~]# mysql -uproftpd -p proftpd <proftpd.sql
Enter password: 在这里输入proftpd 数据库管理员proftpd 的密码,我们前面举例是123456,以你设置的为准;

下面是proftpd的数据库,您可以拷贝下来,另存为 proftpd.sql ,然后用上面的命令来导入;

-- 数据库: `proftpd`
--
-- --------------------------------------------------------
--
-- 表的结构 `ftpgroups`
--
CREATE TABLE `ftpgroups` (
  `groupname` varchar(30) NOT NULL default '',
  `gid` int(11) NOT NULL default '1000',
  `members` varchar(255) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- 表的结构 `ftpusers`
--
CREATE TABLE `ftpusers` (
  `userid` varchar(30) NOT NULL default '',
  `passwd` varchar(80) NOT NULL default '',
  `uid` int(10) unsigned NOT NULL default '1000',
  `gid` int(10) unsigned NOT NULL default '1000',
  `homedir` varchar(255) NOT NULL default '',
  `shell` varchar(255) NOT NULL default '/sbin/nologin',
  `count` int(10) unsigned NOT NULL default '0',
  `host` varchar(30) NOT NULL default '',
  `lastlogin` varchar(30) NOT NULL default '',
  UNIQUE KEY `userid` (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- 导出表中的数据 `ftpusers`
--
INSERT INTO `ftpusers` VALUES ('test', 'test', 1000, 1000, '/home/test', '/sbin/nologin',0,'','');
-- --------------------------------------------------------
--
-- 表的结构 `quotalimits`
--
CREATE TABLE `quotalimits` (
  `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'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- 表的结构 `quotatallies`
--
CREATE TABLE `quotatallies` (
  `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'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;




4、ProFTPD的配置文件proftpd.conf

在我们这个例子中,ProFTPD的配置文件在/opt/proftpd/etc目录中,就是proftpd.conf文件;您可以把它改名备份;

[root@localhost ~]# cd /opt/proftpd/etc/
[root@localhost etc]# mv proftpd.conf proftpd.confBAK

然后再新建一个 proftpd.conf 文件,内容如下;您可以对这个文件进行相应的调整;其中#号部份就是注掉的,不会生效;注意一下MySQL连接数据库部份;另外如果您不是把ProFTPD安装在了/opt/proftpd目录下,一些东西也是需要调整的;自己看着办吧;

# 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 "My TestFTP" #这是您的FTP服务器的名字,自己写定
ServerType standalone
ServerAdmin xxxxx@xxxxxxxxxxx.com #这是管理员信箱,自己来写;
DefaultServer On
# Display message
DisplayLogin /opt/proftpd/etc/ftplogin.msg
#DisplayConnect /net/messages/ftp.pre
#DisplayFirstChdir index.txt
# Port 21 is the standard FTP port.
Port 21
# Limit users to login by username
<Limit LOGIN>
AllowAll
</Limit>
# Umask 022 is a good standard umask to prevent new dirs and files
# from being group and world writable.
Umask 022
# Limit login attempts
#
MaxLoginAttempts 5
# Set the maximum number of seconds a data connection is allowed
# to "stall" before being aborted.
TimeoutStalled 600
TimeoutLogin 900
TimeoutIdle 600
TimeoutNoTransfer 600
# 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 ~
# Users needs a valid shell
#
RequireValidShell off
# Performance: skip DNS resolution when we process the logs...
UseReverseDNS off
# Turn off Ident lookups
IdentLookups off
# Restart session support
#
AllowStoreRestart on
AllowRetrieveRestart on
#-------- load sql.mod for mysql authoritative --------#
SQLConnectInfo proftpd@localhost proftpd 123456
#注:上面这行是MySQL连接服务器部份,自己根据情况来改一改;
SQLAuthTypes Plaintext
SQLUserInfo ftpusers userid passwd uid gid homedir shell
SQLGroupInfo ftpgroups groupname gid members
SQLAuthenticate users groups
SQLNegativeCache on
SQLHomedirOnDemand on
SQLLogFile /var/log/proftpd.sql.log
SQLNamedQuery getcount SELECT "count from ftpusers where userid='%u'"
SQLNamedQuery getlastlogin SELECT "lastlogin from ftpusers where userid='%u'"
SQLNamedQuery updatelogininfo UPDATE "count=count+1,host='%h',lastlogin=current_timestamp() WHERE userid='%u'" ftpusers
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 --------#
QuotaDirectoryTally on
QuotaDisplayUnits "Mb"
QuotaEngine on
#QuotaLog /var/log/proftpd.quota.log
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 --------#
# 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
#注;上面几行是存放log的设置,不必改动也行;查看log就到上面相应的文件看吧;
# 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 30 #注最多30个ip同时登录使用ftp;
# Maximum clients with message
#MaxClients 2 "Sorry, max %m users -- try again later"
MaxClientsPerHost 2 "Sorry, only 2 session for one host"
#注每个ip,只能两个线程程,请自己调整;
# Normally, we want files to be overwriteable.
<Directory />
  AllowOverwrite on
</Directory>
RootLogin off
RequireValidShell off
# alphanumeric characters for uploads (and not shell code...)
#PathAllowFilter "^[a-zA-Z0-9_.-]()'+$"
#PathAllowFilter "^[a-zA-Z0-9 _.-]()'+$"
# We don't want .ftpaccess or .htaccess files to be uploaded
#PathDenyFilter "(.ftp)|(.ht)[a-z]+$"
#pathDenyFilter ".ftp[a-z]+$"
# Do not allow to pass printf-Formats (security! see documentation!):
#AllowFilter "^[a-zA-Z0-9@~ /,_.-]*$"
#DenyFilter "%"


  • 转载请注明来源:IT学习网 网址:http://www.t086.com/ 向您的朋友推荐此文章
  • 特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系我们,我们会尽快予以更正。
更多
留言建议ASP探针PHP探针站长Enjoy的Blog
© 2017 T086学习网 - T086.com(原itlearner.com)
RunTime:9.80ms QueryTime:7