LoginSignup
20
23

More than 3 years have passed since last update.

CentOS8のインストールと初期設定お試し(MySQL8,PHPも)

Last updated at Posted at 2019-09-26

はじめに

2019/09/24 にCentOS8が公開されました。
どのくらい違ってるか、雑にでもインストールして、WebからDB接続まで試してみたときのメモです。

前提

Windows10 Pro 上のHyper-VにCentOS8をインストールします。
CentOS8のISOイメージは取得済みとします。
ソフトウェアの選択は「サーバー」を選択します。

Hyper-Vではまった点

CentOSのisoイメージを指定してVMを起動するも、ブートできない。。

⇒仮想マシンの設定で「セキュアブート」を無効にしたら起動しました。

SELinuxの無効化

/etc/selinux/config の編集

#SELINUX=enforcing
SELINUX=disabled

SELINUXの項目をdisabledにします。

firewalldの無効化

今回は雑な検証のため、firewalldは無効にしておきます。

systemctl stop firewalld`

ロケールを日本に

localectl set-locale LANG=ja_JP.utf8

現在のロケール確認コマンドは

localectl

直接設定ファイルを書きたい場合は

vim /etc/locale.conf

時刻合わせ

CentOS8からntpに代わりchronyが採用されました。
標準パッケージに含まれるので、自分でインストールすることは不要かと思います。

タイムゾーンを東京に

timedatectl set-timezone Asia/Tokyo

現在の日時、タイムゾーンの確認コマンド

[root@localhost ~]# timedatectl
               Local time: 木 2019-09-26 12:56:27 JST
           Universal time: 木 2019-09-26 03:56:27 UTC
                 RTC time: 木 2019-09-26 03:56:25
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

chronyの設定ファイルに時刻サーバを追加

/etc/chrony.conf
#pool 2.centos.pool.ntp.org iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst

chornyを再起動して、ソース状況確認

systemctl restart chronyd
[root@localhost ~]# chronyc sourcestats
210 Number of sources = 3
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
ntp1.jst.mfeed.ad.jp        7   7   200     +0.206      5.716    -51us   175us
ntp2.jst.mfeed.ad.jp        7   6   200     +1.069      4.589   +352us   117us
ntp3.jst.mfeed.ad.jp        7   5   200     -0.195      6.270    -90us   175us

パッケージのアップデート

CentOS8からdnfが採用され、今後はdnfになるようなので、慣れる意味でdnfを使います。
※yum XX とうってもdnfに転送されて今まで通り実行は可能です

dnf update

一応EPELリポジトリを追加

dnf install epel-release

phpとmysqlをインストール

dnf install php mysql-server

rootでのSSHログイン禁止

/etc/ssh/sshd_configの編集

#PermitRootLogin yes
PermitRootLogin no

yesの行を無効にし、noを設定します。

sshdの再起動

systemctl restart sshd

SSH接続を鍵認証で行う

sshクライアント側で公開鍵を作成(TeraTerm)

・Teratermのメニュー 設定-SSH鍵生成 を開き、「鍵の種類」はRSAにして「生成」する。
・パスフレーズは今回はなしにします。
・「公開鍵の保存」と「秘密鍵の保存」両方を適当な場所にファイルを保存する

公開鍵をサーバ側に保存

鍵を利用するLinuxユーザでサーバ側にいったんログインします。
ホームディレクトリに.sshディレクトリを作成、パーミッションを700に

mkdir ~/.ssh
chmod 700 ~/.ssh

.ssh内に公開鍵を「authorized_keys」というファイル名で保存します。
そして、こちらのファイルも自分ユーザのみアクセスできる権限にします。

chmod 700 ~/.ssh/authorized_keys

あとはTeratermでログインするときにローカルにだけある秘密鍵ファイルを指定するのみ

パスワード認証の禁止

・/etc/ssh/sshd_configの編集

#PasswordAuthentication yes
PasswordAuthentication no

PasswordAuthenticationをnoに設定し、再起動

systemctl restart sshd

MySQL8の初期設定とphpmyadmin

まず起動します。

systemctl start mysqld

初期化が走るため、少しまたされると大見ます。その後、MySQLのログにrootパスワードが記録されていると思うので確認・・

[root@localhost mysql]# grep 'password' /var/log/mysql/mysqld.log
2019-09-26T04:03:35.656371Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

が、MySQL8では単純な起動だとパスワードなしみたいです。

mysql_secure_installation でパスワード設定

[root@localhost mysql]# 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) : Yes
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!

Apacheの起動

systemctl start httpd

phpmyadminの導入

最低限のphp関連モジュールをインストール

dnf install php-pdo php-json php-xml php-mysqlnd php-gd php-mbstring

ドキュメントルートに移動し、phpmyadminのソースを取得

cd /var/www/html
wget https://files.phpmyadmin.net/phpMyAdmin/4.9.1/phpMyAdmin-4.9.1-all-languages.zip
unzip phpMyAdmin-4.9.1-all-languages.zip
mv phpMyAdmin-4.9.1-all-languages myadmin

動作確認

ブラウザで

http://VMのIPアドレス/myadmin

でphpmyadminへログインできるか確認します。

20
23
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
23