CentOS8でサーバー構築 - 3.LAMP環境構築(Apache2.4+MySQL8.0+PHP7.4のインストール)

Linux(OS)環境において
  • Apache(WEBサーバー)のインストールと設定
  • MySQL(RDBMS)のインストールと設定
  • PHP(プログラミング言語)と使いそうなPHPのモジュールのインストールと設定
LAMP環境を構築していく。

プログラミング言語をこれから習得してプロを目指す初学者の方、
言語には触っているがLinuxなどのサーバー関連はイマイチの方、
XAMPP環境と比べて一手間かかってしまうが、LAMP環境で学習することを強くお勧めします。


OS:Operating System
RDBMS:relational database management system
PHP:Hypertext Preprocessor

Apacheのインストール

dnfでインストールできるApacheのバージョンは2.4.37でした。
ドメイン kowloonet.local
IPアドレス192.168.1.100
で設定。
インストール
# dnf -y install httpd
設定
# vi /etc/httpd/conf/httpd.conf
#
ServerName kowloonet.local:80
・
・
# Further relax access to the default document root:
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Includes ExecCGI FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php index.cgi
</IfModule>

・
・
    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    SetEnvIf Request_URI "default\.ida" no_log
    SetEnvIf Request_URI "cmd\.exe" no_log
    SetEnvIf Request_URI "root\.exe" no_log
    SetEnvIf Request_URI "Admin\.dll" no_log
    SetEnvIf Request_URI "NULL\.IDA" no_log
    SetEnvIf Request_URI "\.(bmp|css|gif|htc|ico|jpe?g|svg|js|mpe?g|png|swf|woff|ttf)$" no_log
    CustomLog logs/access_log combined env=!no_log
    #CustomLog "logs/access_log" combined
・
・
#AddDefaultCharset UTF-8
Indexes
DirectoryIndexで指定したファイル(index.html)が存在しない場合、ディレクトリ内ファイルを一覧表示。
FollowSymLinks
シンボリックリンクの許可。
Includes
SSIの許可。
ExecCGI
CGIの許可。
AllowOverride All
.htaccessの許可
ドキュメントルートのファイル所有者変更
# chown -R xiohei. /var/www/
起動
# systemctl start httpd
# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
確認
ブラウザで 192.168.1.100 へアクセスしてみて確認。
テストページのデザインが一新されていました。
アクセスログ表示
# tail -f /var/log/httpd/access_log
エラーログ表示
# tail -f /var/log/httpd/error_log
テストページを非表示に
外部に公開する場合は非表示にする事。
# cd /etc/httpd/conf.d/
# mv welcome.conf welcome.conf.org
# mv autoindex.conf autoindex.conf.org
# systemctl restart httpd

MySQLのインストール

CentOS8ではMariaDBをアンインストールする必要は無い様です。
バージョン確認
# dnf list mysql*
メタデータの期限切れの最終確認: 0:32:26 時間前の 2020年05月21日 22時41分01秒 に実施しまし た。
利用可能なパッケージ
MySQL-zrm.noarch                3.0-23.el8                                       epel
mysql.x86_64                    8.0.17-3.module_el8.0.0+181+899d6349             AppStream
mysql-common.x86_64             8.0.17-3.module_el8.0.0+181+899d6349             AppStream
mysql-devel.x86_64              8.0.17-3.module_el8.0.0+181+899d6349             AppStream
mysql-errmsg.x86_64             8.0.17-3.module_el8.0.0+181+899d6349             AppStream
mysql-libs.x86_64               8.0.17-3.module_el8.0.0+181+899d6349             AppStream
mysql-server.x86_64             8.0.17-3.module_el8.0.0+181+899d6349             AppStream
mysql-test.x86_64               8.0.17-3.module_el8.0.0+181+899d6349             AppStream
インストール
# dnf install @mysql:8.0
「@」を付けてコロンの後にバージョンを指定する形で、必要なものをインストールしてくれます。
起動
# systemctl start mysqld
# systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
初期設定
文字コードの設定はデフォルトで utf8なので設定する必要は無い様です。
現在開発用として構築しているので、
使い勝手が良いようにパスワードのセキュリティレベルをLOWに。
# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!
パスワードのセキュリティレベルを個別に変更したい場合、
パスワードの条件を4文字以上に緩和
mysql> SET GLOBAL validate_password.length=4;
パスワードの条件緩和
mysql> SET GLOBAL validate_password.policy=LOW;
パスワードの変更
mysql> ALTER USER ユーザ名@localhost IDENTIFIED BY '変更後のパスワード';
データーベースの確認
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.08 sec)
ここではユーザ名「xiohei」を、全てのデーターベースにローカルホスト内からパスワード「1q2w」でアクセスできるように作成。
MySQL8からはCREATE USERを使う。
ユーザの追加
mysql> CREATE USER xiohei@localhost IDENTIFIED BY '1q2w'; mysql> GRANT ALL PRIVILEGES ON *.* TO xiohei@localhost WITH GRANT OPTION;
MySQL5.7以前のバージョンでは
GRANT ALL PRIVILEGES ON *.* TO xiohei@localhost IDENTIFIED BY '1q2w';
接続の確認
# mysql -uxiohei -p1q2w mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 46 Server version: 8.0.16 MySQL Community Server - GPL Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

PHPのインストール

dnfでAppStreamリポジトリからインストールできるPHPのバージョンは、7.2.11でした。
# dnf list php
# dnf list available | grep php
remiリポジトリからから現時点で最新のPHP7.4をインストールしましょう。
epelリポジトリ追加
# dnf -y install epel-release
remiリポジトリ追加
# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-8.rpm
# dnf module reset php
# dnf module enable php:remi-7.4
php-devel をインストールする時にPowerToolsリポジトリから
libedit-devel をインストール必要があるのでこちらも利用可能にしておく。
PowerToolsリポジトリ追加
# dnf config-manager --set-enabled PowerTools
利用可能リポジトリ確認
# dnf repolist --enabled
メタデータの期限切れの最終確認: 0:31:56 時間前の 2020年05月21日 20時48分35秒 に実施しまし た。
repo id             repo の名前                                                      状態
AppStream           CentOS-8 - AppStream                                             5,283
BaseOS              CentOS-8 - Base                                                  1,661
PowerTools          CentOS-8 - PowerTools                                            1,456
*epel               Extra Packages for Enterprise Linux 8 - x86_64                   5,601
*epel-modular       Extra Packages for Enterprise Linux Modular 8 - x86_64               0
extras              CentOS-8 - Extras                                                   16
remi-modular        Remi's Modular repository for Enterprise Linux 8 - x86_64          359
remi-safe           Safe Remi's RPM repository for Enterprise Linux 8 - x86_64       2,285
利用可能パッケージ確認
# dnf info php
利用可能なパッケージ
名前         : php
バージョン   : 7.4.6
リリース     : 1.el8.remi
Arch         : x86_64
サイズ       : 3.0 M
ソース       : php-7.4.6-1.el8.remi.src.rpm
リポジトリー : remi-modular
概要         : PHP scripting language for creating dynamic web sites
URL          : http://www.php.net/
ライセンス   : PHP and Zend and BSD and MIT and ASL 1.0 and NCSA
説明         : PHP is an HTML-embedded scripting language. PHP attempts to
             : make it easy for developers to write dynamically generated web
             : pages. PHP also offers built-in database integration for
             : several commercial and non-commercial database management
             : systems, so writing a database-enabled webpage with PHP is
             : fairly simple. The most common use of PHP coding is probably
             : as a replacement for CGI scripts.
             :
             : The php package contains the module (often referred to as
             : mod_php) which adds support for the PHP language to Apache
             : HTTP Server.
PHPのインストール
# dnf -y install php php-devel php-gd php-zip php-mysqlnd
上記コマンドで必要なものもインストールしてくれるのでいろいろ入ります。
# dnf list installed | grep php
php.x86_64                                         7.4.6-1.el8.remi                                  @remi-modular
php-cli.x86_64                                     7.4.6-1.el8.remi                                  @remi-modular
php-common.x86_64                                  7.4.6-1.el8.remi                                  @remi-modular
php-devel.x86_64                                   7.4.6-1.el8.remi                                  @remi-modular
php-fpm.x86_64                                     7.4.6-1.el8.remi                                  @remi-modular
php-gd.x86_64                                      7.4.6-1.el8.remi                                  @remi-modular
php-json.x86_64                                    7.4.6-1.el8.remi                                  @remi-modular
php-mbstring.x86_64                                7.4.6-1.el8.remi                                  @remi-modular
php-mysqlnd.x86_64                                 7.4.6-1.el8.remi                                  @remi-modular
php-opcache.x86_64                                 7.4.6-1.el8.remi                                  @remi-modular
php-pdo.x86_64                                     7.4.6-1.el8.remi                                  @remi-modular
php-pecl-zip.x86_64                                1.18.2-1.el8.remi.7.4                             @remi-modular
php-sodium.x86_64                                  7.4.6-1.el8.remi                                  @remi-modular
php-xml.x86_64                                     7.4.6-1.el8.remi                                  @remi-modular
libedit-develが無い状態でphp-develをインストールしようとすると、
エラー:
 問題: cannot install the best candidate for the job
  - nothing provides libedit-devel(x86-64) needed by php-devel-7.4.6-1.el8.remi.x86_64
(インストール不可のパッケージをスキップするには、'--skip-broken' を追加してみてください または、'--nobest' を追加して、最適候補のパッケージのみを使用しないでください)
と出てしまいインスールできません。
古いPHPからバージョンアップしたい場合は、PHP関連のモジュールを一旦削除
# dnf remove php-*
dnfのログはこちらで確認。
# tail -f /var/log/dnf.log
起動
# systemctl restart httpd
確認
# php -v
PHP 7.4.6 (cli) (built: May 12 2020 08:09:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies
動作確認
# vi /var/www/html/phpinfo.php
<?php
phpinfo();
ブラウザで http://192.168.1.100/phpinfo.php へアクセス。
(IPアドレスは各自で設定しているもの。)
公開したくない場合は削除するか、
Basic認証をかけたディレクトリへ移動させておきましょう。
# rm -rf /var/www/html/phpinfo.php
LAMP環境構築は以上で完了です。

CentOS8でサーバー構築 - 2.Postfix+Dovecot(MTA)

CentOS7ではデフォルトでPostfixが、古いものではsendmailがインストールされていたが、
CentOS8ではPostfix、SendmailなどのMTAがインストールされておらず、する必要がある。
メールの送受信ができるようにPostfixとDovecotを使えるようにしておく。
主にサーバーサイドからの送信を目的とした設定を記載しています。
MTAとは Mail Transfer Agent の略。ネットワーク上でメールを転送・配送するソフトウェアの事。Postfix、Sendmail、qmailなど。
それに対し、ユーザ側がメールを表示・作成・送受信するソフトウェアをMUA(Mail User Agent)という。メールクライアント、メーラーと呼ばれるもの。Outlook、Thunderbird、Becky!(私はこれ使ってます)など。
使用中のMTAの確認
# alternatives --display mta mta -ステータスは自動です。 リンクは現在 /usr/sbin/sendmail.postfix を指しています。 /usr/sbin/sendmail.postfix - priority 60 スレーブ mta-mailq: /usr/bin/mailq.postfix スレーブ mta-newaliases: /usr/bin/newaliases.postfix スレーブ mta-pam: /etc/pam.d/smtp.postfix スレーブ mta-rmail: /usr/bin/rmail.postfix スレーブ mta-sendmail: /usr/lib/sendmail.postfix スレーブ mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz スレーブ mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz スレーブ mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz スレーブ mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz スレーブ mta-smtpdman: /usr/share/man/man8/smtpd.postfix.8.gz 現在の「最適」バージョンは /usr/sbin/sendmail.postfix です。
使用中のMTAの変更
# alternatives --config mta 1 プログラムがあり 'mta' を提供します。 選択 コマンド ----------------------------------------------- *+ 1 /usr/sbin/sendmail.postfix Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:

Postfix

実際に運用するには暗号化通信、スパム対策、などの対策も必要だが、
今回はCentOS上で動作するWebアプリケーションの作製が主な目的のためとりあえず割愛。
参照:CentOS8でサーバー構築 - 7.Postfix3.3+Dovecot2.3の暗号化設定(SSL/TLS)
インストール
# dnf -y install postfix
設定
# vi /etc/postfix/main.cf
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = mail.kowloonet.local
・省略
・
 #mydomain = domain.tld
mydomain = kowloonet.local

・省略
・
#myorigin = $myhostname
myorigin = $mydomain
・省略
・
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost

# Enable IPv4, and IPv6 if supported
inet_protocols = ipv4
・省略
・
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain
・省略
・
#home_mailbox = Mailbox
home_mailbox = Maildir/
・省略
・
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown
・
・下記追加

# SMTP Auth
#
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions =
    permit_mynetworks
    permit_sasl_authenticated
    reject_unauth_destination

# Mail size limit
# 10M
message_size_limit = 10485760

# Mailbox size limit
# 1G
mailbox_size_limit = 1073741824

# OP25B
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
# vi /etc/postfix/master.cf
smtp      inet  n       -       n       -       -       smtpd
#smtp      inet  n       -       n       -       1       postscreen
#smtpd     pass  -       -       n       -       -       smtpd
#dnsblog   unix  -       -       n       -       0       dnsblog
#tlsproxy  unix  -       -       n       -       0       tlsproxy
submission inet n       -       n       -       -       smtpd
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
ユーザー毎にメールボックスが作製されるように設定
# mkdir -p /etc/skel/Maildir/{new,cur,tmp}
# chmod -R 700 /etc/skel/Maildir/
既存ユーザにMaldirが存在しない場合はメールボックス作成
# mkdir -p /home/xiohei/Maildir/{new,cur,tmp}
# chmod -R 700 /home/xiohei/Maildir/
# chown -R xiohei. /home/xiohei/Maildir/
SMTP認証
# dnf -y install cyrus-sasl
# systemctl start saslauthd
# systemctl enable saslauthd
SMTP認証で使用するパスワード設定
# echo [smtp.gmail.com]:587 Gmaiのlアドレス:Gmailのパスワード > /etc/postfix/sasl_passwd
# chmod 640 /etc/postfix/sasl_passwd
# postmap /etc/postfix/sasl_passwd
OP25B対策リレーに使うGmailアカウント設定
リレー(中継)に使うGmailアカウントのセキュリティレベルを変更する必要があったため変更。
「リンクされているGoogleアカウントの重大なセキュリティ通知」のメールも飛んできました。
Gmailアカウントを管理 → セキュリティ → 安全性の低いアプリのアクセス を有効にする。
OP25:Outbound Port 25 Blocking。ISP(インターネットサービスプロバイダ)が迷惑メール対策として特定のサーバ以外からPort25をブロック。
Gmailのセキュリティ設定で中継がうまくいかない時のmailログ
# tail -f /var/log/maillog May 17 13:02:35 kowloonet postfix/smtp[9253]: 45CF0185725A: to=<送信先メールアドレス>, relay=smtp.gmail.com[64.233.189.109]:587, delay=1.8, delays=0.04/0.03/1.7/0, dsn=4.7.8, status=deferred (SASL authentication failed; server smtp.gmail.com[64.233.189.109] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8 https://support.google.com/mail/?p=BadCredentials q100sm5156446pjc.11 - gsmtp)
変更後は無事に送信できました。
# tail -f /var/log/maillog May 17 13:04:37 kowloonet postfix/smtp[9253]: 43B15185725D: to=<送信先メールアドレス>, relay=smtp.gmail.com[64.233.189.109]:587, delay=2.5, delays=0.02/0/1.7/0.86, dsn=2.0.0, status=sent (250 2.0.0 OK 1589688277 a16sm5273075pff.41 - gsmtp)
起動
# postfix check
# systemctl start postfix
# systemctl enable postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-05-11 17:26:22 JST; 9min ago
 Main PID: 8383 (master)
    Tasks: 3 (limit: 4884)
   Memory: 7.6M
   CGroup: /system.slice/postfix.service
           ├─8383 /usr/libexec/postfix/master -w
           ├─8384 pickup -l -t unix -u
           └─8385 qmgr -l -t unix -u

Dovecot

インストール
# yum -y install dovecot
設定
# vi /etc/dovecot/conf.d/10-mail.conf
#  <doc/wiki/MailLocation.txt >
#
mail_location = maildir:~/Maildir
# vi /etc/dovecot/conf.d/10-auth.conf
# See also ssl=required setting.
disable_plaintext_auth = no
# vi /etc/dovecot/conf.d/10-ssl.conf
# plain imap and pop3 are still allowed for local connections
ssl = no
起動
# systemctl start dovecot
# systemctl enable dovecot
Created symlink /etc/systemd/system/multi-user.target.wants/dovecot.service → /usr/lib/systemd/system/dovecot.service.

root宛メールを一般ユーザへ転送

この場合は一般ユーザ xiohei
# sed -i '/^root:/d' /etc/aliases
# echo 'root: xiohei' >> /etc/aliases
# newaliases

メール配送の確認

Gmailなどの外のアドレス宛へメールが送信できるか確認。
mailコマンドが使えない場合はインストール。
mailxインストール
# dnf -y install mailx
メール送信
# echo testMessage| mail -s "test" 送信先メールアドレス
メールログ確認
# tail -f /var/log/maillog
May 18 07:26:42 kowloonet postfix/pickup[18628]: 6C4831857241: uid=0 from=
May 18 07:26:42 kowloonet postfix/cleanup[18829]: 6C4831857241: message-id=<20200517222642.6C4831857241@mail.kowloonet.local>
May 18 07:26:42 kowloonet postfix/qmgr[9097]: 6C4831857241: from=, size=451, nrcpt=1 (queue active)
May 18 07:26:46 kowloonet postfix/smtp[18831]: 6C4831857241: to=<送信先メールアドレス>, relay=smtp.gmail.com[64.233.189.108]:587, delay=3.9, delays=0.06/0.04/2.2/1.5, dsn=2.0.0, status=sent (250 2.0.0 OK  1589754406 ce21sm6744215pjb.51 - gsmtp)
May 18 07:26:46 kowloonet postfix/qmgr[9097]: 6C4831857241: removed
status=sent と出てればOK。
キューの確認
# postqueue -p
キューの配送
# postqueue  -i キューのID
全てのキューの配送
# postqueue  -f
キューの削除
# postsuper -d キューのID
全てのキューの削除
# postsuper -d all

CentOS8でサーバー構築 - 1.環境設定

当面は、VMWareWorkstation上で学習用、開発用、テスト用としての利用を想定に記載しています。
インストールから環境設定までは過去記事も参考にしてみて下さい。
VMware+CentOSで開発環境構築 - 1.インストール
VMware+CentOSで開発環境構築 - 2.環境設定

minimal iso からCentoOS8をインストールすると、以前とは違って、
  • GUI環境(Gnome)で立ち上がる(インストール時の選択によるので要検証)
  • postfixがデフォルトでインストールされていない
  • yumからdnfへ変更(過渡期)
  • git がデフォルトでインストールされている
など、CentOS7から変更されたものが多々あるので注意。

dnfリポジトリの修正

CentOS8からyumは廃止となり、dnfへ変更に。
コマンドyumは以前と同じように使えますが、実行しているのはdnfの模様。
インストール済みパッケージ(postfix)を調べたい時、
# dnf list installed | grep postfix
rpmコマンドでも可。
# rpm -qa | grep postfix
利用可能なパッケージ(postfix)を調べたい時、
# dnf list available | grep postfix
有効なリポジトリを表示、
# dnf repolist
また、リポジトリの設定ファイルがリポジトリ毎に分かれたみたいです。
    CentOS-AppStream.repo
    開発者用パッケージ。最新ののものはこちらへ。
    CentOS-Base.repo
    OSの動作に必要なパッケージ。
    CentOS-Extras.repo
    拡張パッケージ。
    CentOS-centosplus.repo
    拡張パッケージ。デフォルトでは無効。
日本のサーバーに向けておきます。
リポジトリ設定ファイル修正
# vi /etc/yum.repos.d/CentOS-AppStream.repo
[AppStream]
name=CentOS-$releasever - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
# vi /etc/yum.repos.d/CentOS-Base.repo
[BaseOS]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
# vi /etc/yum.repos.d/CentOS-Extras.repo
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/extras/$basearch/os/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/extras/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
# vi /etc/yum.repos.d/CentOS-centosplus.repo
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/centosplus/$basearch/os/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
最新のパッケージに更新
# dnf -y update
そこそこ時間がかかるので、離席前などに。

開発ツールのインストール

# dnf -y groupinstall base "Development tools"

PERLのシンボリックリンク作成

# ln -s /usr/bin/perl /usr/local/bin/perl

NTPの設定

外部公開せず、内部のネットワークからのみ参照できるようにしておく。
設定
# vi /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
#pool 2.centos.pool.ntp.org iburst
server ntp.nict.jp iburst
server ntp.ring.gr.jp iburst
・
・
# Allow NTP client access from local network.
allow 192.168.1.0/16
起動
# systemctl start chronyd
# systemctl enable chronyd
強制同期
# chronyc makestep
200 OK
確認
# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor pre>
   Active: active (running) since Sat 2020-05-16 14:41:59 JST; 1 day 17h ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 1047 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=ex>
  Process: 970 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCC>
 Main PID: 975 (chronyd)
    Tasks: 1 (limit: 4884)
   Memory: 1.1M
   CGroup: /system.slice/chronyd.service
           └─975 /usr/sbin/chronyd
・
・
# chronyc sources
210 Number of sources = 2
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp-b2.nict.go.jp             1  10   377   31m    +11ms[  +11ms] +/-   30ms
^+ core.ring.gr.jp               2  10   377   750  +3254us[+3254us] +/-   46ms

vimの設定

# echo "alias vi='vim'" >> /etc/profile
# source /etc/profile

SSHの設定

openSSHがデフォルトでインストール済みなので、設定を変更して再起動。
実際に運用する場合はPort22は使用せず、大まかに1100番~60000の間で割り振り
攻撃を受けないようにするのをお勧めします。
設定
# vi /etc/ssh/sshd_config
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
Port 22
・
・
# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:
LoginGraceTime 30s
PermitRootLogin no
・
・
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
PermitEmptyPasswords no
PasswordAuthentication yes
起動
# systemctl restart sshd
# systemctl enable sshd

FTPのインストール

実際に運用するにはセキュリティを考慮する必要有。
CentOS8でサーバー構築 - 6.FTPサーバーの設定(vsftpd SSL/TLSなど)
インストール
# dnf -y install vsftpd
設定
# vi /etc/vsftpd/vsftpd.conf
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
・
・
# ASCII mangling is a horrible feature of the protocol.
ascii_upload_enable=YES
ascii_download_enable=YES
起動
# systemctl start vsftpd
# systemctl enable vsftpd Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /usr/lib/systemd/system/vsftpd.service.

systemctlのBash保管 (2020/06/19追記)

completionインストール
# yum -y install bash-completion
Last metadata expiration check: 0:47:01 ago on Fri 19 Jun 2020 08:05:10 AM JST.
Package bash-completion-1:2.7-5.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

不要なサービスの停止

稼働中のサービスを調べてみて、不要だと思われるサービスは停止しておく。
稼働中のサービス
# systemctl list-units --type=service
UNIT                         LOAD   ACTIVE SUB     DESCRIPTION
accounts-daemon.service      loaded active running Accounts Service
alsa-state.service           loaded active running Manage Sound Card State (>
atd.service                  loaded active running Job spooling tools
auditd.service               loaded active running Security Auditing Service
avahi-daemon.service         loaded active running Avahi mDNS/DNS-SD Stack
chronyd.service              loaded active running NTP client/server
colord.service               loaded active running Manage, Install and Gener>
crond.service                loaded active running Command Scheduler
cups.service                 loaded active running CUPS Scheduler
dbus.service                 loaded active running D-Bus System Message Bus
dovecot.service              loaded active running Dovecot IMAP/POP3 email s>
dracut-shutdown.service      loaded active exited  Restore /run/initramfs on>
gdm.service                  loaded active running GNOME Display Manager
gssproxy.service             loaded active running GSSAPI Proxy Daemon
httpd.service                loaded active running The Apache HTTP Server
import-state.service         loaded active exited  Import network configurat>
iscsi-shutdown.service       loaded active exited  Logout off all iSCSI sess>
kdump.service                loaded active exited  Crash recovery kernel arm>
kmod-static-nodes.service    loaded active exited  Create list of required s>
ksm.service                  loaded active exited  Kernel Samepage Merging
ksmtuned.service             loaded active running Kernel Samepage Merging (>
libstoragemgmt.service       loaded active running libstoragemgmt plug-in se>
libvirtd.service             loaded active running Virtualization daemon
lvm2-monitor.service         loaded active exited  Monitoring of LVM2 mirror>
lvm2-pvscan@8:2.service      loaded active exited  LVM event activation on d>
mcelog.service               loaded active running Machine Check Exception L>
ModemManager.service         loaded active running Modem Manager
NetworkManager-wait-online.service loaded active exited  Network Manager Wai>
NetworkManager.service       loaded active running Network Manager
nis-domainname.service       loaded active exited  Read and set NIS domainna>
php-fpm.service              loaded active running The PHP FastCGI Process M>
polkit.service               loaded active running Authorization Manager
postfix.service              loaded active running Postfix Mail Transport Ag>
rngd.service                 loaded active running Hardware RNG Entropy Gath>
rpc-statd-notify.service     loaded active exited  Notify NFS peers of a res>
rpcbind.service              loaded active running RPC Bind
rsyslog.service              loaded active running System Logging Service
rtkit-daemon.service         loaded active running RealtimeKit Scheduling Po>
saslauthd.service            loaded active running SASL authentication daemo>
smartd.service               loaded active running Self Monitoring and Repor>
sshd.service                 loaded active running OpenSSH server daemon
sssd.service                 loaded active running System Security Services >
systemd-fsck@dev-disk-by\x2duuid-c902437d\x2d4f4e\x2d4040\x2d829e\x2d80db761>
systemd-journal-flush.service loaded active exited  Flush Journal to Persist>
systemd-journald.service     loaded active running Journal Service
systemd-logind.service       loaded active running Login Service
systemd-machined.service     loaded active running Virtual Machine and Conta>
systemd-random-seed.service  loaded active exited  Load/Save Random Seed
systemd-remount-fs.service   loaded active exited  Remount Root and Kernel F>
systemd-resolved.service     loaded active running Network Name Resolution
systemd-sysctl.service       loaded active exited  Apply Kernel Variables
systemd-tmpfiles-setup-dev.service loaded active exited  Create Static Devic>
systemd-tmpfiles-setup.service loaded active exited  Create Volatile Files a>
systemd-udev-settle.service  loaded active exited  udev Wait for Complete De>
systemd-udev-trigger.service loaded active exited  udev Coldplug all Devices
systemd-udevd.service        loaded active running udev Kernel Device Manager
systemd-update-utmp.service  loaded active exited  Update UTMP about System >
systemd-user-sessions.service loaded active exited  Permit User Sessions
tuned.service                loaded active running Dynamic System Tuning Dae>
udisks2.service              loaded active running Disk Manager
upower.service               loaded active running Daemon for power manageme>
user-runtime-dir@1000.service loaded active exited  /run/user/1000 mount wra>
user-runtime-dir@42.service  loaded active exited  /run/user/42 mount wrapper
user@1000.service            loaded active running User Manager for UID 1000
user@42.service              loaded active running User Manager for UID 42
vdo.service                  loaded active exited  VDO volume services
vgauthd.service              loaded active running VGAuth Service for open-v>
vmtoolsd.service             loaded active running Service for virtual machi>
wpa_supplicant.service       loaded active running WPA supplicant

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

69 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
※postfix、dovecot、Apache、PHPインストール後に対応したので表示されています。
atd
スケジュール管理
kdump
システム異常時にメインメモリ上の内容をHDDに記録
mdmonitor
ソフトウェアRAID
# systemctl stop atd
# systemctl disable atd
# systemctl stop kdump
# systemctl disable kdump
# systemctl stop mdmonitor
# systemctl disable mdmonitor