Debian

Créer un serveur web, mail et DNS avec ISPConfig 3.1 sur Debian 9 (Stretch)

par | 24 Sep. 2017 | Debian, Linux

Objectif

Personnellement j’ai toujours eu un « serveur » à la maison, pour stocker des fichiers sur mon réseau, pour faire des tests, juste pour avoir une machine qui tourne sans utilité ou dans le cas présent de rédiger cet article.

Nous allons partir d’une installation minimale de Debian 9 (une machine virtuelle sous ProxMox 5 dans mon cas) et mettre en place un serveur complet pour héberger vos sites, bases de données, mail et DNS. Pour ça, nous allons utiliser Apache, MariaDB, Dovecot, BIND, PureFTPD et d’autres.

Prérequis

  • Un serveur sous Debian 9 (Stretch)
  • Un accès SSH avec les droits « root »

C’est parti !

Alors, nous allons commencer par mettre à jour notre système.
apt-get update && apt-get upgrade
Maintenant, on édite le fichier /etc/hosts
nano /etc/hosts
Configurer comme suit : (remplacer « srv88 » par le nom de votre serveur, « miloose.test » par votre nom de domaine et « 10.10.10.150 » par l’IP de votre serveur)
127.0.0.1       localhost.localadmin localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
# --- BEGIN PVE ---
10.10.10.150 srv88.miloose.test srv88
# --- END PVE ---
Votre fichier de configuration ne doit pas être identique au mien et comme le dit si bien « Perceval » : L’important, c’est les valeurs !

On redémarre le serveur pour que les modifications soient prise en compte.

reboot
On vérifie que tout est bien configuré avec les commandes « hostname » & « hostname -f ». Le résultat doit ressembler à ça (avec vos propre valeur).
root@srv88:/home/miloose# hostname
srv88
root@srv88:/home/miloose# hostname -f
srv88.miloose.test
Editer le fichier /etc/apt/souces.list
nano /etc/apt/sources.list
Ajouter ces lignes à la fin du fichier.
deb http://ftp.fr.debian.org/debian/ stretch main contrib non-free
deb-src http://ftp.fr.debian.org/debian/ stretch main contrib non-free

deb http://security.debian.org/debian-security stretch/updates main contrib non-free
deb-src http://security.debian.org/debian-security stretch/updates main contrib non-free
On met à jour tout ça !
apt-get update && apt-get upgrade
Il faut changer le shell par défaut du système, sans cette modification l’installation d’ISPConfig échouera.
dpkg-reconfigure dash
Répondre « Non ».
Pour toujours avoir notre serveur à la bonne date et la bonne heure, on va installer ntp.
apt-get install ntp
Nous pouvons maintenant installer Postfix, MariaDB, Dovecot, rkhunter et Binutils.
apt-get install postfix postfix-mysql postfix-doc mariadb-client mariadb-server openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d dovecot-mysql dovecot-sieve dovecot-lmtpd sudo
Lorsqu’il vous le sera demandé, répondre Site internet et indiquer le nom complet de votre serveur.
Afin de sécuriser un peu plus notre installation de MariaDB, lancer la commande suivante :
mysql_secure_installation
Laisser vide lorsque le mot de passe root actuel est demandé puis il faut répondre oui à toutes les questions.
Il faut ouvrir les ports TLS/SSL et submission dans Postfix en éditant le fichier /etc/postfix/master.cf
nano /etc/postfix/master.cf
Dé-commenter submission et smtps puis ajouter quelques lignes nécessaires. Cette partie du fichier devrait ressembler à ceci :
[...]
submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o syslog_name=postfix/smtps
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
[...]
Redémarrer Postfix.
service postfix restart
Nous allons faire ne sorte que MySQL écoute sur toutes les interfaces et pas seulement localhost en éditant le fichier /etc/mysql/mariadb.conf.d/50-server.cnf
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Commenter la ligne bind-address = 127.0.0.1 et ajouter sql-mode= »NO_ENGINE_SUBSTITUTION ». Cela devrait ressembler à ça :
[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1

sql-mode="NO_ENGINE_SUBSTITUTION"

[...]
Configurer la méthode d’authentification par mot de passe en native dans MariaDB afin de pouvoir se connecter en root sur PHPMyAdmin en tapant cette commande :
echo "update mysql.user set plugin = 'mysql_native_password' where user='root';" | mysql -u root
Editer le fichier /etc/mysql/debian.cnf
nano /etc/mysql/debian.cnf
Entrer le mot de passe root MySQL sur les deux lignes commençant par « password =  » comme suit :(remplacer sqlrootpasswd par votre mot de passe défini précédemment)
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = root
password = sqlrootpasswd
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = root
password = sqlrootpasswd
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr
Redémarrer MySQL.
service mysql restart
Vérifier que MySQL est bien à l’écoute avec la commande suivante :
netstat -tap | grep mysql
Vous devriez avoir un résultat similaire à ceci :
root@srv88:/home/miloose# netstat -tap | grep mysql
tcp6       0      0 [::]:mysql              [::]:*                  LISTEN      13074/mysqld
Maintenant, installer SpamAssassin et ClamAV ainsi que quelques autres paquets utiles avec la commande suivante :
apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perl libdbd-mysql-perl postgrey
L’installation d’ISPConfig utilise amavisd qui charge la bibliothèque de filtres de SpamAssassin en interne, nous pouvons donc stopper SpamAssassin et libérer un peu de RAM.
service spamassassin stop
systemctl disable spamassassin
Installer Apache2, PHP, FCGI, suExec, PHPMyAdmin, mcrypt et Pear.
apt-get install apache2 apache2-doc apache2-utils libapache2-mod-php php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-imap phpmyadmin php7.0-cli php7.0-cgi libapache2-mod-fcgid apache2-suexec-pristine php-pear php7.0-mcrypt mcrypt  imagemagick libruby libapache2-mod-python php7.0-curl php7.0-intl php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl memcached php-memcache php-imagick php-gettext php7.0-zip php7.0-mbstring memcached libapache2-mod-passenger php7.0-soap
Lorsqu’il vous le sera demandé, cocher « apache2 » et « OK » puis répondre « Oui » pour la configuration de la base de données de PHPMyAdmin avec dbconfig-common et laisser le champ vide lorsque le mot de passe vous est demandé.
Activer les modules Apache nécessaires. (si vous souhaitez utiliser WebDAV, ajouter dav dav_fs auth_digest)
a2enmod suexec rewrite ssl actions include dav_fs dav auth_digest cgi headers
Pour nous assurer que notre serveur ne se fasse pas attaquer par la vulnérabilité HTTPOXY, nous allons désactiver l’en-tête HTTP_PROXY dans Apache en créant le fichier /etc/apache2/conf-available/httpoxy.conf
nano /etc/apache2/conf-available/httpoxy.conf
Copier les lignes suivantes dans le fichier.
<IfModule mod_headers.c>
    RequestHeader unset Proxy early
</IfModule>
Activer ce nouveau module.
a2enconf httpoxy
Redémarrer Apache pour que tout soit pris en compte.
service apache2 restart
Installer certbot, cela vous permettra de générer des certificats SSL gratuit par le biais de Let’s Encrypt pour vos sites web directement dans ISPConfig.
apt-get install certbot
Installer PHP 7.0 FPM.
apt-get install php7.0-fpm
Activer les modules Apache.
a2enmod actions proxy_fcgi alias 
Redémarrer Apache.
service apache2 restart
Installer PHP Opcode Cache.
apt-get install php7.0-opcache php-apcu
Redémarrer Apache.
service apache2 restart
Installer Mailman.
apt-get install mailman
Choisir votre langue et « OK » puis encore une fois « OK ».
Avant de lancer Mailman, nous devons créer une première liste de diffusion appelé mailman.
newlist mailman
Indiquer une adresse mail pour l’administrateur (listadmin@miloose.test dans cet exemple) puis un mot de passe administrateur.
root@srv88:/home/miloose# newlist mailman
Entrez l'adresse courriel du gestionnaire de la liste : listadmin@miloose.xyz
Mot de passe initial de la liste mailman :
Pour achever la création de votre liste de diffusion, vous devez
modifier votre fichier /etc/aliases (ou équivalent) en y ajoutant les
lignes suivantes et peut être exécuter le programme `newaliases':

liste de diffusion ## mailman
mailman:              "|/var/lib/mailman/mail/mailman post mailman"
mailman-admin:        "|/var/lib/mailman/mail/mailman admin mailman"
mailman-bounces:      "|/var/lib/mailman/mail/mailman bounces mailman"
mailman-confirm:      "|/var/lib/mailman/mail/mailman confirm mailman"
mailman-join:         "|/var/lib/mailman/mail/mailman join mailman"
mailman-leave:        "|/var/lib/mailman/mail/mailman leave mailman"
mailman-owner:        "|/var/lib/mailman/mail/mailman owner mailman"
mailman-request:      "|/var/lib/mailman/mail/mailman request mailman"
mailman-subscribe:    "|/var/lib/mailman/mail/mailman subscribe mailman"
mailman-unsubscribe:  "|/var/lib/mailman/mail/mailman unsubscribe mailman"

Tapez sur Entrée pour aviser le propriétaire de mailman...
Editer le fichier /etc/aliases
nano /etc/aliases
Ajouter les lignes suivantes à la fin du fichier :
## mailman mailing list
mailman:              "|/var/lib/mailman/mail/mailman post mailman"
mailman-admin:        "|/var/lib/mailman/mail/mailman admin mailman"
mailman-bounces:      "|/var/lib/mailman/mail/mailman bounces mailman"
mailman-confirm:      "|/var/lib/mailman/mail/mailman confirm mailman"
mailman-join:         "|/var/lib/mailman/mail/mailman join mailman"
mailman-leave:        "|/var/lib/mailman/mail/mailman leave mailman"
mailman-owner:        "|/var/lib/mailman/mail/mailman owner mailman"
mailman-request:      "|/var/lib/mailman/mail/mailman request mailman"
mailman-subscribe:    "|/var/lib/mailman/mail/mailman subscribe mailman"
mailman-unsubscribe:  "|/var/lib/mailman/mail/mailman unsubscribe mailman"
Actualiser les allias.
newaliases
Redémarrer Postfix.
service postfix restart
Ajouter la configuration de Mailman dans Apache.
ln -s /etc/mailman/apache.conf /etc/apache2/conf-enabled/mailman.conf
Ceci activera l’allias /cgi-bin/mailman/ pour tous les vhosts d’Apache. Vous aurez accès à l’interface d’administration de Mailman pour une liste et à une page web pour les utilisateurs d’une liste de diffusion aux adresses suivantes : (remplacer « srv88.miloose.test » par le nom complet de votre serveur)
http://srv88.miloose.test/cgi-bin/mailman/admin/

http://srv88.miloose.test/cgi-bin/mailman/listinfo/
Redémarrer Apache.
service apache2 restart
Démarrer le daemon Mailman.
service mailman start
Installer PureFTPd et Quota.
apt-get install pure-ftpd-common pure-ftpd-mysql quota quotatool
Editer le fichier /etc/default/pure-ftpd-common
nano /etc/default/pure-ftpd-common
Mettre les valeurs STANDALONE_OR_INETD et VIRTUALCHROOT comme suit :
[...]
STANDALONE_OR_INETD=standalone
[...]
VIRTUALCHROOT=true
[...]
Autoriser les sessions FTP et TLS.
echo 1 > /etc/pure-ftpd/conf/TLS
Pour utiliser TLS, nous devons créer une certificat SSL. Nous allons créer le répertoire qui va accueillir ce certificat.
mkdir -p /etc/ssl/private/
Maintenant on peut générer notre certificat.
openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem
Remplir les informations demandées pour le création du certificat. (adapter les informations à votre configuration)
Country Name (2 letter code) [AU]:FR
State or Province Name (full name) [Some-State]:France
Locality Name (eg, city) []:Nice
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Miloose Corp.
Organizational Unit Name (eg, section) []:Web Services
Common Name (e.g. server FQDN or YOUR name) []:srv88.miloose.test
Email Address []:admin@miloose.test
Changer les permissions du certificat.
chmod 600 /etc/ssl/private/pure-ftpd.pem
Redémarrer PureFTPd.
service pure-ftpd-mysql restart
Editer le fichier /etc/fstab
nano /etc/fstab
Ajouter ,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0 à la ligne correspondant à la partition avec le point de montage « / » comme ci-dessous :
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=f5fe1fc3-41e4-4557-a101-104e32a7e2b4 /               ext4    errors=remount-ro,usrjquota=quota.user,grpjquota=quota.group,jqfmt=vfsv0 0       1
# swap was on /dev/sda3 during installation
UUID=de1fa94d-5e13-4dc4-81f1-bc4159793d93 none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0
Activer Quota.
mount -o remount /
quotacheck -avugm
quotaon -avug

Dans mon cas (sur un CT sous Proxmox) il n’est pas possible de modifier le fichier /etc/fstab car il est géré par l’hôte. Lors de mon test sur un VPS prit pour faire un test, cela fonctionnait parfaitement.

J’avais aussi rencontré une erreur lors de l’activation de Quota mais je ne me souviens plus à laquelle des trois commande ci-dessus. Il suffit de relancer la commande qui a fait une erreur et cela fonctionne.

Installer BIND.
apt-get install bind9 dnsutils
Si comme moi votre serveur est une machine virtuelle, il est conseillé d’installer le daemon amélioré et avoir une meilleur entropie pour la signature DNSSEC. Vous pouvez l’installer sur un serveur non virtuel, cela ne devrait pas poser de problème.
apt-get install haveged
Installer Webalizer et AWStats.
apt-get install webalizer awstats geoip-database libclass-dbi-mysql-perl libtimedate-perl
Editer le fichier /etc/cron.d/awstats
nano /etc/cron.d/awstats
Commenter toutes les lignes.
#MAILTO=root

#*/10 * * * * www-data [ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/update.sh

# Generate static reports:
#10 03 * * * www-data [ -x /usr/share/awstats/tools/buildstatic.sh ] && /usr/share/awstats/tools/buildstatic.$
Installer Jailkit.
apt-get install build-essential autoconf automake libtool flex bison debhelper binutils

cd /tmp
wget http://olivier.sessink.nl/jailkit/jailkit-2.19.tar.gz
tar xvfz jailkit-2.19.tar.gz
cd jailkit-2.19
echo 5 > debian/compat
./debian/rules binary
Nous pouvons maintenant installer le package .deb de Jailkit.
cd ..
dpkg -i jailkit_2.19-1_*.deb
rm -rf jailkit-2.19*

Jailkit doit être installer avant l’installation d’ISPConfig.

Installer fail2ban.
apt-get install fail2ban
Créer le fichier /etc/fail2ban/jail.local
nano /etc/fail2ban/jail.local
Ajouter les lignes suivantes pour que fail2ban surveille PureFTPd et Dovecot.
[pure-ftpd]
enabled = true
port = ftp
filter = pure-ftpd
logpath = /var/log/syslog
maxretry = 3

[dovecot]
enabled = true
filter = dovecot
logpath = /var/log/mail.log
maxretry = 5

[postfix-sasl]
enabled = true
port = smtp
filter = postfix-sasl
logpath = /var/log/mail.log
maxretry = 3
Redémarrer fail2ban.
service fail2ban restart
Installer UFW firewall.
apt-get install ufw
Installer RoundCube WebMail.
apt-get install roundcube roundcube-core roundcube-mysql roundcube-plugins
Répondre « Oui » pour la configuration de la base de données de RoundCube avec dbconfig-common et laisser le champ vide pour le mot de passe de connexion MySQL pour RoundCube.
Editer le fichier /etc/roundcube/config.inc.php
nano /etc/roundcube/config.inc.php
Modifier la configuration comme suit :
[...]
$config['default_host'] = 'localhost';
[...]
$config['smtp_server'] = 'localhost';
[...]
Editer le fichier /etc/apache2/conf-enabled/roundcube.conf
nano /etc/apache2/conf-enabled/roundcube.conf
Ajouter l’allias suivant en début de fichier.
Alias /webmail /var/lib/roundcube

N’utiliser pas l’allias /mail sinon le module email d’ISPConfig ne fonctionnera plus !

Recharger Apache.
service apache2 reload
Vous pouvez maintenant accéder à votre webmail à l’adresse suivante : (modifier par le nom complet de votre serveur)
http://srv88.miloose.test/webmail
Télécharger et décompresser la dernière version d’ISPConfig (actuellement la version 3.1.6
cd /tmp
wget https://downloads.sourceforge.net/project/ispconfig/ISPConfig%203/ISPConfig-3.1.6/ISPConfig-3.1.6.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fispconfig%2Ffiles%2Flatest%2Fdownload&ts=1506220006&use_mirror=10gbps-io
tar xfz ISPConfig-3.1.6.tar.gz
cd ispconfig3_install/install/
Lancer l’installation d’ISPConfig.
php -q install.php
Procéder à l’installation comme suit : (appuyer juste sur la touche « Entrée » pour les champs laissés vides)

--------------------------------------------------------------------------------
 _____ ___________   _____              __ _         ____
|_   _/  ___| ___ \ /  __ \            / _(_)       /__  \
  | | \ `--.| |_/ / | /  \/ ___  _ __ | |_ _  __ _    _/ /
  | |  `--. \  __/  | |    / _ \| '_ \|  _| |/ _` |  |_ |
 _| |_/\__/ / |     | \__/\ (_) | | | | | | | (_| | ___\ \
 \___/\____/\_|      \____/\___/|_| |_|_| |_|\__, | \____/
                                              __/ |
                                             |___/
--------------------------------------------------------------------------------


>> Initial configuration

Operating System: Debian 9.0 (Stretch) or compatible

    Following will be a few questions for primary configuration so be careful.
    Default values are in [brackets] and can be accepted with <ENTER>.
    Tap in "quit" (without the quotes) to stop the installer.


Select language (en,de) [en]:

Installation mode (standard,expert) [standard]:

Full qualified hostname (FQDN) of the server, eg server1.domain.tld  [srv88.miloose.test]:

MySQL server hostname [localhost]:

MySQL server port [3306]:

MySQL root username [root]:

MySQL root password []: sqlrootpasswd

MySQL database to create [dbispconfig]:

MySQL charset [utf8]:

Configuring Postgrey
Configuring Postfix
Generating a 4096 bit RSA private key
..................................................++
.............................................................................++
writing new private key to 'smtpd.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:FR
State or Province Name (full name) [Some-State]:France
Locality Name (eg, city) []:Nice
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Miloose Corp.
Organizational Unit Name (eg, section) []:Web Services
Common Name (e.g. server FQDN or YOUR name) []:srv88.miloose.test
Email Address []:admin@miloose.test
Configuring Mailman
Configuring Dovecot
Configuring Spamassassin
Configuring Amavisd
Configuring Getmail
Configuring Jailkit
Configuring Pureftpd
Configuring BIND
Configuring Apache
Configuring vlogger
[INFO] service OpenVZ not detected
Configuring Ubuntu Firewall
[INFO] service Metronome XMPP Server not detected
Configuring Fail2ban
Configuring Apps vhost
Installing ISPConfig
ISPConfig Port [8080]:

Admin password [admin]: adminpasswd

Re-enter admin password []: adminpasswd

Do you want a secure (SSL) connection to the ISPConfig web interface (y,n) [y]:

Generating RSA private key, 4096 bit long modulus
....++
....++
e is 65537 (0x010001)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:FR
State or Province Name (full name) [Some-State]:France
Locality Name (eg, city) []:Nice
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Miloose Corp.
Organizational Unit Name (eg, section) []:Web Services
Common Name (e.g. server FQDN or YOUR name) []:srv88.miloose.test
Email Address []:admin@miloose.test

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:Miloose Corp.
writing RSA key
_

Configuring DBServer
Installing ISPConfig crontab
Installing ISPConfig crontab
no crontab for root
no crontab for getmail
Detect IP addresses
Restarting services ...
Installation completed.
Vous pouvez maintenant accéder à l’interface web d’ISPConfig à l’adresse : (changer « srv88.miloose.test » par le nom complet de votre serveur)
https://srv88.miloose.test:8080
Connectez-vous avec l’utilisateur « admin » et le mot de passe défini lors de l’installation d’ISPConfig, dans le cas de cette article « adminpasswd ».
Je vous laisse vous débrouiller pour la configuration de votre ISPConfig.
Share This
%d blogueurs aiment cette page :