proftpd 1.3.1rc3 + Mysql5 + Quota安装(全)

技术分享 Story 80浏览 0评论
摘要

proftpd 1.3.1rc3 + Mysql5 + Quota安装(全)

1、下载proftpd-1.3.1rc3,编译(mysql安装在/opt/mysql5中)
proftpd-1.3.1rc3不需要再下载mod-quotatab了,直接编译安装就可以了

./configure --prefix=/opt/proftpd --enable-ctrls --with-modules=mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql --with-includes=/opt/mysql5/include/mysql --with-libraries=/opt/mysql5/lib/mysql

make
make install

2、创建Proftpd启动脚本
cp contrib/dist/rpm/proftpd.init.d /etc/init.d/proftpd
--------------------------------------------------------------
vi /etc/init.d/proftpd
找到PATH="$PATH:/usr/local/sbin"这一句
将它改成PATH="$PATH:/opt/proftpd/sbin"
chmod 755 /etc/init.d/proftpd
或者
ln -s /opt/proftpd/sbin/ftpshut /usr/local/sbin/ftpshut
ln -s /opt/proftpd/sbin/proftpd /usr/local/sbin/proftpd
-----------------------------------------------------------

3、建立相应的用户和用户组
groupadd -g 5500 ftpgroup
adduser -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser

4、进入mysql数据库执行

Mysql用户管理相关表
CREATE TABLE `ftpgroups` (
`groupname` varchar(30) NOT NULL,
`gid` int(11) NOT NULL,
`members` varchar(255) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=gbk;

CREATE TABLE `ftpusers` (
`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` )
) TYPE = MYISAM

quota数据库管理相关表

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;

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;

5、ProFTPD的配置文件proftpd.conf
ServerName "FOO FTP"
ServerType standalone
ServerAdmin FOO@gmail.com
DefaultServer on
Port 21
Umask 022
MaxInstances 100
User nobody
Group nobody
MaxClients 100
DisplayLogin welcome.msg
DisplayChdir .message
MaxHostsPerUser 1
MaxClientsPerUser 5
MaxClientsPerHost 5
RootLogin off
RequireValidShell off
UseReverseDNS off
IdentLookups off
TimeoutStalled 600
TimeoutLogin 900
TimeoutIdle 600
TimeoutNoTransfer 600
AllowForeignAddress on
PassivePorts 61000 62999
AllowStoreRestart on
AllowRetrieveRestart on
AllowOverwrite on
ServerIdent off
DefaultRoot ~ ftpgroup

#Log Set
SyslogLevel emerg
SystemLog /opt/proftpd/log/proftpd.system.log
TransferLog /opt/proftpd/log/proftpd.xferlog
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"
ExtendedLog /opt/proftpd/log/proftpd.auth_log AUTH auth
ExtendedLog /opt/proftpd/log/proftpd.paranoid_log ALL default

#MySQL Auth Set
SQLAuthTypes Backend Plaintext
SQLAuthenticate users* groups*
SQLConnectInfo proftpd@localhost ftp ftp123
SQLUserInfo ftpusers userid passwd uid gid homedir shell
SQLGroupInfo ftpgroups groupname gid members
SQLNegativeCache on
SQLLogFile /opt/proftpd/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

#MySQL Quota Set
QuotaEngine on
QuotaDirectoryTally on
QuotaDisplayUnits Mb
QuotaShowQuotas on
QuotaLog "/opt/proftpd/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

转载请注明:成长的对话 » proftpd 1.3.1rc3 + Mysql5 + Quota安装(全)