linux proftpd mysql_虚拟主机与Proftpd和MySQL(包括配额)在Ubuntu 14.04LTS

本教程详细介绍了如何在Ubuntu 14.04LTS上安装使用MySQL数据库管理虚拟用户的Proftpd服务器,包括设置配额,并使用phpMyAdmin进行管理。教程涵盖了从安装MySQL、phpMyAdmin到配置Proftpd和创建MySQL数据库表的整个过程。
摘要由CSDN通过智能技术生成

本文档介绍如何安装使用MySQL数据库而不是真实系统用户的虚拟用户的Proftpd服务器。 这是更好的性能,并允许在单个机器上有成千上万的ftp用户。 除此之外,我将使用此设置显示使用配额。 本教程基于Ubuntu 14.04LTS。

对于MySQL数据库的管理,您可以使用基于Web的工具,如phpMyAdmin,它也将安装在此howto中。 phpMyAdmin是一个舒适的图形界面,这意味着您不必乱用命令行。

这是一个实践指南; 它不包括理论背景。 他们在网络上的许多其他文档中被处理。

本文档不附带任何形式的保证! 我想说,这不是设立这样一个制度的唯一办法。 实现这一目标有很多方法,但这是我所采取的方式。 我不会保证这将为您工作!

1初步说明

在本教程中,我使用IP地址为192.168.0.100的hostname server1.example.com 。 这些设置可能会有所不同,因此您必须在适当的情况下更换它们。

确保您以root身份登录:

sudo su

1.1更改默认Shell

/ bin / sh是/ bin / dash的符号链接,但是我们需要/ bin / bash ,not / bin / dash 。 所以我们这样做:

dpkg-reconfigure dash

安装破折号为/ bin / sh? < - 不

1.2禁用AppArmor

AppArmor是一个安全扩展(类似于SELinux),应该提供扩展的安全性。 在我看来,你不需要配置一个安全的系统,它通常会导致更多的问题,而不是优势(考虑到你做了一周的故障排除后,因为一些服务不能按预期工作,然后你发现一切都很好,只有AppArmor导致了这个问题)。 所以我禁用它。

我们可以禁用它:

/etc/init.d/apparmor stop

update-rc.d -f apparmor remove

apt-get remove apparmor apparmor-utils

2安装MySQL和phpMyAdmin

这一切都可以通过一个命令安装:

apt-get install mysql-server mysql-client phpmyadmin apache2

您将被要求为MySQL root用户提供密码 - 此密码对用户root @ localhost以及root@server1.example.com有效 ,因此我们不必在以后手动指定MySQL根密码:

MySQL“root”用户的新密码: < - yourrootsqlpassword

重复MySQL“root”用户的密码: < - yourrootsqlpassword

除此之外,您将看到以下问题:

Web服务器自动重新配置: < - apache2

使用dbconfig-common配置phpmyadmin的数据库? < - 不

3使用MySQL支持安装Proftpd

对于Ubuntu,有一个预配置的proftpd-mod-mysql包可用。 将其作为独立守护进程安装,如下所示:

apt-get install proftpd-mod-mysql

您将被问到以下问题:

运行proftpd: < - standalone

然后我们创建一个ftp组( ftpgroup )和用户( ftpuser ),我们所有的虚拟用户将被映射到。 将group-and userid 2001替换为系统上免费的数字:

groupadd -g 2001 ftpgroup

useradd -u 2001 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser

4为Proftpd创建MySQL数据库

现在我们创建一个名为ftp的数据库和名为proftpd的MySQL用户,proftpd守护程序稍后将使用它来连接到ftp数据库:

mysql -u root -p

CREATE DATABASE ftp;

GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO 'proftpd'@'localhost' IDENTIFIED BY 'password';

GRANT SELECT, INSERT, UPDATE, DELETE ON ftp.* TO 'proftpd'@'localhost.localdomain' IDENTIFIED BY 'password';

FLUSH PRIVILEGES;

将字符串密码替换为要用于MySQL用户proftpd的任何密码。 仍然在MySQL shell上,我们创建了我们需要的数据库表:

USE ftp;

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)

) ENGINE=MyISAM COMMENT='ProFTP group table';

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 bigint(20) unsigned NOT NULL default '0',

bytes_out_avail bigint(20) unsigned NOT NULL default '0',

bytes_xfer_avail bigint(20) unsigned 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'

) ENGINE=MyISAM;

CREATE TABLE ftpquotatallies (

name varchar(30) NOT NULL default '',

quota_type enum('user','group','class','all') NOT NULL default 'user',

bytes_in_used bigint(20) unsigned NOT NULL default '0',

bytes_out_used bigint(20) unsigned NOT NULL default '0',

bytes_xfer_used bigint(20) unsigned 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'

) ENGINE=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:00:00',

modified datetime NOT NULL default '0000-00-00 00:00:00',

PRIMARY KEY (id),

UNIQUE KEY userid (userid)

) ENGINE=MyISAM COMMENT='ProFTP user table';

quit;

你可能已经注意到,随着戒烟; 命令我们已经离开了MySQL shell,并回到了Linux shell。

BTW,(我假设您的ftp服务器系统的主机名为server1.example.com ),您可以访问http://server1.example.com/phpmyadmin/下的phpMyAdmin (您可以使用IP地址而不是server1。 example.com ),并以proftpd身份登录。 那么你可以看看数据库。 以后可以使用phpMyAdmin管理您的Proftpd服务器。

5配置Proftpd

打开/etc/proftpd/modules.conf ...

vi /etc/proftpd/modules.conf

...并启用以下三个模块:[...]

# Install one of proftpd-mod-mysql, proftpd-mod-pgsql or any other

# SQL backend engine to use this module and the required backend.

# This module must be mandatory loaded before anyone of

# the existent SQL backeds.

LoadModule mod_sql.c

[...]

# Install proftpd-mod-mysql and decomment the previous

# mod_sql.c module to use this.

LoadModule mod_sql_mysql.c

[...]

# Install one of the previous SQL backends and decomment

# the previous mod_sql.c module to use this

LoadModule mod_quotatab_sql.c

[...]

然后打开/etc/proftpd/proftpd.conf并注释掉以下几行:

vi /etc/proftpd/proftpd.conf[...]

#

#QuotaEngine off

#

[...]

在文件中进一步向下,添加以下行:[...]

#

# Alternative authentication frameworks

#

#Include /etc/proftpd/ldap.conf

#Include /etc/proftpd/sql.conf

DefaultRoot ~

SQLBackend mysql

# The passwords in MySQL are encrypted using CRYPT

SQLAuthTypes Plaintext Crypt

SQLAuthenticate users groups

# used to connect to the database

# databasename@host database_user user_password

SQLConnectInfo ftp@localhost proftpd password

# Here we tell ProFTPd the names of the database columns in the "usertable"

# we want it to interact with. Match the names with those in the db

SQLUserInfo ftpuser userid passwd uid gid homedir shell

# Here we tell ProFTPd the names of the database columns in the "grouptable"

# we want it to interact with. Again the names match with those in the db

SQLGroupInfo ftpgroup groupname gid members

# set min UID and GID - otherwise these are 999 each

SQLMinID 500

# create a user's home directory on demand if it doesn't exist

CreateHome on

# Update count every time user logs in

SQLLog PASS updatecount

SQLNamedQuery updatecount UPDATE "count=count+1, accessed=now() WHERE userid='%u'" ftpuser

# Update modified everytime user uploads or deletes a file

SQLLog STOR,DELE modified

SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser

# User quotas

# ===========

QuotaEngine on

QuotaDirectoryTally on

QuotaDisplayUnits Mb

QuotaShowQuotas on

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-limit

QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally

RootLogin off

RequireValidShell off

[...]

确保将字符串密码替换为SQLConnectInfo行中的MySQL用户proftpd的真实密码!

然后重新启动Proftpd:

/etc/init.d/proftpd restart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值