4.8. ベース GCP インスタンスの作成および設定
GCP の運用およびセキュリティー要件に準拠する GCP インスタンスを作成して設定するには、次の手順を実行します。
手順
バケット内の圧縮ファイルからイメージを作成します。
$ gcloud compute images create BaseImageName --source-uri gs://BucketName/BaseImageName.tar.gz
以下に例を示します。
[admin@localhost ~] $ gcloud compute images create rhel-76-server --source-uri gs://user-rhelha/rhel-server-76.tar.gz Created [https://www.googleapis.com/compute/v1/projects/MyProject/global/images/rhel-server-76]. NAME PROJECT FAMILY DEPRECATED STATUS rhel-76-server rhel-ha-testing-on-gcp READY
イメージからテンプレートインスタンスを作成します。ベース RHEL インスタンスに必要な最小サイズは n1-standard-2 です。追加の設定オプションは、gcloud compute instances create を参照してください。
$ gcloud compute instances create BaseInstanceName --can-ip-forward --machine-type n1-standard-2 --image BaseImageName --service-account ServiceAccountEmail
以下に例を示します。
[admin@localhost ~] $ gcloud compute instances create rhel-76-server-base-instance --can-ip-forward --machine-type n1-standard-2 --image rhel-76-server --service-account account@project-name-on-gcp.iam.gserviceaccount.com Created [https://www.googleapis.com/compute/v1/projects/rhel-ha-testing-on-gcp/zones/us-east1-b/instances/rhel-76-server-base-instance]. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS rhel-76-server-base-instance us-east1-bn1-standard-2 10.10.10.3 192.227.54.211 RUNNING
SSH 端末セッションでインスタンスに接続します。
$ ssh root@PublicIPaddress
RHEL ソフトウェアを更新します。
- Red Hat Subscription Manager (RHSM) に登録します。
-
サブスクリプションプール ID を有効にします (または
--auto-attach
コマンドを使用します)。 すべてのリポジトリーを無効にします。
# subscription-manager repos --disable=*
以下のリポジトリーを有効にします。
# subscription-manager repos --enable=rhel-8-server-rpms
yum update
コマンドを実行します。# yum update -y
実行中のインスタンスに GCP Linux ゲスト環境をインストールします (インプレースインストール)。
手順は、Install the guest environment in-place を参照してください。
- CentOS/RHEL オプションを選択します。
- コマンドスクリプトをコピーして、コマンドプロンプトに貼り付けて、スクリプトを即座に実行します。
インスタンスに以下の設定変更を行います。これらの変更は、カスタムイメージの GCP の推奨事項に基づいています。詳細は、gcloudcompute images list を参照してください。
-
/etc/chrony.conf
ファイルを編集し、すべての NTP サーバーを削除します。 以下の NTP サーバーを追加します。
metadata.google.internal iburst Google NTP server
永続的なネットワークデバイスルールを削除します。
# rm -f /etc/udev/rules.d/70-persistent-net.rules # rm -f /etc/udev/rules.d/75-persistent-net-generator.rules
ネットワークサービスが自動的に開始するように設定します。
# chkconfig network on
sshd service
が自動的に起動するように設定します。# systemctl enable sshd # systemctl is-enabled sshd
タイムゾーンを UTC に設定します。
# ln -sf /usr/share/zoneinfo/UTC /etc/localtime
(必要に応じて)
/etc/ssh/ssh_config
ファイルを編集し、以下の行をファイルの最後に追加します。アクティブではない期間が長くなった場合も、SSH セッションをアクティブな状態に保ちます。# Server times out connections after several minutes of inactivity. # Keep alive ssh connections by sending a packet every 7 minutes. ServerAliveInterval 420
/etc/ssh/sshd_config
ファイルを編集し、必要に応じて以下の変更を加えます。ClientAliveInterval 420 設定は任意です。これにより、アクティブではない期間が長くなった場合にも SSH セッションをアクティブな状態に保ちます。PermitRootLogin no PasswordAuthentication no AllowTcpForwarding yes X11Forwarding no PermitTunnel no # Compute times out connections after 10 minutes of inactivity. # Keep ssh connections alive by sending a packet every 7 minutes. ClientAliveInterval 420
-
パスワードアクセスを無効にします。
ssh_pwauth from 1 to 0. ssh_pwauth: 0
重要以前は、SSH セッションアクセスを許可するパスワードアクセスを有効にして、インスタンスを設定していました。パスワードアクセスを無効にする必要があります。すべての SSH セッションアクセスはパスワードなしにする必要があります。
サブスクリプションマネージャーからインスタンスの登録を解除します。
# subscription-manager unregister
シェルの履歴を消去します。次の手順でインスタンスを実行した状態にします。
# export HISTSIZE=0