完美的服务器——Ubuntu 15.10(nginx、MySQL、PHP、Postfix、BIND、Dovecot、Pure-FTPD 和 ISPConfig 3)
本教程展示了使用 Nginx、PHP、MariaDB、Postfix、pure-ftpd、BIND、Dovecot 和 ISPConfig 3 安装 Ubuntu 15.10 (Wiley Werewolf) 服务器的步骤。ISPConfig 3 是一个网络托管控制面板,允许您配置已安装的通过网络浏览器的服务。此设置提供了一个完整的托管服务器,包括 Web、电子邮件(包括垃圾邮件和防病毒过滤器)、数据库、FTP 和 DNS 服务。
1. 初步说明
在本教程中,我将使用 IP 地址为 192.168.1.100 的主机名 server1.example.com 和网关 192.168.1.1 进行网络配置。这些设置可能因您而异,因此您必须在适当的地方替换它们。在继续之前,您需要按照教程中的说明对 Ubuntu 15.10 进行基本的最小安装。
本教程中的步骤必须以 root 用户身份执行,因此我不会在命令前添加 \sudo\。在继续或运行之前以 root 用户身份登录到您的服务器:
sudo su
当您在 shell 上以不同用户身份登录时成为 root 用户。
编辑文件的命令将使用编辑器 \nano\,您可以将其替换为您选择的编辑器。 Nano 是一个易于使用的 shell 文件编辑器。如果你喜欢使用 nano 并且还没有安装它,运行:
apt-get install nano
2. 更新您的 Linux 安装
编辑 /etc/apt/sources.list。从文件中注释掉或删除安装 CD,并确保启用了 universe 和 multiverse 存储库。它应该是这样的:
nano /etc/apt/sources.list
#
# deb cdrom:[Ubuntu-Server 15.10 _Wily Werewolf_ - Release amd64 (20151021)]/ wily main restricted
#deb cdrom:[Ubuntu-Server 15.10 _Wily Werewolf_ - Release amd64 (20151021)]/ wily 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/ wily main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ wily main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://de.archive.ubuntu.com/ubuntu/ wily-updates main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ wily-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. 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/ wily universe
deb-src http://de.archive.ubuntu.com/ubuntu/ wily universe
deb http://de.archive.ubuntu.com/ubuntu/ wily-updates universe
deb-src http://de.archive.ubuntu.com/ubuntu/ wily-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/ wily multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ wily multiverse
deb http://de.archive.ubuntu.com/ubuntu/ wily-updates multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ wily-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/ wily-backports main restricted universe multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ wily-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu wily-security main restricted
deb-src http://security.ubuntu.com/ubuntu wily-security main restricted
deb http://security.ubuntu.com/ubuntu wily-security universe
deb-src http://security.ubuntu.com/ubuntu wily-security universe
deb http://security.ubuntu.com/ubuntu wily-security multiverse
deb-src http://security.ubuntu.com/ubuntu wily-security 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 wily partner
# deb-src http://archive.canonical.com/ubuntu wily partner
然后运行:
apt-get update
要更新 apt 包数据库,然后:
apt-get upgrade
安装最新的更新(如果有的话)。如果您看到作为更新的一部分安装了新内核,您应该在之后重新启动系统:
reboot
3.更改默认外壳
/bin/sh 是 /bin/dash 的符号链接,但是我们需要 /bin/bash,而不是 /bin/dash。因此我们这样做:
dpkg-reconfigure dash
使用 dash 作为默认系统 shell (/bin/sh)? <-- 没有
如果您不这样做,ISPConfig 安装将失败。
4.禁用AppArmor
AppArmor 是一个安全扩展(类似于 SELinux),应该提供扩展的安全性。从 13.10 开始默认不安装它。我们将交叉检查它是否已安装。在我看来,你不需要它来配置一个安全的系统,它通常会导致更多的问题而不是好处(在你完成一周的故障排除后想想它,因为一些服务没有按预期工作,然后你发现一切没问题,只有 AppArmor 导致了问题)。因此,我禁用它(如果您想稍后安装 ISPConfig,这是必须的)。
我们可以像这样禁用它:
service apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils
5.同步系统时钟
将系统时钟与 Internet 上的 NTP (network ttime protocol) 服务器同步是个好主意。只需运行
apt-get install ntp ntpdate
并且您的系统时间将始终保持同步。
6. 安装 Postfix、Dovecot、MariaDB、phpMyAdmin、rkhunter、Binutils
我们可以使用一个命令安装 Postfix、Dovecot、MariaDB(作为 MySQL 的替代品)、rkhunter 和 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 sudo
MariaDB 是 MySQL 数据库服务器的一个分支,由最初的 MySQL 开发人员 Monty Widenius 开发。根据在互联网上找到的测试,MariaDB 比 MySQL 更快,而且它的发展正在以更快的速度进行,因此,大多数 Linux 发行版用 MariaDB 取代了 MySQL 作为默认的“类似 MySQL”的数据库服务器。如果您更喜欢 MySQL 而不是 MariaDB,请将上述命令中的 \mariadb-client mariadb-server\ 替换为 \mysql-client mysql-server\。
您将被问及以下问题:
General type of mail configuration: <-- Internet Site
System mail name: <-- server1.example.com
接下来打开 Postfix 中的 TLS/SSL 和提交端口:
nano /etc/postfix/master.cf
取消对提交和 smtps 部分的注释,如下所示 - 添加行 -o smtpd_client_restrictions=permit_sasl_authenticated,reject 到这两个部分,然后留下所有注释:
[...]
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
[...]
之后重新启动 Postfix:
service postfix restart
我们希望 MariaDB/MySQL 监听所有接口,而不仅仅是本地主机。因此,我们编辑 /etc/mysql/mariadb.conf.d/mysqld.cnf(对于 MariaDB 或 /etc/mysql/my.cnf(对于 MySQL)并注释掉 bind-address=127.0.0.1 行:
MariaDB
nano /etc/mysql/mariadb.conf.d/mysqld.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
[...]
然后我们重启MariaDB:
service mysql restart
MariaDB 和 MySQL 的 systemd 服务名称是 \mysql\,因此两个数据库服务器的重启命令是相同的。
现在我们在 MariaDB 中设置一个 root 密码。跑步:
mysql_secure_installation
你会被问到这些问题:
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
然后运行此命令为 root 用户禁用 UNIX 身份验证插件:
echo "update user set plugin='' where User='root';flush privileges;" | mysql --defaults-file=/etc/mysql/debian.cnf mysql
允许来自 PHPMyAdmin 的基于密码的身份验证。
nano /etc/mysql/my.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
[...]
然后我们重启MySQL:
service mysql restart
MariaDB 和 MySQL 的 systemd 服务名称是 \mysql\,因此两个数据库服务器的重启命令是相同的。
对于 MySQL 和 MariaDB:
现在检查网络是否已启用。跑步:
netstat -tap | grep mysql
输出应如下所示:
:~#
7. 安装 Amavisd-new、SpamAssassin 和 ClamAV
要安装 amavisd-new、SpamAssassin 和 ClamAV,我们运行
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
ISPConfig 3 安装程序使用 amavisd-new 在内部加载 SpamAssassin 过滤器库,因此我们可以停止 SpamAssassin 以释放 RAM:
service spamassassin stop
update-rc.d -f spamassassin remove
更新 ClamAV 防病毒签名并启动 Clamd 服务。更新过程可能需要一些时间,请勿中断。
freshclam
service clamav-daemon start