完美的服务器 -  Ubuntu 18.04(Nginx,MySQL,PHP,Postfix,BIND,Dovecot,Pure-FTPD和ISPConfig 3.1)

完美的服务器 - Ubuntu 18.04(Nginx,MySQL,PHP,Postfix,BIND,Dovecot,Pure-FTPD和ISPConfig 3.1)

本教程介绍了使用Nginx,PHP,MariaDB,Postfix,pure-ftpd,BIND,Dovecot和ISPConfig 3.1安装Ubuntu 18.04(Bionic Beaver)服务器的步骤。 ISPConfig是一个Web托管控制面板,允许您通过Web浏览器配置已安装的服务。 此设置提供完整的托管服务器,包括Web,电子邮件(包括垃圾邮件和防病毒过滤器),数据库,FTP和DNS服务。

1.初步说明

在本教程中,我将使用主机名server1.example.com ,其IP地址为192.168.1.100 ,网关为192.168.1.1,用于网络配置。 这些设置可能因您而异,因此您必须在适当的位置更换它们。 在继续之前,您需要按照本教程中的说明进行Ubuntu 18.04的基本最小安装。

本教程中的步骤必须以root用户身份执行,因此我不会在命令前面添加“sudo”。 在继续或运行之前,以root用户身份登录到服务器:

sudo -s

在shell上以其他用户身份登录时成为root用户。

编辑文件的命令将使用编辑器“nano”,您可以用您选择的编辑器替换它。 Nano是一个易于使用的shell文件编辑器。 如果您想使用nano并且还没有安装它,请运行:

apt-get install nano

2.更新Linux安装

编辑/etc/apt/sources.list 。 从文件中注释掉或删除安装CD,并确保已启用Universe多重宇宙存储库。 它应该如下所示:

nano /etc/apt/sources.list
#

# deb cdrom:[Ubuntu-Server 18.04 LTS _Bionic Beaver_ - Release amd64 (20180425.1)]/ bionic main restricted

#deb cdrom:[Ubuntu-Server 18.04 LTS _Bionic Beaver_ - Release amd64 (20180425.1)]/ bionic 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/ bionic main restricted
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://de.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-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/ bionic universe
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic universe
deb http://de.archive.ubuntu.com/ubuntu/ bionic-updates universe
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-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/ bionic multiverse
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic multiverse
deb http://de.archive.ubuntu.com/ubuntu/ bionic-updates multiverse
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-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/ bionic-backports main restricted universe multiverse
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-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 bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

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

然后运行:

apt-get update

要更新apt包数据库,然后:

apt-get upgrade

安装最新的更新(如果有的话)。 如果您发现新内核作为更新的一部分安装,则应在以后重新引导系统:

reboot

3.更改默认Shell

/ bin / sh/ bin / dash的符号链接,但我们需要/ bin / bash ,而不是/ bin / dash 。 因此我们这样做:

dpkg-reconfigure dash

使用dash作为默认系统shell(/ bin / sh)? < - 不

如果不这样做,ISPConfig安装将失败。

4.禁用AppArmor

AppArmor是一个安全扩展(类似于SELinux),应该提供扩展的安全性。 我们将交叉检查是否已安装并在必要时将其删除。 在我看来,你不需要它来配置一个安全的系统,它通常会导致更多的问题而不是优点(在你完成一周的故障排除之后想想它,因为某些服务没有按预期工作,然后你发现一切都很好,只有AppArmor引起了问题)。 因此,我禁用它(如果你想稍后安装ISPConfig,这是必须的)。

我们可以像这样禁用它:

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

5.同步系统时钟

通过Internet将系统时钟与NTP( n etwork t ime p rotocol)服务器同步是一个好主意。 简单地跑

apt-get -y install ntp ntpdate

并且您的系统时间将始终保持同步。

6.安装Postfix,Dovecot,MariaDB,phpMyAdmin,rkhunter,Binutils

要安装postfix,我们需要确保sendmail没有安装并运行。 要停止并删除sendmail,请运行以下命令:

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

错误消息:

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

没问题,这只是意味着没有安装sendmail,所以没有什么可以删除的。

我们可以用一个命令安装Postfix,Dovecot,MariaDB(作为MySQL替代品),rkhunter和binutils:

apt-get -y 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

MariaDB是MySQL数据库服务器的一个分支,由最初的MySQL开发人员Monty Widenius开发。 根据在互联网上发现的测试结果,MariaDB比MySQL更快,并且它的开发速度正在加快,因此,大多数Linux发行版都将MariaDB替换为默认的“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,拒绝这两个部分,然后将所有内容留下评论:

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

注意:   “-o ....”前面的空格非常重要!

之后重启Postfix:

service postfix restart

我们希望MariaDB / MySQL能够监听所有接口,而不仅仅是localhost。 因此,我们编辑/etc/mysql/mariadb.conf.d/50-server.cnf(对于MariaDB或 /etc/mysql/my.cnf (对于MySQL)并注释掉绑定地址= 127.0.0.1

MariaDB的

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

现在我们在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

将MariaDB中的密码身份验证方法设置为本机,以便我们以后可以使用PHPMyAdmin以root用户身份进行连接:

echo "update mysql.user set plugin = 'mysql_native_password' where user='root';" | mysql -u root

编辑文件/etc/mysql/debian.cnf并在以password开头的行中将MYSQL / MariaDB root密码设置为两次。

nano /etc/mysql/debian.cnf

需要添加的MySQL root密码以read显示,在本例中密码为“youcl”。

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = root
password = youcl
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = root
password = youcl
socket = /var/run/mysqld/mysqld.sock
basedir = /usr

然后我们重启MariaDB:

service mysql restart

MariaDB和MySQL的systemd服务名称是“ mysql ”,因此两个数据库服务器的restart命令相同。

MySQL的

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”,因此两个数据库服务器的restart命令相同。

对于MySQL和MariaDB:

现在检查是否已启用网络。 跑:

netstat -tap | grep mysql

输出应如下所示:

root@server1:~# netstat -tap | grep mysql
tcp6 0 0 [::]:mysql [::]:* LISTEN 12210/mysqld

7.安装Amavisd-new,SpamAssassin和ClamAV

为了安装amavisd-new,SpamAssassin和ClamAV,我们运行

apt-get -y install amavisd-new spamassassin clamav clamav-daemon 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

ISPConfig 3设置使用amavisd-new在内部加载SpamAssassin过滤器库,因此我们可以阻止SpamAssassin释放RAM:

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

更新ClamAV防病毒签名并启动Clamd服务。 更新过程可能需要一些时间,不要打断它。

freshclam
service clamav-daemon start

第一次运行freshclam时可以忽略以下错误。

ERROR: /var/log/clamav/freshclam.log is locked by another process
ERROR: Problem with internal logger (UpdateLogFile = /var/log/clamav/freshclam.log).

amavisd-new程序目前在Ubuntu 18.04中存在一个错误,它可以防止电子邮件正确地与Dkim签名。 运行以下命令修补amavisd-new。

cd /tmp
wget https://git.ispconfig.org/ispconfig/ispconfig3/raw/stable-3.1/helper_scripts/ubuntu-amavisd-new-2.11.patch
cd /usr/sbin
cp -pf amavisd-new amavisd-new_bak
patch < /tmp/ubuntu-amavisd-new-2.11.patch

如果你的'patch'命令出错,那么Ubuntu可能在此期间解决了这个问题,所以忽略那个错误应该是安全的。

7.1安装Metronome XMPP服务器(可选)

Metronome XMPP服务器提供XMPP聊天服务器。 此步骤是可选的,如果您不需要聊天服务器,则可以跳过此步骤。 没有其他ISPConfig功能依赖于此软件。

使用apt安装以下软件包。

apt-get -y 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

为Metronome添加shell用户。

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

将Metronome下载到/ opt目录并进行编译。

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

Beats器现已安装到/ opt /Beats器。

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏