Proftpd + mysql + quota _mysql

Source: Internet
Author: User
There are a lot of articles on proftpd installation on the internet. I just sorted it out a little and used the new quota disk quota module. because proftpd is in the latest version 1.2.8 or RC, some settings cannot be used, therefore, 1.2.7 is used here. First download the source code proftpd1.2.7: ftp. proftpd. orgdistribsourceproftpd has a lot of articles on proftpd installation on the internet. I just sorted it out a bit and used the new quota disk quota module. because proftpd is in the latest version 1.2.8 and RC version, some settings cannot be used in general, so 1.2.7 is used here.
  
  
  
First download the source code
Proftpd1.2.7:
Ftp://ftp.proftpd.org/distrib/source/proftpd-1.2.7.tar.bz2

Mod_quotatab-1.2.4 (version 1.2.5 of mod_quotatab is used on the latest 1.2.8rc1)
Http://www.castaglia.org/proftpd/modules/proftpd-mod-quotatab-1.2.4.tar.gz

Assume that mysql has been installed on your machine.
Start compilation and installation
Decompress the proftpd source code package to a temporary directory:
Localhost proftpd # tar-jxvf proftpd-1.2.7.tar.bz2
Extract mod_quotatab-1.2.4
Localhost proftpd # tar-zxvf proftpd-mod-quotatab-1.2.4.tar.gz
Go to the mod_quotatab Directory
Localhost proftpd # cd mod_quotatab
Copy the files in mod_quotatab to the modules directory in proftpd.
Localhost mod_quotatab # cp * ../proftpd-1.2.7/modules
  
Before running configure, we need to change a file.
Go to the proftpd-1.2.7/contrib Directory
Localhost mod_quotatab # cd ../proftpd-1.2.7/contrib
Modify mod_ SQL _mysql.c
Localhost contrib # vi mod_ SQL _mysql.c
Find # include and set it to your actual path
If your mysql is installed in/usr/local/mysql, change it to # include r.
Then
Localhost contrib # cd ..
Localhost proftpd-1.2.7 # cd ..
Localhost proftpd #./configure -- prefix = DIR -- with-modules = mod_ SQL: mod_ SQL _mysql: mod_quotatab: mod_quotatab_ SQL -- with-synchronized des = DIR -- with-libraries = DIR
Three places to be modified
-- Prefix = DIR: where do you want to install it?
-- With-primary des = DIR mysql's primary des Directory
-- With-libraries = DIR mysql lib Directory
Then
Make
Make install
  
Next, go to the proftpd directory you have installed and modify the etc/proftpd. conf file to start configuration.
I will not talk much about basic configuration. There are a lot of articles on the Internet, but I can't find them myself. here I will mainly introduce how to configure mysql User Authentication and disk quota.
  
Mysql User authentication:
Add the following content to proftpd. conf:
  
# Set MySQL authentication:
# Database Connection information. DatabaseName indicates the database name and HostName indicates the host name,
# Port indicates the Port number, UserName indicates the UserName used to connect to the database, and Password indicates the Password.
SQLConnectInfo DatabaseName @ HostNameort UserName Password
  
# Database authentication type:
SQLAuthTypes Backend Plaintext
  
# Specify information about the table used for user authentication. ("FTPUSERS" and "FTPGRPS" are the names of the data tables, which will be created below after a while)
SQLUserInfo FTPUSERS userid passwd uid gid homedir shell
  
SQLGroupInfo FTPGRPS groupname gid members
  
# Set to allow users to log on if shell is empty:
RequireValidShell off
  
# Database authentication
SQLAuthenticate users groups usersetfast groupsetfast
  
# If the home directory does not exist, the system creates a directory based on its home item:
SQLHomedirOnDemand on
  
Create a user table FTPUSERS in this database, which is required:
  
Use FTP;
Create table FTPUSERS (
Userid text not null,
Passwd text not null,
Uid int not null,
Gid int not null,
Home TEXT,
Shell TEXT
);
This table is required for user authentication. userid and passwd are essential, and userid is the username used for FTP service; passwd is the password of this user; uid is the ID of the system user, that is, the mapped system user; gid is the ID of the system group to which the user belongs; home is the HOME directory of the user; you can specify a shell for this user. Of course, you can create more fields, such as the count used to record the number of user logins, or the date of the date. if you are familiar with the configuration, you can add more features as you like. I will not talk about it here.
3. if you want to use all the functions, you can add another required Table: FTPGRPS, that is, the table for determining the group. of course, you can skip this, here is a format:
Create table FTPGRPS (
Pagername text not null,
Gid smallint not null,
Members text not null,
);
In this example, the value of "kgname" indicates the group name, "gid" indicates the system Group ID, and "members" indicates the group members. Note: Multiple members must be separated by commas (,). spaces are not allowed.
  
4. empty table insert records:
Insert into ftpusers (userid, passwd, uid, gid, home, shell)
ValueS ('user1', '000000', '000000', '000000', '/home/FTP/user1 ','');
  
In this format, you can insert a record for each user.
If you want to apply more features and create a group table, you also need to add records for it. However, you must note that multiple members in the members field must be separated by commas.
  
Insert into ftpgrps values ('ftpgrppps', 1000, 'ftpusr ');
4. create system users for FTP users.
In this example, only one valid system user FTPUSR and a group FTPGRP are provided for the entire FTP service. of course, you can also set multiple system users. For the sake of security, I only set one, use it to start FTP daemon, and map all FTP users to this user.
  
Create an FTPGRP group first:
Groupadd-g 1000-r FTPGRP
Create an FTPUSR User:
Adduser-u 1000-g 1000-d/home/FTP-s/bin/bash-r FTPUSR
  
Create a HOME for FTPUSR and store all the FTP user active spaces in this directory:
Mkdir/home/FTP
Chown FTPUSR/home/FTP
Chgrp FTPGRP/home/FTP
  
Here, even if the MYSQL authentication is basically configured, the next part is the disk quota.
  
First, edit the proftpd file.
  
# Disk quota
QuotaDirectoryTally on
  
# Disk quota unit: B "|" Kb "|" Mb "|" Gb"
QuotaDisplayUnits "Kb"
  
QuotaEngine on
  
# Disk quota log records
QuotaLog "your LOG path"
  
# Enable the disk QUOTA information. after logging on to the FTP account, run the "quote site quota" command to display the disk QUOTA of the current user.
QuotaShowQuotas on
  
# The following is an SQL call Statement. you do not need to modify the statement and copy it directly.
  
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
  
Create a mysql data table
Create table quotalimits (
Name VARCHAR (30 ),
Quota_type ENUM ("user", "group", "class", "all") not null,
Per_session ENUM ("false", "true") not null,
Limit_type ENUM ("soft", "hard") not null,
Bytes_in_avail float not null,
Bytes_out_avail float not null,
Bytes_xfer_avail float not null,
Files_in_avail int unsigned not null,
Files_out_avail int unsigned not null,
Files_xfer_avail INT UNSIGNED NOT NULL
);
  
Create table quotatallies (
Name VARCHAR (30) not null,
Quota_type ENUM ("user", "group", "class", "all") not null,
Bytes_in_used float not null,
Bytes_out_used float not null,
Bytes_xfer_used float not null,
Files_in_used int unsigned not null,
Files_out_used int unsigned not null,
Files_xfer_used INT UNSIGNED NOT NULL
);
  
Note: The quotatallies table does not need to be modified. it records the user's current disk usage and is automatically recorded by the program.
Note the meaning of some fields in the quotalimits table.
Quota_type: identifies the disk quota. you can set a single user, set all users in a group, and set all users.
Bytes_in_avail the maximum number of bytes for uploading, that is, the FTP User space capacity (when setting fields, the unit is byte (bytes,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.