GNU/Linux >> Znalost Linux >  >> Ubuntu

The Perfect Server - Ubuntu 16.04 (Xenial Xerus) s Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot a ISPConfig 3.1

Tento výukový program ukazuje instalaci webhostingového serveru Ubuntu 16.04 (Xenial Xerus) s Apache2, Postfix, Dovecot, Bind a PureFTPD, abyste jej připravili na instalaci ISPConfig 3.1. Výsledný systém bude poskytovat Web, Mail, Mailinglist, DNS a FTP Server.

ISPConfig 3 je webhostingový ovládací panel, který vám umožňuje konfigurovat následující služby prostřednictvím webového prohlížeče:webový server Apache nebo nginx, poštovní server Postfix, server IMAP/POP3 Courier nebo Dovecot, jmenný server MySQL, BIND nebo MyDNS, PureFTPd, SpamAssassin, ClamAV a mnoho dalších. Toto nastavení pokrývá instalaci Apache (místo Nginx), BIND (místo MyDNS) a Dovecot (místo Courier).

Upozornění: Verze ISPConfig 3.1 použitá v tomto kurzu je aktuálně ve stavu beta. Starou stabilní verzi ISPConfig 3.0.5p9 nelze použít na Ubuntu 16.04, protože není kompatibilní s PHP 7.

1. Předběžná poznámka

V tomto tutoriálu používám název hostitele server1.example.com s IP adresou 192.168.1.100 a bránou 192.168.1.1 . Tato nastavení se pro vás mohou lišit, takže je musíte v případě potřeby nahradit. Než budete pokračovat dále, musíte mít základní minimální instalaci Ubuntu 16.04, jak je vysvětleno v návodu.

2. Upravte /etc/apt/sources.list a aktualizujte svou instalaci Linuxu

Upravte /etc/apt/sources.list. Zakomentujte nebo odeberte instalační CD ze souboru a ujistěte se, že jsou povolena úložiště vesmíru a multiverse. Poté by to mělo vypadat takto:

nano /etc/apt/sources.list
#

# deb cdrom:[Ubuntu-Server 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420)]/ xenial main restricted

#deb cdrom:[Ubuntu-Server 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420)]/ xenial main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://de.archive.ubuntu.com/ubuntu/ xenial main restricted
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://de.archive.ubuntu.com/ubuntu/ xenial universe
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial universe
deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates universe
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://de.archive.ubuntu.com/ubuntu/ xenial multiverse
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://de.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu xenial partner
# deb-src http://archive.canonical.com/ubuntu xenial partner

deb http://security.ubuntu.com/ubuntu xenial-security main restricted
# deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

Potom spusťte

apt-get update

pro aktualizaci databáze balíčků apt a

apt-get upgrade

k instalaci nejnovějších aktualizací (pokud nějaké existují). Pokud uvidíte, že se v rámci aktualizací nainstaluje nové jádro, měli byste poté restartovat systém:

reboot

3. Změňte výchozí prostředí

/bin/sh je symbolický odkaz na /bin/dash, ale potřebujeme /bin/bash, ne /bin/dash. Proto uděláme toto:

dpkg-reconfigure dash

Použít pomlčku jako výchozí systémové prostředí (/bin/sh)? <-- Ne

Pokud to neuděláte, instalace ISPConfig se nezdaří.

4. Zakázat AppArmor

AppArmor je bezpečnostní rozšíření (podobně jako SELinux), které by mělo poskytovat rozšířené zabezpečení. Podle mého názoru to ke konfiguraci zabezpečeného systému nepotřebujete a obvykle to způsobí více problémů než výhod (přemýšlejte o tom až po týdnu odstraňování problémů, protože některá služba nefungovala podle očekávání, a pak zjistíte, že vše bylo v pořádku, problém způsoboval pouze AppArmor). Proto jsem to zakázal (to je nutnost, pokud chcete ISPConfig nainstalovat později).

Můžeme to zakázat takto:

service apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils

5. Synchronizujte systémové hodiny

Je vhodné synchronizovat systémové hodiny s NTP (n síť t ime p rotocol) server přes internet, když provozujete fyzický server. V případě, že provozujete virtuální server, měli byste tento krok přeskočit. Stačí spustit

apt-get -y install ntp ntpdate

a váš systémový čas bude vždy synchronizován.

6. Nainstalujte Postfix, Dovecot, MariaDB, rkhunter a binutils

Pro instalaci postfixu se musíme ujistit, že sendmail není nainstalován a spuštěn. Chcete-li zastavit a odstranit sendmail, spusťte tento příkaz:

service sendmail stop; update-rc.d -f sendmail remove

Chybová zpráva:

Failed to stop sendmail.service: Unit sendmail.service not loaded.

Je v pořádku, jen to znamená, že sendmail nebyl nainstalován, takže nebylo co odstraňovat.

Nyní můžeme nainstalovat Postfix, Dovecot, MariaDB (jako náhradu MySQL), rkhunter a binutils jediným příkazem:

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

Budou vám položeny následující otázky:

General type of mail configuration: <-- Internet Site
System mail name: <-- server1.example.com

Je důležité, abyste jako „systémový název pošty“ použili subdoménu, např. server1.example.com nebo server1.vasedomena.com, a nikoli doménu, kterou chcete později použít jako e-mailovou doménu (např. vasedomena.tld).

Dále otevřete TLS/SSL a porty pro odesílání v Postfixu:

nano /etc/postfix/master.cf

Odkomentujte sekce odeslání a smtps následovně - přidejte řádek -o smtpd_client_restrictions=permit_sasl_authenticated, odmítněte obě sekce a ponechte vše komentované:

[...]
submission inet n       -       -       -       -       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 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=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
smtps     inet  n       -       -       -       -       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 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=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
[...]

POZNÁMKA:Mezery před řádky "-o .... " jsou důležité!

Poté restartujte Postfix:

service postfix restart

Chceme, aby MySQL naslouchalo na všech rozhraních, nejen na localhost. Proto upravíme /etc/mysql/mariadb.conf.d/50-server.cnf a zakomentujeme řádek bind-address =127.0.0.1:

nano /etc/mysql/mariadb.conf.d/50-server.cnf
[...]
# 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
[...]

Nyní nastavíme heslo root v MariaDB. Spustit:

mysql_secure_installation

Budou vám položeny tyto otázky:

Enter current password for root (enter for none): <-- press enter
Set root password? [Y/n] <-- y
New password: <-- Enter the new MariaDB root password here
Re-enter new password: <-- Repeat the password
Remove anonymous users? [Y/n] <-- y
Disallow root login remotely? [Y/n] <-- y
Reload privilege tables now? [Y/n] <-- y

Poté restartujeme MariaDB:

service mysql restart

Nyní zkontrolujte, zda je síť povolena. Spustit

netstat -tap | grep mysql

Výstup by měl vypadat takto:

[email protected]:~# netstat -tap | grep mysql
tcp6 0 0 [::]:mysql [::]:* LISTEN 5230/mysqld
[email protected]:~# 

7. Nainstalujte Amavisd-new, SpamAssassin a Clamav

Chcete-li nainstalovat amavisd-new, SpamAssassin a ClamAV, spustíme

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 postgrey

Nastavení ISPConfig 3 používá amavisd, který interně načítá knihovnu filtrů SpamAssassin, takže můžeme zastavit SpamAssassin, abychom uvolnili RAM:

service spamassassin stop 
update-rc.d -f spamassassin remove

Upravte konfigurační soubor clamd:

nano /etc/clamav/clamd.conf

a změňte řádek:

AllowSupplementaryGroups false

komu:

AllowSupplementaryGroups true 

A uložte soubor. Pro spuštění ClamAV použijte:

freshclam
service clamav-daemon start

Následující varování lze ignorovat při prvním spuštění freshclam, když spustíme ClamAV sakra poté, co jsme aktualizovali databázi.

WARNING: Clamd was NOT notified: Can't connect to clamd through /var/run/clamav/clamd.ctl: No such file or directory 

7.1 Instalace Metronome XMPP Server (volitelné)

Metronome XMPP Server poskytuje chatovací server XMPP. Tento krok je volitelný, pokud nepotřebujete chatovací server, můžete tento krok přeskočit. Na tomto softwaru nezávisí žádné další funkce ISPConfig.

Nainstalujte následující balíčky pomocí apt.

apt-get install git lua5.1 liblua5.1-0-dev lua-filesystem libidn11-dev libssl-dev lua-zlib lua-expat lua-event lua-bitop lua-socket lua-sec luarocks luarocks
luarocks install lpc

Přidejte uživatele prostředí pro Metronome.

adduser --no-create-home --disabled-login --gecos 'Metronome' metronome

Stáhněte si Metronome do adresáře /opt a zkompilujte jej.

cd /opt; git clone https://github.com/maranda/metronome.git metronome
cd ./metronome; ./configure --ostype=debian --prefix=/usr
make
make install

Metronome je nyní nainstalován do /opt/metronome.


Ubuntu
  1. The Perfect Server - Ubuntu 16.10 (Yakkety Yak) s Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot a ISPConfig 3.1

  2. The Perfect Server - Ubuntu 17.04 (Zesty Zapus) s Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot a ISPConfig 3.1

  3. The Perfect Server - Ubuntu 17.10 (Artful Aardvark) s Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot a ISPConfig 3.1

  1. The Perfect Server – Ubuntu 15.04 (Vivid Vervet) s Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot a ISPConfig 3

  2. The Perfect Server – Ubuntu 15.04 (nginx, BIND, Dovecot a ISPConfig 3)

  3. The Perfect Server – Ubuntu 15.10 (nginx, MySQL, PHP, Postfix, BIND, Dovecot, Pure-FTPD a ISPConfig 3)

  1. The Perfect Server - Ubuntu 15.10 (Wily Werewolf) s Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot a ISPConfig 3

  2. The Perfect Server – Ubuntu 16.04 (Nginx, MySQL, PHP, Postfix, BIND, Dovecot, Pure-FTPD a ISPConfig 3.1)

  3. The Perfect Server - Ubuntu 18.04 (Bionic Beaver) s Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot a ISPConfig 3.1