(源自網絡)proftpd+mysql+quota
- 詳細內容
- 分類: FTP
- 發佈: 2006-05-28, 週日 21:22
- 作者 Super User
- 點擊數: 18860
一。準備工作
1。你的機器上已調試好了apache+php+mysql環境
2。下載PROFTPD
wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.2.10.tar.gz
因為發現1.2.10直接支持sql和quota
二。安裝
tar -zxvf proftpd-1.2.10.tar.gz
cd proftpd-1.2.10
引用:
1) ./configure --with-modules=mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql --with-libraries=/usr/lib/mysql --with-includes=/usr/include/mysql
2) make
3) make install
修改proftpd配置
vi /usr/local/etc/proftpd.conf
內容改為:
ServerName "newsbook.net"
ServerType standalone
DefaultServer on
# 用戶登陸時不顯示ftp伺服器版本資訊
ServerIdent off
# 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
MaxLoginAttempts 3
TimeoutLogin 120
TimeoutIdle 600
TimeoutNoTransfer 900
TimeoutStalled 3600
MaxClients 100
# 設置每台主機最多併發連接數
MaxClientsPerHost 3
AllowOverwrite no
AllowStoreRestart on
UseReverseDNS off
IdentLookups off
# 設置如果shell為空時允許用戶登錄
RequireValidShell off
# 將用戶限制在自己的主目錄下
DefaultRoot ~
# 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
# Set the user and group under which the server will run.
User nobody
Group nobody
# Normally, we want files to be overwriteable.
<Directory />
AllowOverwrite on
</Directory>
# A basic anonymous configuration, no upload directories.
# 匿名登錄設置。匿名用戶目錄為/ftp
#<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>
以上是PROFTPD.conf
下面加入sql和quota
# 資料庫聯接的資訊,proftpdb是資料庫名,localhost是主機名,newsbook是連接資料庫的用戶名,
#books123是密碼
#(如果沒有密碼留空)
SQLConnectInfo proftpdb@localhost newsbook books123
# 資料庫認證的類型
SQLAuthTypes Backend Plaintext
# 資料庫的鑒別
SQLAuthenticate users* groups*
# 指定用來做用戶認證的表的有關資訊。
SQLUserInfo proftpd_users username password uid gid homedir shell
SQLGroupInfo proftpd_groups groupname gid members
# 如果home目錄不存在,則系統會根據它的home項新建一個目錄
SQLHomedirOnDemand on
這是目錄所有者,我覺得這個很重要。所以我用nobody來做,在此我的nobody為99.
SQLDefaultGID 99
SQLDefaultUID 99
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "count=count+1,accessed=now() WHERE username='%u'" proftpd_users
# Update modified everytime user uploads or deletes a file
SQLLog STOR,DELE modified
SQLNamedQuery modified UPDATE "modified=now() WHERE username='%u'" proftpd_users
# 啟用磁片限額
QuotaDirectoryTally on
# 磁片限額單位 b"|"Kb"|"Mb"|"Gb"
QuotaDisplayUnits "Kb"
QuotaEngine on
# 磁片限額日誌記錄
QuotaLog "/var/log/proftpquota.log"
# 打開磁片限額資訊,當登陸FTP帳戶後,使用命令 "quote SITE 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 proftpd_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 proftpd_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}'" proftpd_quotatallies
SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" proftpd_quotatallies
QuotaLimitTable sql:/get-quota-limit
QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally
下面可以用phpmyadmin在mysql裏加入,我的sql為以下
CREATE DATABASE proftpdb;
grant all on proftpdb.* to newsbook@localhost identified by 'books123';
USE proftpdb
CREATE TABLE `proftpd_groups` (
`groupname` varchar(16) NOT NULL default '',
`gid` smallint(6) NOT NULL default '99',
`members` varchar(16) NOT NULL default '',
KEY `groupname` (`groupname`)
) TYPE=MyISAM COMMENT='ProFTP group table';
INSERT INTO `proftpd_groups` VALUES ('nobody', 99, 'test');
CREATE TABLE `proftpd_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'
) TYPE=MyISAM;
INSERT INTO `proftpd_quotalimits` VALUES ('test','user','false','hard','15728640','0','0','0','0','0');
CREATE TABLE `proftpd_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'
) TYPE=MyISAM;
CREATE TABLE `proftpd_users` (
`id` int(10) unsigned NOT NULL auto_increment,
`username` varchar(32) NOT NULL default '',
`password` varchar(32) NOT NULL default '',
`uid` smallint(6) NOT NULL default '99',
`gid` smallint(6) NOT NULL default '99',
`homedir` varchar(255) NOT NULL default '',
`shell` varchar(16) NOT NULL default '/sbin/nologin',
`count` int(11) NOT NULL default '0',
`accessed` datetime NOT NULL default '0000-00-00 00:00:00',
`modified` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='ProFTP user table';
INSERT INTO `proftpd_users` VALUES (1, 'test', 'test', 99, 99, '/home/hosting/test', '/sbin/nologin',0,'','');
CREATE TABLE `proftpd_admins` (
`username` varchar(50) NOT NULL default '',
`password` varchar(50) NOT NULL default '',
`firstname` varchar(50) NOT NULL default '',
`lastname` varchar(50) NOT NULL default '',
`startpage` int(6) NOT NULL default '0'
) TYPE=MyISAM;
INSERT INTO proftpd_admins VALUES ( 'admin', 'books123', 'Default_admin', 'Default_admin', '0');
mkdir -p /home/hosting/test
chown -R nobody:nobody /home/hosting
啟動proftpd
service xinetd restart