Proftpd learning note (four)
Today we speak Proftp MySQL quota applications, I think everyone is about this.
1. First we build corresponding users and user groups
GroupAdd -g 5500 ftpgroup
Adduser -u 5500 -s / bin / false -d / bin / null -c "proFTPD user" -g ftpgroup ftpuser
2. Operating the database
MySQL mysql -uroot -ppassword
Create Database FTPDB
Grant SELECT, UPDATE ON fTPDB. * to proFTPD @ localhost identified by 'password'
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`)) Type = Myisam 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') 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; 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: 0000-00-00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00:00: 00' User Table ' ;
Note that everyone fills in the username and password of its own database according to the actual situation. If you are not familiar with the database, you can use phpMyAdmin to operate.
3. Configure the Proftp file
ServerName "Frank's FTP Server" Servertype Standalone Default Server ON
Port 21
Umask 022
MaxInstances 30maxloginattempts 3
User NobodyGroup NoBody
MaxHostsPerUser 1 "Sorry, you may not connect more than one time." MaxClientsPerUser 2 "Only one such user at a time." MaxClientsPerHost 3 "Sorry, you may not connect more than one time." RootLogin offRequireValidShell offTimeoutStalled 10MaxClients 10AllowForeignAddress onAllowStoreRestart onServerIdent offDefaultRoot ~ ftpgroup
SQLAUTHTYPES BACKEND PLAINTEXT # backend indicates that the user authentication method is the authentication method of the mysql database.
# Databasename @ host database_user user_passwordSQLConnectInfo ftpdb @ localhost proftpd passwordSQLUserInfo ftpuser userid groupname gid membersSQLHomedirOnDemand on # If the user's home directory does not exist, it will be the value passwd uid gid homedir shellSQLGroupInfo ftpgroup system according to this user in the user data table homedir fields to create a new directory # Update count every time user logs inSQLLog PASS updatecountSQLNamedQuery updatecount UPDATE "count = count 1, accessed = now () WHERE userid = '% u'" ftpuser # Update modified everytime user uploads or deletes a fileSQLLog STOR, DELE modifiedSQLNamedQuery modified UPDATE " Modified = now () where userid = '% u' "ftpuser
QuotaEngine onQuotaDirectoryTally onQuotaDisplayUnits MbQuotaShowQuotas onQuotaLog "/ 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_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-limitquotatallytable sql: / get-quota-tally / update-quota-tally / insert-quota-tally
OK, it's as simple, restart the PROFTP service can already use the function of ProftP MySQL Quota
We can add a virtual user in the database FTPUser,
INSERT INTO `FTPUSER` VALUES (1, 'Test', 'ftppasswd', 5500, 5500, '/ home / test', '/ sbin / nologin');
Everyone can add a user directly in PHPMYADMIN. I believe how to teach everyone.
If you want to set Quota, just set up in the ftpquotalimits table, the various parameters in this table represent:
Quotalimits table
Name: - User, Group, Class, All (We Use user) Per_session: - True Or False (We Use true) Limit_Type: - Hard limit OR soft limit (we generally use hard restrictions) BYTES_IN_AVAIL: - The number of bytes allowed to be uploaded BYTES_OUT_AVAIL: - Allow downloaded bytes Bytes_xfer_avail: - Allowed bytes (including upload / download) files_in_avail: - Allows upload file_out_avail: - Allow Download file number files_xfer_avail: - Allow The number of files (including upload / download)
Honestly use the MySQL and Quota modules to verify the user and set disk limit, but I always feel that it is not perfect, because in this method, there is no field of permissions in the database table, so I say that the authority of the corresponding user is actually used. The user is Mysql corresponding to the UID and GID to control the permissions. If the mysql database can completely control the permissions. If you feel that you feel the format copy, you may go wrong, you may wish to download my profile and database table directly.
Download proFTPD.conf download ftpdb.sql just the corresponding UID and GID in my database table are 5500, you can modify it according to your own situation :) Pay attention to digestion.