CentOS 7安装配置pure-ftpd
pure-ftpd是ftp服务端,可以与mysql整合,通过mysql建立和验证ftp账户,实现流量、磁盘、带宽等限制功能。可以自己开发php程序来实现web管理。
安装步骤:
一、安装mysql-devel
mysql-devel是pureftpd整合mysql必须的。安装的mysql-devel尽量和安装的mysql用相同版本号。
yum install mysql-devel
二、安装pureftpd
wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.42.tar.gz
tar zxf pure-ftpd-1.0.42.tar.gz
cd pure-ftpd-1.0.42
./configure --without-capabilities --with-virtualchroot --with-mysql --with-pam --with-altlog --with-cookie --with-throttling --with-ratios --with-paranoidmsg --with-quotas --with-everything
如果编译配置提示mysql-init没有正确安装,说明你没有安装mysql-devel.
make && make install
安装完毕!
三、配置pureftpd
cp pureftpd-mysql.conf /etc/
cp configuration-file/pure-config.pl /usr/local/sbin/
chmod 755 /usr/local/sbin/pure-config.pl
cp configuration-file/pure-ftpd.conf /etc/
cp contrib/redhat.init /etc/rc.d/init.d/pureftpd
chmod u+x /etc/rc.d/init.d/pureftpd
chkconfig --add pureftpd
chkconfig --level 2345 pureftpd on
service pureftpd start
然后编辑/etc/pure-ftpd.conf
确保ChrootEveryone 、MySQLConfigFile 和CreateHomeDir是开启的.
ChrootEveryone yes
MySQLConfigFile /etc/pureftpd-mysql.conf
CreateHomeDir yes
编辑 /etc/pureftpd-mysql.conf
如下:
MYSQLSocket /tmp/mysql.sock
MYSQLUser pureftpd
MYSQLPassword 这里输入前面给mysql授权时的密码
MYSQLDatabase pureftpd
#MYSQLCrypt md5, cleartext, crypt() or password() - md5 is VERY RECOMMENDABLE uppon cleartext
MYSQLCrypt md5
MYSQLGetPW SELECT Password FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MYSQLGetUID SELECT Uid FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MYSQLGetGID SELECT Gid FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MYSQLGetDir SELECT Dir FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MySQLGetBandwidthUL SELECT ULBandwidth FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MySQLGetBandwidthDL SELECT DLBandwidth FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MySQLGetQTASZ SELECT QuotaSize FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MySQLGetQTAFS SELECT QuotaFiles FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
创建组和用户以及mysql表创建
# groupadd ftpgroup –g 10000
# useradd ftpuser –g ftpgroup –u 10000 –d /dev/null –s /sbin/nologin
然后进入mysql
#/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
输入密码后就进入mysql了,然后创建pureftpd数据表及赋予mysql中用户的权限。
CREATE DATABASE pureftpd;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO 'pureftpd'@'localhost' IDENTIFIED BY '对应的密码';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO 'pureftpd'@'localhost.localdomain' IDENTIFIED BY '对应的密码';
FLUSH PRIVILEGES;
USE pureftpd;
CREATE TABLE ftpd (
User varchar(16) NOT NULL default '',
status enum('0','1') NOT NULL default '0',
Password varchar(64) NOT NULL default '',
Uid varchar(11) NOT NULL default '-1',
Gid varchar(11) NOT NULL default '-1',
Dir varchar(128) NOT NULL default '',
ULBandwidth smallint(5) NOT NULL default '0',
DLBandwidth smallint(5) NOT NULL default '0',
comment tinytext NOT NULL,
ipaccess varchar(15) NOT NULL default '*',
QuotaSize smallint(5) NOT NULL default '0',
QuotaFiles int(11) NOT NULL default 0,
PRIMARY KEY (User), UNIQUE KEY User (User)
) TYPE=MyISAM;
查看表结构
mysql> desc ftpd;
注意创建的表名是ftpd,而pureftpd配置文件/etc/pureftpd-mysql.conf中默认数据库命令操作的表名是users。修改下任意一种即可。
数据表说明:
User:帐号名;
status:0 表示帐号被禁用,无法登录服务器;
Password:密码,使用MD5加密;
Uid:前面创建的ftpuser帐户号,我们填写的是10000;
Gid:前面创建的ftpgroup组号,我们填写的是10000;
Dir:虚拟用户的个人目录路径,将在/home下创建(第一次登录);
ULBandwidth:上传文件限制速度,KB/s,0为不限制;
DLBandwidth:下载文件限制速度,KB/s,0为不限制;
comment:备注信息;
ipaccess:* 表示任意IP都可以访问此ftp服务器,输入具体IP地址可以只允许此IP连接服务器;
QuotaSize:用户磁盘空间分配,单位:MB,0表示不加限制;
QuotaFiles:用户可以保存的文件数量限制,0表示不加限制。
好了,向数据库中添加一个用户,把我们fptd的服务重启一下吧!
#service pureftpd restart
不出意外,我们的ftp服务是可以用了。