ubuntu pure-ftpd + mysql 配置詳情

上一篇文章是使用PureDB來存儲虛擬用戶信息,本篇文章將會使用mysql來存儲ftp用戶數據信息

一 下載安裝

編譯安裝
./configure --with-mysql --with-rfc2640 --with-everything --with-puredb
在安裝的時候出現了一個小問題:ubuntu configure: error: libmysqlclient is needed for MySQL support
解決方法:安裝libmysqlclient-dev包

二 配置

ChrootEveryone               yes
BrokenClientsCompatibility   no
MaxClientsNumber             50
Daemonize                    yes
MaxClientsPerIP              8
VerboseLog                   no
DisplayDotFiles              yes
AnonymousOnly                no
NoAnonymous                  yes  #禁止匿名用戶登陸
SyslogFacility               auth
DontResolve                  yes
MaxIdleTime                  15
MySQLConfigFile              /etc/pureftpd-mysql.conf    #mysql驗證
PureDB                       /etc/pureftpd.pdb
LimitRecursion               10000 8
AnonymousCanCreateDirs       no
MaxLoad                      4
PassivePortRange             30000 50000  #被動模式
ForcePassiveIP              172.30.51.200 
AntiWarez                    yes
Umask                        133:022
MinUID                       100
AllowUserFXP                 no
AllowAnonymousFXP            no
ProhibitDotFilesWrite        no
ProhibitDotFilesRead         no
AutoRename                   no
AnonymousCantUpload          no
MaxDiskUsage                   99
CustomerProof                yes

三 創建用戶

建立mysql認證數據庫

[root@localhost ~]# mysql -uroot -p
mysql>create database pureftpd;
mysql>grant all privileges on pureftpd.* to 'pureftpuser'@'%' identified by 'pureftpuser';
mysql>flush privileges;
mysql>use pureftpd;
mysql> create table if not exists `users`(
	`user` varchar(16) not null default '',
	`password` varchar(32) not null default '',
	`uid` int(11) not null default '1000',
	`gid` int (11) not null default '1000',
	`dir` varchar(128) not null default '',
	`quotafiles` int(10) not null default '0',
	`quotasize` int(10) not null default '0',
	`ulbandwidth` int(10) not null default '0',
	`dlbandwidth` int(10) not null default '0',
	`ipaddress` varchar(15) not null default '*',
	`comment` tinytext,
	`status` enum('0','1') not null default '1',
	`ulratio` smallint(5) not null default '1',
	`dlratio` smallint(5) not null default '1',
	primary key (`user`),
	unique key `user` (`user`)
	)engine=innodb default charset=utf8;
mysql> show tables;
+--------------------+
| Tables_in_pureftpd |
+--------------------+
| users              |
+--------------------+
1 row in set (0.00 sec)
mysql> desc users;
+-------------+---------------+------+-----+---------+-------+
| Field       | Type          | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| user        | varchar(16)   | NO   | PRI |         |       |
| password    | varchar(32)   | NO   |     |         |       |
| uid         | int(11)       | NO   |     | NULL    |       |
| gid         | int(11)       | NO   |     | NULL    |       |
| dir         | varchar(128)  | NO   |     |         |       |
| quotafiles  | int(10)       | NO   |     | 0       |       |
| quotasize   | int(10)       | NO   |     | 0       |       |
| ulbandwidth | int(10)       | NO   |     | 0       |       |
| dlbandwidth | int(10)       | NO   |     | 0       |       |
| ipaddress   | varchar(15)   | NO   |     | *       |       |
| comment     | tinytext      | YES  |     | NULL    |       |
| status      | enum('0','1') | NO   |     | 1       |       |
| ulratio     | smallint(5)   | NO   |     | 1       |       |
| dlratio     | smallint(5)   | NO   |     | 1       |       |
+-------------+---------------+------+-----+---------+-------+

User:帳號名;
Password:密碼,使用MD5加密;
Uid:前面創建的ftpuser帳戶號;
Gid:前面創建的ftpgroup組號;
Dir:虛擬用戶的個人目錄路徑;
ULBandwidth:上傳文件限制速度,KB/s,0爲不限制;
DLBandwidth:下載文件限制速度,KB/s,0爲不限制;
comment:備註信息;
ipaccess:* 表示任意IP都可以訪問此ftp服務器,輸入具體IP地址可以只允許此IP連接服務器;
QuotaSize:用戶磁盤空間分配,單位:MB,0表示不加限制;
QuotaFiles:用戶可以保存的文件數量限制,0表示不加限制。
status:0 表示帳號被禁用,無法登錄服務器;

在數據庫中創建pureftp虛擬用戶

mysql> insert into users values ('xixi','password','7777','7777','/ftp','500','30','30','50','*','','1','1','1');
mysql> select * from users\G;
*************************** 1. row ***************************
       user: bev
   password: 5bc915d575ad9c57aa0fc6e1fd719615
        uid: 7777
        gid: 7777
        dir: /ftp
 quotafiles: 500
  quotasize: 30
ulbandwidth: 30
dlbandwidth: 50
  ipaddress: *
    comment: 
     status: 1
     ulratio: 1
    dlratio: 1
1 row in set (0.11 sec)

ERROR: 
No query specified

注意mysql賬戶密碼的加密方式需要與pureftp支持的機密方式相吻合,不然會出現530錯誤

mysql> update users set password=md5('pureftpuser') where user='bev';
   我在這裏選擇的MD5加密方式,那麼在下面配置pureftp的加密方式時一定選擇MD5。

修改pureftp關於mysql模塊的配置文檔 /etc/pureftpd-mysql.conf 如果文件不存在,請在源碼包中拷貝即可

# Optional : define the location of mysql.sock if the server runs on this host.
MYSQLSocket     /var/lib/mysql/mysql.sock      # mysql.sock文件
MYSQLUser       pureftpuser                    # mysql用戶名
MYSQLPassword   pureftpuser                    # mysql密碼
MYSQLDatabase   pureftpd                       # mysql數據庫名
MYSQLCrypt      md5                            #加密方式,這裏用md5加密

MYSQLGetPW      SELECT Password FROM users WHERE User='\L'
MYSQLGetUID     SELECT Uid FROM users WHERE User='\L'
MYSQLGetGID     SELECT Gid FROM users WHERE User='\L'
MYSQLGetDir     SELECT Dir FROM users WHERE User='\L'
MySQLGetQTAFS   SELECT QuotaFiles FROM users WHERE User='\L'
MySQLGetQTASZ   SELECT QuotaSize FROM users WHERE User='\L'
MySQLGetRatioUL SELECT ULRatio FROM users WHERE User='\L'
MySQLGetRatioDL SELECT DLRatio FROM users WHERE User='\L'
MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User='\L'
MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User='\L'

這裏重點說下;這個配置文件是你數據庫的對應的數據庫和表的內容,不要按照網上的複製,根據自己數據庫建立的數據庫和表做相應的配置。
表中必須的內容有 用戶名,密碼,Uid,Gid,Dir,其餘皆可省略。請注意與你的配置文件相對應。

重啓pureftp,測試剛剛建立的xixi是否生效了
在這裏,我提醒大家出現錯誤先去vi /var/log/messages 看下ftp標籤所報錯誤,對症下藥。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章