さくらVPS 再セットアップ1

結局、さくらVPSはもう一度セットアップしなおすことにした。

まずは、OS再インストールから、初期設定を行っていく。

1. OS再インストール

VPSのコンパネからOSを再インストール。

パケットフィルタリングは以下の設定。

  • SSH:22 → 開放(後で閉じる)
  • Web:80/443 → 開放
  • メール:25/110/143/465/587/993/995 → 開放
  • カスタム:(SSH用の別番号) → 開放

2. 初期設定いろいろ

2.1. ホスト名変更

hostnamectl set-hostname hogehoge.xxx

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

dnf -y update

2.3. 管理用一般ユーザーの追加

adduser hoge
passwd hoge
Changing password for user hoge.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
usermod -G wheel hoge

2.4. sudo関連

vi /etc/pam.d/su
#%PAM-1.0
(中略)
# Uncomment the following line to require a user to be in the "wheel" group.
#auth           required        pam_wheel.so use_uid 
 ↓
auth           required        pam_wheel.so use_uid
visudo
(中略)
## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
 ↓
%wheel        ALL=(ALL)       NOPASSWD: ALL ##コメント解除。sudo でいちいちパスワード聞かれなくなる。

2.5. セキュリティ関連のパッケージを自動アップデート

dnf -y install dnf-automatic
vi /etc/dnf/automatic.conf
===
[commands]
#  What kind of upgrade to perform:
# default                            = all available upgrades
# security                           = only the security upgrades
upgrade_type = default
 ↓
upgrade_type = security
# Whether updates should be applied when they are available, by
# dnf-automatic.timer. notifyonly.timer, download.timer and
# install.timer override this setting.
apply_updates = no
 ↓
apply_updates = yes
===
systemctl enable dnf-automatic.timer
systemctl start dnf-automatic.timer

2.5. SSH関連

2.5.1. sshdの設定ファイルを変更

vi /etc/ssh/sshd_config
### root の直ログイン禁止
#PermitRootLogin yes
  ↓
PermitRootLogin no  # コメント解除し、no に変更。
### 空パスワードの禁止
#PermitEmptyPasswords no
  ↓
PermitEmptyPasswords no  # コメント解除。
### パスワード認証を禁止
PasswordAuthentication yes
  ↓
PasswordAuthentication no
### 公開鍵認証を有効に
PubkeyAuthentication yes  # コメント解除
### ポート番号変更
# Port 22
  ↓
Port 99999  # コメント解除し、ポート番号を変更

2.5.2. クライアント側で鍵ファイル生成し、サーバーにアップ

以下参照。

*Macから

https://blog.office-iwakiri.com/archives/linux/centos-2922

*Windowsから

2.7. 日本語化

dnf -y install langpacks-ja
localectl set-locale LANG=ja_JP.utf8
localectl
   System Locale: LANG=ja_JP.utf8
       VC Keymap: jp
      X11 Layout: jp

2.8. リポジトリの追加

dnf install epel-release
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

普段は無効化しておき、必要な時だけリポジトリを都度指定する。

vi /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
#baseurl=https://download.fedoraproject.org/pub/epel/$releasever/Everything/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1 ← ここを0に変更
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
(以下略)
vi /etc/yum.repos.d/remi-safe.repo
[remi-safe]
name=Safe Remi's RPM repository for Enterprise Linux 8 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/8/safe/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/8/safe/$basearch/httpsmirror
mirrorlist=http://cdn.remirepo.net/enterprise/8/safe/$basearch/mirror
enabled=1 ← ここを0に変更
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
(以下略)

3. アプリ色々

今度は、Apache、PHPを先に入れて確認してみる。

3.1. Apache

dnf -y install httpd mod_ssl
systemctl enable httpd
systemctl start httpd

今度は、どこがネックになってるか探るためにも、随時チェックしながら進めていくので、まずはデフォルトの状態でサービスを起動してみる。

この時点では、問題なし。Apacheのデフォルトページが表示された。

3.2. PHP

今回は、PHPのインストール方法を変えてみる。

まずは、デフォルトになっているバージョンを確認。

dnf module list php
Last metadata expiration check: 0:36:35 ago on Thu 26 Nov 2020 06:11:26 PM JST.
CentOS-8 - AppStream
Name                    Stream                      Profiles                                      Summary
php                     7.2 [d]                     common [d], devel, minimal                    PHP scripting language
php                     7.3                         common [d], devel, minimal                    PHP scripting language

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name                    Stream                      Profiles                                      Summary
php                     remi-7.2                    common [d], devel, minimal                    PHP scripting language
php                     remi-7.3                    common [d], devel, minimal                    PHP scripting language
php                     remi-7.4                    common [d], devel, minimal                    PHP scripting language
php                     remi-8.0                    common [d], devel, minimal                    PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

AppStreamの7.2がデフォルトになっているので、remi の7.4 を有効にする。

dnf module reset php
dnf module enable php:remi-7.4
dnf module list php
Last metadata expiration check: 0:40:40 ago on Thu 26 Nov 2020 06:11:26 PM JST.
CentOS-8 - AppStream
Name                   Stream                         Profiles                                     Summary
php                    7.2 [d]                        common [d], devel, minimal                   PHP scripting language
php                    7.3                            common [d], devel, minimal                   PHP scripting language

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name                   Stream                         Profiles                                     Summary
php                    remi-7.2                       common [d], devel, minimal                   PHP scripting language
php                    remi-7.3                       common [d], devel, minimal                   PHP scripting language
php                    remi-7.4 [e]                   common [d], devel, minimal                   PHP scripting language
php                    remi-8.0                       common [d], devel, minimal                   PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

これで、remi の7.4 がenable になったので、まずはPHP本体をインストールする。

dnf module install php:remi-7.4
Last metadata expiration check: 0:43:04 ago on Thu 26 Nov 2020 06:11:26 PM JST.
Error:
 Problem: cannot install the best candidate for the job
  - nothing provides libonig.so.105()(64bit) needed by php-mbstring-7.4.13-1.el8.remi.x86_64
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

libonig.so が無いとエラーになった…

いろいろググってみると、鬼車とかいうライブラリが php-mbstring で必要になっていて、その鬼車で libonig.so が必要になるのだとか…

dnf --enablerepo=remi install oniguruma5php
dnf module install php:remi-7.4

oniguruma5php を先にインストールしておくと、今度はインストールできた。何このトラップ…

とりあえず、本体+依存関係をインストールできたので、追加パッケージを入れておく。ひとまずは最小限度で、mysqlとimapのみ。

imap で libc-clientが必要になるので、それも先に入れておく。

dnf install -y wget
wget https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/l/libc-client-2007f-24.el8.x86_64.rpm
rpm -Uvh libc-client-2007f-24.el8.x86_64.rpm
dnf --enablerepo=remi install php-mysqlnd php-imap

追加パッケージがインストールできたので、php-fpm を起動しておく。

systemctl enable php-fpm
systemctl start php-fpm
systemctl restart httpd

この状態で、phpinfo を出力するPHPファイルを作ってブラウザから確認してみたら、ちゃんと表示できました。

これで、他のアプリを色々入れていって、503エラーが再現するようならスペック不足、ということになるし、再現しないようなら、手順がまずかった、ということになる。

タグ: # # # # #
コメントはまだありません

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA