tencent cloud

Linuxシステムへのcloud-initのインストール
最終更新日:2023-05-15 10:18:48
Linuxシステムへのcloud-initのインストール
最終更新日: 2023-05-15 10:18:48

ユースケース

Cloud-initはLinuxディストリビューションのインスタンスの自動的な初期化とカスタマイズのためのツールです。インポートされたイメージにcloud-initサービスがインストールされていない場合、イメージを介して起動されたインスタンスは正しく初期化できなくなり、イメージのインポートに失敗する可能性があります。このドキュメントでは、cloud-initサービスをインストールする方法について説明します。 cloud-initをインストールするには、次の3つの方法をお勧めします:

注意事項

Linuxシステムイメージをインポートする前に、イメージにcloud-initサービスが正しくインストールされていることを確認してください。

前提条件

cloud-initサービスがインストールされているサーバーは、パブリックネットワークに正常にアクセスできます。

操作手順

cloud-initバイナリーパッケージをダウンロードする
cloud-init パッケージを手動でダウンロードする
ソフトウェアソースから cloud-init パッケージを使用する
説明:
cloud-initはqcloud-pythonに依存します。qcloud-pythonは、Tencent Cloudによって再コンパイルおよびパッケージ化されたソフトウェアパッケージです。これは、ディレクトリ/usr/local/qcloud/pythonにインストールされた、cloud-initオペレーティング環境にのみ使用される個別のpython環境です。システムでのデフォルトのpythonと競合しません。
cloud-initは、Tencent Cloudがコミュニティのバージョン20.1に基づいて開発され、Tencent Cloudの動作環境に適応する専用のcloud-initです。
cloud-initバイナリーパッケージは、次のOSをサポートします:
タイプ
OS
バージョン
x86_64
arm64
qcloud-python
cloud-init
qcloud-python
cloud-init
rpm
CentOS
7
8
Fedora
36
NA
NA
Kylin
20sp1
openSUSE
15.4
NA
NA
deb
Debian
11
10
NA
NA
9
NA
NA
8
NA
NA
Ubuntu
22.04
NA
NA
20.04
18.04
16.04
NA
NA


cloud-initバイナリーパッケージのダウンロード

1. 上記のインストールパッケージをダウンロードします。
2. cloud-init がすでに存在する場合は、次のコマンドを実行してクリアします。
rm -rf /var/lib/cloud
rm -rf /etc/cloud
rm -rf /usr/local/bin/cloud*
3. OSに応じて、次のコマンドを実行します:
debシリーズの場合は、次のコマンドを実行します:
dpkg -i *.deb
rpmシリーズの場合は、次のコマンドを実行します:
rpm -ivh *.rpm
4. バージョンが正しくインストールされているかどうかを確認します
cloud-init qcloud -v
/usr/bin/cloud-init qcloud 0011
5. 再起動後に有効になります

cloud-initパッケージのダウンロード

説明:
cloud-init-20.1.0011 バージョンはTencent Cloud と最も互換性があります。これにより、このイメージで作成されたCVMのすべての設定項目が適切に初期化されることが保証されます。cloud-init-20.1.0011.tar.gzバージョンをインストールすることを推奨します。また ここをクリック してcloud-initパッケージの他のバージョンをダウンロードすることもできます。 このドキュメントでは、cloud-init-20.1.0011バージョンを例に説明します。
次のコマンドを実行して、cloud-initソースパッケージをダウンロードします。
wget https://gerryguan-1306210569.cos.ap-chongqing.myqcloud.com/cloud-init/src/cloud-init-20.1.0011.tar.gz

cloud-initのインストール

1. 次のコマンドを実行して、cloud-initインストールパッケージを解凍します。
説明:
OSがUbuntuの場合は、rootアカウントに切り替えてください。
tar -zxvf cloud-init-20.1.0011.tar.gz
2. 次のコマンドを実行して、解凍したcloud-initインストールパッケージディレクトリ(cloud-init-20.1.0011ディレクトリ)に移動します。
cd cloud-init
3. OSバージョンに応じてPython-pipをインストールします。
CentOS 6/7の場合、次のコマンドを実行します:
yum install python3-pip -y
Ubuntuの場合、次のコマンドを実行します。
apt-get -y install python3-pip
インストール中に「インストールに失敗しました」または「インストールパッケージが見つかりません」などのエラーが発生した場合は、 Python-pipがインストールできない時の解決法 を参考して問題のトラブルシューティングを行ってください。
4. 次のコマンドを実行し、pipをアップグレードします。
python3 -m pip install --upgrade pip
5. 以下のコマンドを実行して、依存関係をインストールします。
ご注意:
Cloud-initがrequests 2.20.0コンポーネントを使用する場合、Python 2.6はサポートされません。イメージ環境にインストールされているPythonインタープリターバージョンが2.6以前の場合、cloud-initの依存関係をインストールする前、pip install 'requests<2.20.0' コマンドを実行して、requests 2.20.0以前のバージョンをインストールしてください。
pip3 install -r requirements.txt
6. OSのバージョンによりcloud-utilsコンポーネントをインストールします。
CentOS 6の場合、次のコマンドを実行します。
yum install cloud-utils-growpart dracut-modules-growroot -y
dracut -f
CentOS 7の場合、次のコマンドを実行します。
yum install cloud-utils-growpart -y
Ubuntuの場合、次のコマンドを実行します。
apt-get install cloud-guest-utils -y
7. 次のコマンドを実行して、cloud-initをインストールします。
python3 setup.py build
python3 setup.py install --init-system systemd
ご注意:
--init-systemのオプションパラメータには、:(systemd、sysvinit、sysvinit_deb、sysvinit_freebsd、sysvinit_openrc、sysvinit_suse、upstart)[default:None]があります。現在のOSで使用されている自動起動サービス管理方法によってパラメータを選択してください。選択したパラメータが間違った場合、システム起動時にcloud-initサービスを自動的に開始できません。
CentOS6以前の旧バージョンではsysvinitを選択し、CentOS 7以降のバージョンではsystemdを選択してください。このドキュメントでは、例としてsystemdを使用します。

cloud-init設定ファイルの変更

1. OSの違いに応じて、cloud.cfgをダウンロードします。
Ubuntu OSのcloud.cfgをダウンロードするには、ここをクリックしてください
CentOSのcloud.cfgをダウンロードするには、ここをクリックしてください
2. /etc/cloud/cloud.cfg の内容を、ダウンロードしたcloud.cfgファイルの内容に置き換えます。

syslogユーザーの追加

次のコマンドを実行して、syslogユーザーを追加します。
useradd syslog

システムの起動時にcloud-initサービスを自動実行させる方法

OSがsystemdを使用する場合、次のコマンドを実行します。
説明:
OSがsystemdを使用しているかどうかを確認するには、strings /sbin/init | grep "/lib/system"コマンドを実行できます。メッセージが返された場合は、OSがsystemdを使用していることを意味します。
OSがUbuntuまたはDebianの場合は、次のコマンドを実行する必要があります。
ln -s /usr/local/bin/cloud-init /usr/bin/cloud-init
すべてのOSは、次のコマンドを実行する必要があります。
systemctl enable cloud-init-local.service
systemctl start cloud-init-local.service
systemctl enable cloud-init.service
systemctl start cloud-init.service
systemctl enable cloud-config.service
systemctl start cloud-config.service
systemctl enable cloud-final.service
systemctl start cloud-final.service
systemctl status cloud-init-local.service
systemctl status cloud-init.service
systemctl status cloud-config.service
systemctl status cloud-final.service
OSがCentOSまたはRedhatの場合は、次のコマンドを実行する必要があります。 /lib/systemd/system/cloud-init-local.service ファイルを以下の内容に置き換えます:
[Unit]
Description=Initial cloud-init job (pre-networking)
Wants=network-pre.target
After=systemd-remount-fs.service
Before=NetworkManager.service
Before=network-pre.target
Before=shutdown.target
Conflicts=shutdown.target
RequiresMountsFor=/var/lib/cloud
[Service]
Type=oneshot
ExecStart=/usr/bin/cloud-init init --local
ExecStart=/bin/touch /run/cloud-init/network-config-ready
RemainAfterExit=yes
TimeoutSec=0
# Output needs to appear in instance console output
StandardOutput=journal+console
[Install]
WantedBy=cloud-init.target
/lib/systemd/system/cloud-init.service ファイルを以下の内容に置き換えます:
[Unit]
Description=Initial cloud-init job (metadata service crawler)
Wants=cloud-init-local.service
Wants=sshd-keygen.service
Wants=sshd.service
After=cloud-init-local.service
After=systemd-networkd-wait-online.service
After=networking.service
After=systemd-hostnamed.service
Before=network-online.target
Before=sshd-keygen.service
Before=sshd.service
Before=systemd-user-sessions.service
Conflicts=shutdown.target
[Service]
Type=oneshot
ExecStart=/usr/bin/cloud-init init
RemainAfterExit=yes
TimeoutSec=0
# Output needs to appear in instance console output
StandardOutput=journal+console
[Install]
WantedBy=cloud-init.target
OSがsystemdを使用する場合、次のコマンドを実行します。
説明:
OSがsystemdを使用しているかどうかを確認するには、strings /sbin/init | grep "sysvinit"コマンドを実行できます。メッセージが返された場合は、OSがsysvinitを使用していることを意味します。
chkconfig --add cloud-init-local
chkconfig --add cloud-init
chkconfig --add cloud-config
chkconfig --add cloud-final
chkconfig cloud-init-local on
chkconfig cloud-init on
chkconfig cloud-config on
chkconfig cloud-final on

cloud-initのインストール

次のコマンドを実行して、cloud-initをインストールします。
apt-get/yum install cloud-init
説明:
デフォルトでは、apt-getまたはyumコマンドでインストールされるcloud-initは、現在のOSで設定されたソフトウェアソース中のデフォルトcloud-initバージョンを使用します。 この方法でインストールされたイメージを使用して作成したインスタンスは、一部の設定項目が予想通りに初期化されない可能性があるため、 手動でcloud-initソースコードパッケージをダウンロード してサービスをインストールすることをお勧めします。

cloud-init設定ファイルの変更

1. OSの違いに応じて、cloud.cfgをダウンロードします。
Ubuntu OSのcloud.cfgをダウンロードするには、ここをクリックしてください
CentOSのcloud.cfgをダウンロードするには、ここをクリックしてください
2. /etc/cloud/cloud.cfg の内容を、ダウンロードしたcloud.cfgファイルの内容に置き換えます。

関連する操作

ご注意:
以下の操作が完了した後、サーバーを再起動しないでください。再起動した場合は、以下の操作を再実行する必要があります。
1. 次のコマンドを実行して、cloud-initが正しく設定されているかどうかを確認します。
cloud-init init --local
次のようなメッセージが返却された場合、cloud-initの設定が完了したことがわかります。
Cloud-init v. 20.1.0011 running 'init-local' at Fri, 01 Apr 2022 01:26:11 +0000. Up 38.70 seconds.
2. 次のコマンドを実行し、cloudinitのキャッシュをクリアします。
rm -rf /var/lib/cloud
3. Ubuntu OSまたはDebian OSについて、以下のコマンドを実行します。
rm -rf /etc/network/interfaces.d/50-cloud-init.cfg
4. Ubuntu OSまたはDebian OSの場合、/etc/network/interfacesの内容を次のように変更します:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*

付録

Python-pipがインストールできない時の解決法

インストール中に「インストールに失敗しました」や「インストールパッケージが見つかりません」などのエラーが発生した場合は、ご使用のOSに基づいて次のようにトラブルシューティングを行います。
CentOS 6/7の場合
Ubuntu の場合
1. 次のコマンドを実行して、EPELストレージリポジトリを設定します。
yum install epel-release -y
2. 次のコマンドを実行して、Python-pipをインストールします。
yum install python3-pip -y
1. 次のコマンドを実行して、キャッシュを消去します。
apt-get clean all
2. 次のコマンドを実行して、ソフトウェアパッケージリストを更新します。
apt-get update -y
3. 次のコマンドを実行して、Python-pipをインストールします。
apt-get -y install python3-pip

この記事はお役に立ちましたか?
営業担当者に お問い合わせ いただくか チケットを提出 してサポートを求めることができます。
はい
いいえ

フィードバック