1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RHEL 8.4 (ppc64le) へ cloud-init を導入

Last updated at Posted at 2021-11-09

#####はじめに

PowerVC キャプチャーイメージのため RHEL 8.4 サーバーに cloud-init を導入します。

参考:

・Installing and configuring cloud-init on Linux®


#####環境

RHEL 8.4 (ppc64le, Server with GUI で導入) on Power Systems S824

# cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="8.4 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.4"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.4 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8.4:GA"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/8/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.4
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.4"

yum repository 構成

インストールiso ファイルを使用して、BaseOS と AppStream の yum repository を構成します。

メディア・マウント

[root@test-cloudinit ~]# mkdir -p /media/rhel84dvd
[root@test-cloudinit ~]# mount /dev/sr0 /media/rhel84dvd/
mount: /media/rhel84dvd: WARNING: device write-protected, mounted read-only.
[root@test-cloudinit ~]# ls -l /media/rhel84dvd
total 48
dr-xr-xr-x. 4 root root  2048 May  3  2021 AppStream
dr-xr-xr-x. 4 root root  2048 May  3  2021 BaseOS
dr-xr-xr-x. 3 root root  2048 May  3  2021 boot
-r--r--r--. 1 root root  8154 May  3  2021 EULA
-r--r--r--. 1 root root  1455 May  3  2021 extra_files.json
-r--r--r--. 1 root root 18092 May  3  2021 GPL
dr-xr-xr-x. 2 root root  2048 May  3  2021 images
-r--r--r--. 1 root root   103 May  3  2021 media.repo
dr-xr-xr-x. 3 root root  2048 May  3  2021 ppc
-r--r--r--. 1 root root  1669 May  3  2021 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root  5134 May  3  2021 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1796 May  3  2021 TRANS.TBL

リポジトリー・ファイル作成

# cat /etc/yum.repos.d/rhel84_base.repo
[dvd-BaseOS]
name=RHEL84_BaseOS
baseurl=file:///media/rhel84dvd/BaseOS/
enabled=1
gpgcheck=0
gpgkey=file:///media/rhel84dvd/RPM-GPG-KEY-redhat-release

[dvd-AppStream]
name=RHEL84_AppStream
baseurl=file:///media/rhel84dvd/AppStream/
enabled=1
gpgcheck=0
gpgkey=file:///media/rhel84dvd/RPM-GPG-KEY-redhat-release

設定確認

# yum repolist
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

repo id                                repo name
dvd-AppStream                          RHEL84_AppStream
dvd-BaseOS                             RHEL84_BaseOS

#####cloud-init 導入

cloud-init は、マニュアルにリンクがある以下のRHEL8.0用のモジュールを使用します。
http://public.dhe.ibm.com/systems/virtualization/powervc/powervc-2.0/rhel8_cloud_init/

# ls -l
total 3468
-rw-r--r-- 1 root root 1011136 Aug 19  2020 cloud-init-19.1-8.ibm.el8.noarch.rpm

# yum install ./cloud-init-19.1-8.ibm.el8.noarch.rpm

依存関係が解決しました。
==================================================================================================================================
 パッケージ                          アーキテクチャー       バージョン                        リポジトリー                  サイズ
==================================================================================================================================
インストール:
 cloud-init                          noarch                 19.1-8.ibm.el8                    @commandline                  987 k
依存関係のインストール:
python3-jsonpatch                 noarch                 1.21-2.el8                        dvd-AppStream                  27 k
python3-jsonpointer               noarch                 1.10-11.el8                       dvd-AppStream                  20 k
python3-jwt                       noarch                 1.6.1-2.el8                       dvd-BaseOS                     43 k
python3-oauthlib                  noarch                 2.1.0-1.el8                       dvd-BaseOS                    155 k

トランザクションの概要
==================================================================================================================================
インストール  5 パッケージ

合計サイズ: 1.2 M
インストール後のサイズ: 3.9 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中

  準備             :  [====================                                                                                 ] 1/1

~ 省略 ~

  インストール中   : cloud-init-19.1-8.ibm.el8.noarch                                                                         5/5 

  scriptletの実行中: cloud-init-19.1-8.ibm.el8.noarch                                                                         5/5 

  検証             : python3-jwt-1.6.1-2.el8.noarch                                                                           1/5 

  検証             : python3-oauthlib-2.1.0-1.el8.noarch                                                                      2/5 

  検証             : python3-jsonpatch-1.21-2.el8.noarch                                                                      3/5 

  検証             : python3-jsonpointer-1.10-11.el8.noarch                                                                   4/5 

  検証             : cloud-init-19.1-8.ibm.el8.noarch                                                                         5/5 
Installed products updated.

インストール済み:
  cloud-init-19.1-8.ibm.el8.noarch        python3-jsonpatch-1.21-2.el8.noarch        python3-jsonpointer-1.10-11.el8.noarch       
  python3-jwt-1.6.1-2.el8.noarch          python3-oauthlib-2.1.0-1.el8.noarch       

完了しました!

dvd-BaseOS と dvd-AppStream のみで導入できました。よかった..。

導入した cloud-init を確認します。

# rpm -qi cloud-init
Name        : cloud-init
Version     : 19.1
Release     : 8.ibm.el8
Architecture: noarch
Install Date: Sun Dec  5 09:53:54 2021
Group       : Unspecified
Size        : 3198593
License     : ASL 2.0 or GPLv3
Signature   : (none)
Source RPM  : cloud-init-19.1-8.ibm.el8.src.rpm
Build Date  : Thu Jul 30 14:26:48 2020
Build Host  : b4916ccab9e8
Relocations : (not relocatable)
URL         : http://launchpad.net/cloud-init
Summary     : Cloud instance init scripts
Description :
Cloud-init is a set of init scripts for cloud instances.  Cloud instances
need special scripts to run during initialization to retrieve and install
ssh keys and to let the user run various scripts.

cloud-init 19.1-8 が導入されました。


cloud-init の構成

cloud-init を構成位します。
導入直後の /etc/cloud/cloud.cfg を確認。

# cat /etc/cloud/cloud.cfg
# The top level settings are used as module
# and system configuration.

# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'
# from the distro configuration specified below
users:
   - default

# If this is set, 'root' will not be able to ssh in and they
# will get a message to login instead as the default $user
disable_root: false

mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
resize_rootfs_tmp: /dev
ssh_pwauth:   0

# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false
datasource_list: [ ConfigDrive, None ]
datasource:
  ConfigDrive:
    dsmode: local
# Example datasource config
# datasource:
#    Ec2:
#      metadata_urls: [ 'blah.com' ]
#      timeout: 5 # (defaults to 50 seconds)
#      max_wait: 10 # (defaults to 120 seconds)

# The modules that run in the 'init' stage
cloud_init_modules:
 - migrator
 - seed_random
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - disk_setup
 - mounts
 - update_etc_hosts
 - ca-certs
 - rsyslog
 - users-groups
 - ssh

# The modules that run in the 'config' stage
cloud_config_modules:
 - ssh-import-id
 - locale
 - set-passwords
 - spacewalk
 - yum-add-repo
 - ntp
 - timezone
 - runcmd

# The modules that run in the 'final' stage
cloud_final_modules:
 - package-update-upgrade-install
 - puppet
 - chef
 - mcollective
 - salt-minion
 - rightscale_userdata
 - scripts-vendor
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - phone-home
 - final-message
 - power-state-change
 - reset_rmc
 - refresh_rmc_and_interface
 - set_hostname_from_dns
# System and/or distro specific settings
# (not accessible to handlers/transforms)
system_info:
   # This will affect which distro class gets used
   distro: rhel
   # Default user name + that default users groups (if added/used)
   default_user:
     name: rhel
     lock_passwd: True
     gecos: rhel Cloud User
     groups: [wheel, adm, systemd-journal]
     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
     shell: /bin/bash
   # Other config here will be given to the distro class and/or path classes
   paths:
      cloud_dir: /var/lib/cloud/
      templates_dir: /etc/cloud/templates/
   ssh_svcname: sshd

マニュアルを参照して、/etc/cloud/cloud.cfg を編集します。
「RHEL での cloud-init のインストールおよび構成」を実施します。

# cp -p /etc/cloud/cloud.cfg /etc/cloud/cloud.cfg_bk
# ls -l cloud.cfg*
-rw-r--r-- 1 root root 2435 Dec  5 10:09 cloud.cfg
-rw-r--r-- 1 root root 2337 Jul 30  2020 cloud.cfg_bk



#vi /etc/cloud/cloud.cfg

=> 修正追加

# diff cloud.cfg cloud.cfg_bk
17d16
< manage_resolv_conf: false
21,22c20
<
< datasource_list: [ ConfigDrive, NoCloud, None ]
---
> datasource_list: [ ConfigDrive, None ]
24c22
<   ConfigDrive:
---
>   ConfigDrive:
43c41
< # - update_etc_hosts
---
>  - update_etc_hosts
52c50
< # - locale
---
>  - locale
80c78
< # - set_hostname_from_dns
---
>  - set_hostname_from_dns
99,104d96
<
< runcmd:
< - rm -f /etc/machine-id
< - systemd-machine-id-setup

新規ファイル /etc/cloud/ds-identify.cfg を作成し、以下のデータを追加

# vi /etc/cloud/ds-identify.cfg
~ 記載して保存終了 ~ 

# cat /etc/cloud/ds-identify.cfg
policy: search,found=all,maybe=all,notfound=disabled

NetworkManager の upgrade

# yum upgrade NetworkManager
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Last metadata expiration check: 1:11:53 ago on Mon 08 Nov 2021 06:51:45 PM EST.
Dependencies resolved.
Nothing to do.
Complete!

register はまた今度...。

対象サービスの有効化と起動

# systemctl enable cloud-init-local.service
Created symlink /etc/systemd/system/cloud-init.target.wants/cloud-init-local.service → /usr/lib/systemd/system/cloud-init-local.service.

# systemctl enable cloud-init.service
Created symlink /etc/systemd/system/cloud-init.target.wants/cloud-init.service → /usr/lib/systemd/system/cloud-init.service.

# systemctl enable cloud-config.service
Created symlink /etc/systemd/system/cloud-init.target.wants/cloud-config.service → /usr/lib/systemd/system/cloud-config.service.

# systemctl enable cloud-final.service
Created symlink /etc/systemd/system/cloud-init.target.wants/cloud-final.service → /usr/lib/systemd/system/cloud-final.service.


# systemctl list-unit-files | grep cloud
cloud-config.service                       enabled
cloud-final.service                        enabled
cloud-init-local.service                   enabled
cloud-init.service                         enabled
cloud-config.target                        static
cloud-init.target                          enabled-runtime

cloud-init サービスの起動
# systemctl start cloud-init.service

# systemctl start cloud-init-local.service

# systemctl start cloud-config.service

# systemctl start cloud-final.service


これでキャプチャー準備ができました。
cloud-init の構成はもっといろいろ凝れそうですが一旦マニュアル・ベースの修正まで。

参考:

キャプチャー後は cloud-init 起動を停止しておいたりした方が良いかもしれません。

以上です。

1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?