Proftpd+Mysql+Quota的配置
Proftpd+Mysql+Quota的配置:這篇文章整理而來(lái),包括Proftpd+Mysql+Quota的配置。依照本文步驟逐步實(shí)行。mysql/php/apache安裝就免了,需要說(shuō)明的是我的mysql是使用源碼安裝!
相關(guān)軟件:
---------------------------------------------------------------
proftpd-1.2.9.tar.gz
proftpd-mod-quotatab-1.2.11.tar.gz
ftpdb.sql
proftpd.conf
---------------------------------------------------------------
步驟如下:
代碼:
- vi /etc/ld.so.conf
添加:/usr/local/mysql/lib
- tar zvxf proftpd-1.2.9.tar.gz
- tar zvxf proftpd-mod-quotatab-1.2.11.tar.gz
- cp mod_quotatab/*.c proftpd-1.2.9/contrib/
- cp mod_quotatab/*.h proftpd-1.2.9/contrib/
- vi proftpd-1.2.9/contrib/mod_sql_mysql.c
- #include
修改mysql.h的實(shí)際路徑
- cd proftpd-1.2.9
- ./configure \--prefix=/usr/local/proftpd \--with-modules=mod_sql:mod_sql_mysql:mod_quotatab\:mod_quotatab_sql:mod_ratio \--with-includes=/usr/local/mysql/include \--with-libraries=/usr/local/mysql/lib
- make
- make install
- cp proftpd-1.2.9/contrib/dist/rpm/proftpd.init.d /etc/rc.d/init.d/proftpd
- vi /etc/rc.d/init.d/proftpd
修改:PATH="$PATH:/usr/local/proftpd/sbin"
- chmod 755 /etc/rc.d/init.d/proftpd
- chkconfig --level 3 proftpd on
- groupadd -g 5500 ftpgroup
- adduser -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser
#p#
然后配置你的Proftpd.conf
最后就是啟動(dòng)啦。/usr/local/proftpd/sbin/proftpd
-------------------------------Proftpd.conf----------------------------------
代碼:
- # 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 "ltsnet"
- 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 30
- # 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.
- ServerIdent off
- DisplayLogin welcome.msg
- DefaultRoot ~
- # Normally, we want files to be overwriteable.
- AllowOverwrite on
- # A basic anonymous configuration, no upload directories. If you do not
- # want anonymous users, simply delete this entire section.
- 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
- DenyAll
- SQLAuthTypes Backend Plaintext
- SQLAuthenticate users* groups*
- SQLConnectInfo ftpdb@localhost root 123456
- SQLUserInfo ftpuser userid passwd uid gid homedir shell
- SQLGroupInfo ftpgroup groupname gid members
- SQLHomedirOnDemand on
- SQLLog PASS updatecount
- SQLNamedQuery updatecount UPDATE "countcount=count+1,accessed=now() WHERE userid='%u'" ftpuser
- SQLLog STOR,DELE modified
- SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser
- QuotaEngine on
- QuotaDirectoryTally on
- QuotaDisplayUnits Mb
- QuotaShowQuotas on
- QuotaLog "/var/log/quota"
- 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_usedbytes_in_used = bytes_in_used + %{0}, bytes_out_usedbytes_out_used = bytes_out_used+ %{1}, bytes_xfer_usedbytes_xfer_used = bytes_xfer_used + %{2}, files_in_usedfiles_in_used = files_in_used + %{3}, files_out_usedfiles_out_used = files_out_used + %{4}, files_xfer_usedfiles_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
#p#
建ftpdb庫(kù),在phpMyAdmin中導(dǎo)入ftpdb.sql就ok。
--------------------------------------ftpdb.sql---------------------------------
代碼:
- # 表的結(jié)構(gòu) `ftpgroup`
- #
- 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`)
- ) TYPE=MyISAM COMMENT='ProFTP group table';
- #
- # 導(dǎo)出表中的數(shù)據(jù) `ftpgroup`
- #
- INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpuser');
- # --------------------------------------------------------
- #
- # 表的結(jié)構(gòu) `ftpquotalimits`
- #
- 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'
- ) TYPE=MyISAM;
- #
- # 導(dǎo)出表中的數(shù)據(jù) `ftpquotalimits`
- #
- INSERT INTO `ftpquotalimits` VALUES ('test', 'user', 'true', 'hard', '9e+06', '2000', '9e+09', 2000, 2000, 2000);
- # --------------------------------------------------------
- #
- # 表的結(jié)構(gòu) `ftpquotatallies`
- #
- 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'
- ) TYPE=MyISAM;
- #
- # 導(dǎo)出表中的數(shù)據(jù) `ftpquotatallies`
- #
- INSERT INTO `ftpquotatallies` VALUES ('test', 'user', '2000', '2000', '2000', 2000, 2000, 2000);
- # --------------------------------------------------------
- #
- # 表的結(jié)構(gòu) `ftpuser`
- #
- 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',
- `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' AUTO_INCREMENT=3 ;
- #
- # 導(dǎo)出表中的數(shù)據(jù) `ftpuser`
- #
- INSERT INTO `ftpuser` VALUES (1, 'test', '123456', 5500, 5500, '/home/test', '/sbin/nologin', 36, '2004-09-28 13:07:41', '2004-09-28 13:07:42');
quotalimits表
代碼:
name: - 用戶帳號(hào)
quota type: - user, group, class, all (we use user)
per_session: - true or false (we use true)
limit_type: - 硬限制 or 軟限制 (我們一般用硬限制)
bytes_in_avail: - 允許上傳的字節(jié)數(shù)
bytes_out_avail: - 允許下載的字節(jié)數(shù)
bytes_xfer_avail: - 允許傳輸?shù)淖止?jié)數(shù)(包括上傳/下載)
files_in_avail: - 允許上傳的文件數(shù)
files_out_avail: - 允許下載的文件數(shù)
files_xfer_avail: - 允許傳輸?shù)奈募?shù)(包括上傳/下載)
按這些步驟來(lái)安裝,應(yīng)該沒(méi)問(wèn)題。
老實(shí)說(shuō)用mysql和quota模塊來(lái)驗(yàn)證用戶和設(shè)置磁盤限額,但我總覺(jué)得還是不夠完善,因?yàn)樵谶@個(gè)方法中,數(shù)據(jù)庫(kù)表里還沒(méi)有相應(yīng)的權(quán)限的字段,所以說(shuō)相應(yīng)用戶的權(quán)限還是得用實(shí)際得用戶即mysql對(duì)應(yīng)得uid和gid來(lái)控制權(quán)限,要是mysql數(shù)據(jù)庫(kù)也能完全控制權(quán)限就好了,以上就是Proftpd+Mysql+Quota的完全配置。