How to configure virtual user Disk Quota using PureFTPd + Mysql + PHP_Manager

Source: Internet
Author: User
Tags crypt ldap

Install PureFTPdIn the past, we had to make the following preparations:
1. Install FreeBSD4.9.
2. Customize the kernel and add "options QUOTA" to the kernel to support user quotas. (Note: how to implement other * nix systems? Please search for them by yourself .)
3. Install the APACHE + PHP platform, because we will use PHP_Manager to implement online user management later. (Note: There are many online tutorials on this installation content. You can directly install it using PORTS under FreeBSD .)
After completing the above preparations, we can start the installation process.
(Note: all of the following installations are installed using PORTS)
I. Installation Mysql
My installed MysqlThe version is 4.0, so you can try it if you have the latest version.

# Cd/usr/ports/database/mysql40-server
# Make install clean

After installation, a STARTUP script is generated at/usr/local/etc/rc. d/Mysql-Server. sh

You can run the following command to seeMysqlWhether the service has been started.

# Ls | grepMysql

If any information is returned, it indicatesMysqlStarted. If not, run the following command.

# Cd/usr/local/etc/rc. d
#./Mysql-Server. sh start

If you want to stopMysqlService.

#/Usr/local/etc/rc. d/Mysql-Server. sh stop

After the service is started, let's test whether the database runs normally:
(Note: by defaultMysqlThe user is root, and the password is empty, so please log on immediatelyMysqlModify the password of the root user)

#Mysql

The following content indicates the operation is normal.

Welcome toMySQLMonitor. Commands end with; or \ g.
YourMySQLConnection id is 16 to server version: 4.0.18
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql>
Enter exit to exitMysql.

IsMysqlThe root user sets a password of 123456.

# Mysqladmin-u root password '123'

After setting the password, let's test whether the password has taken effect.

#Mysql-U root-p
Enter password:

The password is displayed. Enter the correct password and press Enter.
If the following content appears, the setting is successful.
Welcome toMySQLMonitor. Commands end with; or \ g.
YourMySQLConnection id is 16 to server version: 4.0.18
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql>

If the following content appears, the setting fails. (If so, you will be miserable, haha)

ERROR 1045: Access denied for user: 'root @ localhost' (Using password: YES)

Ii. InstallationPureFTPd
1. Next we will start to installPureFTPd, Also installed in FreeBSD Ports.

# Cd/usr/ports/ftp/pure-ftpd
# Make WITH_MYSQL = 1 \MYSQLDatabase Support
WITH_LANG = simplified-chinese \ The prompt text is simplified chinese
CONFIGURE_ARGS = \
'-- Prefix =/usr/local/Pureftpd\ Installation directory
-- With-paranoidmsg \ // Well... I don't know how to say it. It can be a message to a specific person.
-- With-welcomemsg \ // the information displayed after logon is supported. I am not sure, haha
-- With-uploadscript \ // when a file is fully uploaded, a script is automatically called
Processing. Of course. You have to write this script yourself.
-- With-largefile \ // supports downloading files larger than 2 GB.
-- With-cookie \ // The stuff that the user sees when logging in to the website. Similar to the dashboard.
-- With-virtualchroot \ // safe chroot.
-- With-virtualhosts \ // similar to the virtualhost of http.
-- With-virtualroot \ // supports Virtual root
-- With-diraliases \ // The link function on Serv-U is the same.
-- With-quotas \ // use quota. (non-system quota)
-- With-sysquotas \ // the operating system's Quota (Disk Quota) is allowed)
-- With-ratios \ // supports the upper/lower transfer ratio.
-- With-ftpwho \ // use the pure-ftpwho command to view online users.
-- With-everything \ // All functions are available. (Do It Yourself)
-- With-throttling '// The bandwidth can be set.
Install clean

After the installation is complete,PureftpdDirectory. All the files to be used are in this directory.

2. Now let's start configuring the pure-ftpd.conf File
Here I use all the default values. Only the following content is modified to supportMYSQL. (Note:PureftpdSupports both ldap and,Mysql, Pgsql, and puredb certification)

#MySQLConfiguration file (see README.MySQL)
MySQLConfigFile/usr/local/Pureftpd/Etc/Pureftpd-Mysql. Conf

3. Detailed configuration file (from Pure-FTPd + LDAP +MySQL+ PGSQL + Virtual-Users + Quota How To)
ChrootEveryone yes
Each chroot user is equivalent to the DefaultRoot ~ in Proftpd ~ To restrict user activity in a certain place and enhance server security. When using wu-ftpd, you should know what will happen to cd!
TrustedGID 50
# Use the above two together
BrokenClientsCompatibility no
MaxClientsNumber 50
# Maximum number of links
Daemonize yes
# Fork in background run in the background as a daemon
MaxClientsPerIP 5
# The maximum number of connections per ip address. It is best to set a small point.
VerboseLog no
# Whether to log all client commands
DisplayDotFiles no
# Show files starting
AnonymousOnly no
# Whether to allow anonymous logon only
NoAnonymous no
# Anonymous Login Disabled
SyslogFacility ftp
# The log should be filtered (auth, authpriv, daemon, ftp, security, user, local *) so that the log can only record the desired information
DontResolve yes
# Do not reverse interpret the client's ip address
MaxIdleTime 5
# Maximum idle time
# LDAPConfigFile/usr/local/Pureftpd/Etc/Pureftpd-Ldap. conf
# Use LDAP for authentication,
MySQLConfigFile/usr/local/Pureftpd/Etc/Pureftpd-Mysql. Conf
# UseMySQLAuthentication
# PGSQLConfigFile/usr/local/Pureftpd/Etc/Pureftpd-Pgsql. conf
# Use PGSQL for authentication
# PureDB/ftp/etc/Pureftpd. Pdb
# Database storage location of user data [because I usePureFTPDBuilt-in options]
# ExtAuth/var/run/ftpd. sock
# Pure-authd socket path (for details, see README. Authentication-Modules)
# PAMAuthentication yes
# Enable PAM Authentication
# UnixAuthentication yes
# If you want to have simple Unix (/etc/passwd) authentication
FortunesFile/usr/local/Pureftpd/Etc/. welcome
# A welcome information file is displayed. You can create this file, input some text, and restart your FTP service to discover it unexpectedly.
LimitRecursion 2000 8
# Ls list up to 3000 files. The deepest layer is 8
AnonymousCanCreateDirs no
# Anonymous users can create directories
MaxLoad 4
# When system load exceeds 4, users cannot download
PassivePortRange 30000 50000
# Passive connection response range
ForcePassiveIP 192.168.0.1
# Not translated :(
AnonymousRatio 1 10
# Anonymous connection upload/download Ratio
UserRatio 1 10
# User upload/download ratio (Note: If ldap is used,Mysql, Pgsql, pam do not enable this function, otherwise the Ratio you set in ldap and so on is not School)
AntiWarez no
# The uploaded file cannot be downloaded (the owner is ftp). Wait until the local admin confirms
Bind 127.0.0.1, 8021
# Bind the FTP and ip/port. There are two FTP servers in your system so that one of your FTP servers will use another port.
# Format-> 127.0.0.1, 21 if you only write the port table All ip, port
AnonymousBandwidth 8
# Anonymous bandwidth, in KB/s
UserBandwidth 8
# User bandwidth, in KB/s
Umask 133: 022
# Umask. (<umask for files >:< umask for dirs>)
Min uid 1000
# At least the UID can be logged on
AllowUserFXP yes
# Support does not support FXP
AllowAnonymousFXP no
# The Anonymous branch does not support FXP
ProhibitDotFilesWrite no
ProhibitDotFilesRead no
# Can a file starting with (".") be read/written? a file starting with a dot in UNIX Like can be listed only when the hidden file ls-a is used.
#PureftpdGenerate the ". ftpquota" file in Quota mode.
AutoRename no
# Automatically Rename an uploaded file if it has the same file name (file.1, file.2 ...)
AnonymousCantUpload no
# Uploading files by anonymous users
TrustedIP 10.1.1.1
# Lock IP address.
LogPID
# Add a PID to the Log file
AltLog stats:/ftp/etc/log/Pureftpd. Log
# Log storage location. Note that there are several common log formats
# Clf is similar to apache format, stats UNIX log format, w3c standard W3C format, and may be HTML Format
NoChmod yes
# Do not grant Chmod command Permissions
KeepAllFiles no
# Users can continue to transfer files. Files cannot be deleted.
CreateHomeDir yes
# If the user's home does not exist, it is automatically created (I set this to YES)
Quota 1000:10
# Quota <file count>: <Megabytes capacity>. FTP is limited to 10 MB and 1000 files can be uploaded (Note: If ldap is used,Mysql, Pgsql, pam do not enable this function, otherwise the Quota you set in ldap and so on will not be School)
PIDFile/ftp/etc/log/pure-ftpd.pid
# Record the PID file of pure-ftpd
CallUploadScript yes
# Call UploadScript
MaxDiskUsage 99
# When the hard disk usage reaches, the upload will be stopped
NoRename yes
# You Cannot rename a file name.
CustomerProof yes
PerUserLimits :20
# <Maximum number of Logon times for each account: Maximum number of Logon times for Anonymous>

4. CreateMysqlFTP virtual user management database ftpusers in the database
Save the following content as a script.MysqlFile

INSERTMysql. User (Host, User, Password, Select_priv, Insert_priv, Update
_ Priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Proces
S_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv) VALUES
('2017. 0.0.1 ', 'ftp', PASSWORD ('000000'), 'y', 'n', 'n ', 'N', 'n', 'n'
', 'N ');

Flush privileges;

Create database ftpusers;

USE ftpusers;

Create table admin (
Username varchar (35) not null default '',
Password char (32) binary not null default '',
Primary key (Username)
) TYPE = MyISAM;

Insert into admin VALUES ('admin', MD5 ('20140901 '));

Create table users (
User char (16) not null default '',
Password char (32) binary not null default '',
Uid int (11) not null default '123 ',
Gid int (11) not null default '20140901 ',
Dir char (128) not null default '',
QuotaFiles int (10) not null default '20140901 ',
QuotaSize int (10) not null default '30 ',
ULBandwidth int (10) not null default '80 ',
DLBandwidth int (10) not null default '80 ',
Status enum ('0', '1') not null default '1 ',
Ipaccess varchar (15) not null default '*',
Comment tinytext not null,
Primary key (User ),
Unique key User (User)
) TYPE = MyISAM;

Insert into 'users' VALUES ('kevin ', MD5 ('000000'), 123456,'/home/kevin ', 30,
80, 5 );

First inMysqlThe database creates an ftp user with Operation permissions on the database with a password of 123456.
Create a new database ftpusers, create two new tables admin and users, add the Management User Account to the admin table, and add the new FTP user kevin to the users table. The password is 123456.

Then run the following command to generate the database ftpusers.

#Mysql-U root-ppassword <script.Mysql
Note that-p is used to enter the password, and there is no space between it and the password you entered later.

5. Modify/usr/local/Pureftpd/Etc/Pureftpd-Mysql. Conf configuration file
The content is as follows:

MYSQLServer 127.0.0.1
#MYSQLServer IP Address
MYSQLPort 3306
#MYSQLPort Number
MYSQLSocket/var/lib/Mysql/Mysql. Sock
# Use UNIX. sock for local connection
Note: select either MYSQLServer or MYSQLSocket.

MYSQLUser ftp
# MYSQLUser data Username
MYSQLPassword 123456
#MYSQLDatabase User Password
MYSQLDatabase ftpusers
# FTP data database
MYSQLCrypt md5
# Password encryption methods: "cleartext", "crypt", "md5" and "password"
# Cleartext plaintext, crypt, md5, and password are Backend password ('your-passwd') functions (MYSQLPassword () function used by the database)
MYSQLGetPW SELECT Password FROM users WHERE User = "\ L"
# Password field. I use the Password in the users table as the Password field.
MYSQLGetUID SELECT Uid FROM users WHERE User = "\ L"
# UID user ID field
MYSQLDefaultUID 1000
# Default UID (Note: If this option is enabled, MYSQLGetUID will be ineffective)
MYSQLGetGID SELECT Gid FROM users WHERE User = "\ L"
# GID group ID field
MYSQLDefaultGID 1000
# Default GID (Note: If this option is enabled, MYSQLGetGID will be ineffective)
MYSQLGetDir SELECT Dir FROM users WHERE User = "\ L"
# FTP user directory such as/home/web/www-9812-net
MySQLGetQTAFS SELECT QuotaFiles FROM users WHERE User = "\ L"
# Disk Quota and file quantity limit. For example, 1000 allows users to upload thousands of files.
MySQLGetQTASZ SELECT QuotaSize FROM users WHERE User = "\ L"
# Disk quota, FTP user space limit (unit: M), for example: 100 M
MySQLGetRatioUL SELECT ULRatio FROM users WHERE User = "\ L"
MySQLGetRatioDL SELECT DLRatio FROM users WHERE User = "\ L"
# Upload/download Ratio. MySQLGetRatioUL indicates the upload ratio and MySQLGetRatioDL indicates the download ratio. Example: 1: 5
MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User = "\ L"
MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User = "\ L"
# Download/download bandwidth (unit: KB/s ). MySQLGetBandwidthUL upload bandwidth and MySQLGetBandwidthDL download bandwidth. For example, upload kb/s and download 50KB/s
MySQLForceTildeExpansion 1
MySQLTransactions On
# No translation

After modifying the configuration file, we will continue.

6. RunPureFTPd
To achieve Anonymous logon, you must add an ftp user to the system.

With ftp, you must have an account.
# Vipw
Ftp: *: 2000: 2000: 0: 0: ftp:/home/ftp:
/Sbin/nologin
# Vi/etc/group
Ftpusers: *: 2000:

After the operation, we add an ftp account that belongs to the ftpusers group. The user id and group id are both 2000

StartPureFTPd
#/Usr/local/Pureftpd/Bin/pure-config.pl ../etc/pure-ftpd.conf

To facilitate Ftp service management in the future, I created a new one in/usr/local/etc/rc. d.Pureftpd. Sh file.

# ViPureftpd. Sh

#! /Bin/sh

Case "$1" in
Start)
[-X/usr/local/Pureftpd/Etc/pure-ftpd.conf] & \
/Usr/local/Pureftpd/Bin/pure-config.pl/usr/local/Pureftpd// Etc/pure-ftpd.c
Onf>/dev/null &&\
Echo-n 'ure-ftp'

Stop)
Killall pure-ftpd>/dev/null &&\
Echo-n 'ure-ftp'

*)
Echo "Usage: 'basename $ 0' {start | stop}"> & 2

Esac

Exit 0

Set the executable permissions for this file

# Chmod u + xPureftpd. Sh

You can run the following command to startPureFTPdService

#/Usr/local/etc/rc. d/Pureftpd. Sh start

Run the following command to stopPureFTPdService

#/Usr/local/etc/rc. d/Pureftpd. Sh stop

Test whether FTP is normal.
# Ftp your IP address
Connected to 127.0.0.1.
220 ---------- welcome to Pure-FTPd ----------
220-You Have 1st users, up to 50 connections
220-now the local time is. Server port: 21.
220 if there is no activity within 15 minutes, you will be disconnected.
Name (127.0.0.1: kevin): kevin
Password:
230-user kevin has the following permissions: ftpusers
230-this server supports FXP Transmission
230-OK. The currently restricted directory is/
Remote system type is UNIX.
Using binary mode to transfer files.
Ftp>

Congratulations, your FTP service is working properly.

3. Use PHP_Manager for user management

Download the latest PHP_Manager Software

# Tar zxvf ftp_v1.3.1.tar.gz
# Mv ftp_v1.3.1/www/path/data/ftp
# Cd/www/path/data/ftp
# Vi config. php
Modify the config. php configuration file

$ LANG = $ ZH_CN; // language used by your PHP_Manager
$ DBHost = "localhost"; // yourMysqlHost of the server
$ DBLogin = "ftp"; // user logging on to the database
$ DBPassword = "123456"; // password of the user logging on to the database
$ DBDatabase = "ftpusers"; // name of the database that implements virtual user management
$ FTPAddress = "61.132.35.21: 21"; // IP address and port number of your FTP service

Then, log on to the management console as a webpage.

Http: // your server domain name/ftp

The administrator is administrator and the password is 123456, which can be modified during database creation.
It's all Chinese. Do not write more.
Happy!

I have modified PHP_Manager to support Chinese characters, and now it is uploaded to everyone.

Http://www.linuxsir.org/bbs/attachment.php? S = & postid = 578136.

For installation methods in other systems, see Pure-FTPd + LDAP +MySQL+ PGSQL + Virtual-Users + Quota How To

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.