GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Hosting virtuale con Proftpd e MySQL (quota inclusa) su Ubuntu 14.04LTS

Questo documento descrive come installare un server Proftpd che utilizza utenti virtuali da un database MySQL invece di utenti del sistema reale. Questo è molto più performante e permette di avere migliaia di utenti ftp su una singola macchina. In aggiunta a ciò mostrerò l'uso della quota con questa configurazione. Questo tutorial è basato su Ubuntu 14.04LTS.

Per l'amministrazione del database MySQL è possibile utilizzare strumenti web based come phpMyAdmin che verranno installati anche in questo howto. phpMyAdmin è una comoda interfaccia grafica che significa che non devi scherzare con la riga di comando.

Questo howto vuole essere una guida pratica; non copre le basi teoriche. Sono trattati in molti altri documenti nel Web.

Questo documento viene fornito senza garanzie di alcun tipo! Voglio dire che questo non è l'unico modo per creare un sistema del genere. Ci sono molti modi per raggiungere questo obiettivo, ma questo è il modo in cui prendo. Non garantisco che questo funzionerà per te!

1 Nota preliminare

In questo tutorial utilizzo l'hostname server1.example.com con l'indirizzo IP 192.168.0.100. Queste impostazioni potrebbero differire per te, quindi devi sostituirle dove appropriato.

Assicurati di aver effettuato l'accesso come root:

sudo su

1.1 Modifica della shell predefinita

/bin/sh è un collegamento simbolico a /bin/dash, tuttavia abbiamo bisogno di /bin/bash, non di /bin/dash. Pertanto facciamo questo:

trattino di riconfigurazione dpkg

Installa il trattino come /bin/sh? <-- No

1.2 Disattiva AppArmor

AppArmor è un'estensione di sicurezza (simile a SELinux) che dovrebbe fornire una sicurezza estesa. Secondo me non è necessario per configurare un sistema sicuro e di solito causa più problemi che vantaggi (pensaci dopo aver fatto una settimana di risoluzione dei problemi perché alcuni servizi non funzionavano come previsto, e quindi scopri che era tutto ok, solo AppArmor stava causando il problema). Pertanto lo disabilito.

Possiamo disabilitarlo in questo modo:

/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils

2 Installa MySQL e phpMyAdmin

Tutto questo può essere installato con un solo comando:

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

Ti verrà chiesto di fornire una password per l'utente root di MySQL:questa password è valida per l'utente [protetto tramite posta elettronica] e [protetto tramite posta elettronica], quindi non è necessario specificare manualmente una password di root MySQL in seguito:

Nuova password per l'utente "root" di MySQL:<-- yourrootsqlpassword
Ripeti la password per l'utente "root" di MySQL:<-- yourrootsqlpassword

Oltre a questo, vedrai le seguenti domande:

Server Web da riconfigurare automaticamente:<-- apache2
Configura il database per phpmyadmin con dbconfig-common? <-- No

3 Installa Proftpd con il supporto MySQL

Per Ubuntu è disponibile un pacchetto proftpd-mod-mysql preconfigurato. Installalo come demone autonomo in questo modo:

apt-get install proftpd-mod-mysql

Ti verrà posta la seguente domanda:

Esegui proftpd:<-- autonomo

Quindi creiamo un gruppo ftp (ftpgroup) e un utente (ftpuser) a cui verranno mappati tutti i nostri utenti virtuali. Sostituisci il gruppo e l'ID utente 2001 con un numero gratuito sul tuo sistema:

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

4 Creare il database MySQL per Proftpd

Ora creiamo un database chiamato ftp e un utente MySQL chiamato proftpd che il demone proftpd utilizzerà in seguito per connettersi al database ftp:

mysql -u root -p

CREATE DATABASE ftp;
GRANT SELECT, INSERT, UPDATE, DELETE SU ftp.* A 'proftpd'@'localhost' IDENTIFICATO DA 'password';
GRANT SELECT, INSERT, UPDATE, DELETE SU ftp.* A 'proftpd'@'localhost.localdomain' IDENTIFICATO DA 'password';
PRIVILEGI FLUSH;

Sostituisci la stringa password con la password che desideri utilizzare per l'utente MySQL proftpd. Sempre sulla shell MySQL, creiamo le tabelle del database di cui abbiamo bisogno:

USA 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='Tabella di gruppo ProFTP';

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) non firmato NOT NULL predefinito '0',
bytes_out_avail bigint(20) unsigned NOT NULL predefinito '0',
bytes_xfer_avail bigint(20) unsigned NOT NULL predefinito '0',
files_in_avail int(10) unsigned NOT NULL predefinito '0',
files_out_avail int(10) unsigned NOT NULL predefinito '0',
files_xfer_avail int(10) unsigned NOT NULL predefinito '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 predefinito '0',
bytes_out_used bigint(20) unsigned NOT NULL predefinito '0',
bytes_xfer_used bigint(20) unsigned NOT NULL predefinito '0',
files_in_used int(10) unsigned NOT NULL predefinito '0',
files_out_used int(10) unsigned NOT NULL predefinito '0',
files_xfer_used int(10) unsigned NOT NULL predefinito '0'
) MOTORE=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 predefinito '5500',
gid smallint(6) NOT NULL predefinito '5500',
homedir varchar(255) NOT NULL predefinito '',
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 ',
data/ora modificata NOT NULL default '0000-00-00 00:00:00',
CHIAVE PRIMARIA (id),
CHIAVE UNICA userid (id utente)
) MOTORE =MyISAM COMMENT='Tabella utente ProFTP';

esci;

Come avrai notato, con l'abbandono; comando abbiamo lasciato la shell MySQL e siamo tornati sulla shell Linux.

A proposito, (suppongo che il nome host del tuo sistema server ftp sia server1.example.com) puoi accedere a phpMyAdmin sotto http://server1.example.com/phpmyadmin/ (puoi usare l'indirizzo IP invece di server1. example.com) in un browser e accedi come proftpd. Quindi puoi dare un'occhiata al database. Successivamente potrai utilizzare phpMyAdmin per gestire il tuo server Proftpd.

5 Configura Proftpd

Apri /etc/proftpd/modules.conf...

vi /etc/proftpd/modules.conf

... e abilita i seguenti tre moduli:

[...]
# 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 [...]

Quindi apri /etc/proftpd/proftpd.conf e commenta le seguenti righe:

vi /etc/proftpd/proftpd.conf

[...]
#<IfModule mod_quotatab.c>
#QuotaEngine off
#</IfModule>
[...]

Più in basso nel file, aggiungi le seguenti righe:

[...]
#
# 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
# [email protected] database_user user_password
SQLConnectInfo  [email protected] 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
[...]

Assicurati di sostituire la stringa password con la password reale per l'utente MySQL proftpd nella riga SQLConnectInfo!

Quindi riavvia Proftpd:

/etc/init.d/proftpd riavvia


Ubuntu
  1. Utenti virtuali e domini con Postfix, Courier, MySQL e SquirrelMail (Ubuntu 14.04LTS)

  2. Installazione di Lighttpd con PHP5 (PHP-FPM) e supporto MySQL su Ubuntu 14.04LTS

  3. Utenti e domini virtuali con Postfix, Courier, MySQL e SquirrelMail (Ubuntu 13.10)

  4. Hosting virtuale con PureFTPd e MySQL (incl. Gestione di quote e larghezza di banda) su CentOS 7.0

  5. Hosting virtuale con PureFTPd e MySQL (incl. Gestione della quota e della larghezza di banda) su Ubuntu 7.10 (Gutsy Gibbon)

Utenti e domini virtuali con Postfix, Courier, MySQL e SquirrelMail (Ubuntu 12.10)

Hosting virtuale con vsftpd e MySQL su Ubuntu 12.10

Hosting virtuale con PureFTPd e MySQL (incl. Quota e gestione della larghezza di banda) su Ubuntu 12.10

Hosting virtuale con Proftpd e MySQL (quota inclusa) su Ubuntu 12.10

Hosting virtuale con PureFTPd e MySQL (incl. quota e gestione della larghezza di banda) su Ubuntu 14.04LTS

Hosting virtuale con Proftpd e MySQL (quota inclusa) su Debian Lenny