CentOS Stream 9
Sponsored Link

KVM : VirtualBMC を利用する2022/02/07

 
VirtualBMC をインストールして、IPMI コマンドで仮想マシンが操作できるようにします。
VirtualBMC でサポートされている IPMI コマンドの操作はごく一部ですが、電源のオンオフが可能なため、便利な場合もあります。
[1] KVM ホストで VirtualBMC をインストールします。
# [/opt/virtualbmc] 配下に Python 仮想環境を作成

[root@dlp ~]#
python3 -m venv --system-site-packages /opt/virtualbmc
# VirtualBMC インストール

[root@dlp ~]#
/opt/virtualbmc/bin/pip3 install virtualbmc
# systemd 設定ファイル作成

[root@dlp ~]#
vi /usr/lib/systemd/system/virtualbmc.service
# 新規作成

[Unit]
Description=Virtual BMC Service
After=network.target libvirtd.service

[Service]
Type=simple
ExecStart=/opt/virtualbmc/bin/vbmcd --foreground
ExecStop=/bin/kill -HUP $MAINPID
User=root
Group=root

[Install]
WantedBy=multi-user.target

[root@dlp ~]#
systemctl daemon-reload

[root@dlp ~]#
systemctl enable --now virtualbmc.service
# 動作確認 (エラーがでなければ問題なし)

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc list
[2] 仮想マシンに VirtualBMC を設定します。
[root@dlp ~]#
virsh list --all

 Id   Name         State
-----------------------------
 -    centos-st9   shut off
 -    rx-7         shut off
 -    rx-8         shut off

# [rx-7] に VirtualBMC を設定
# [port], [username], [password] は任意の値で OK

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc add rx-7 --port 6230 --username vbmcadmin --password adminpassword
[root@dlp ~]#
/opt/virtualbmc/bin/vbmc list

+-------------+--------+---------+------+
| Domain name | Status | Address | Port |
+-------------+--------+---------+------+
| rx-7        | down   | ::      | 6230 |
+-------------+--------+---------+------+

# VirtualBMC 起動

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc start rx-7
[root@dlp ~]#
/opt/virtualbmc/bin/vbmc list

+-------------+---------+---------+------+
| Domain name | Status  | Address | Port |
+-------------+---------+---------+------+
| rx-7        | running | ::      | 6230 |
+-------------+---------+---------+------+

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc show rx-7

+-----------------------+----------------+
| Property              | Value          |
+-----------------------+----------------+
| active                | True           |
| address               | ::             |
| domain_name           | rx-7           |
| libvirt_sasl_password | ***            |
| libvirt_sasl_username | None           |
| libvirt_uri           | qemu:///system |
| password              | ***            |
| port                  | 6230           |
| status                | running        |
| username              | vbmcadmin      |
+-----------------------+----------------+

# VirtualBMC 経由で [rx-7] のパワーステータス確認

[root@dlp ~]#
ipmitool -I lanplus -H 127.0.0.1 -p 6230 -U vbmcadmin -P adminpassword power status

Chassis Power is off
# 起動

[root@dlp ~]#
ipmitool -I lanplus -H 127.0.0.1 -p 6230 -U vbmcadmin -P adminpassword power on

Chassis Power Control: Up/On
[root@dlp ~]#
virsh list --all

 Id   Name         State
-----------------------------
 1    rx-7         running
 -    centos-st9   shut off
 -    rx-8         shut off

# 停止

[root@dlp ~]#
ipmitool -I lanplus -H 127.0.0.1 -p 6230 -U vbmcadmin -P adminpassword power off

Chassis Power Control: Down/Off
[root@dlp ~]#
virsh list --all

 Id   Name         State
-----------------------------
 -    centos-st9   shut off
 -    rx-7         shut off
 -    rx-8         shut off
[3] KVM ホストからではなく、他ホストから VirtualBMC を利用する場合は以下のように設定します。
以下で、SSH 鍵をセットした後は、SSH の設定を [PermitRootLogin prohibit-password] に変更しておいた方がよいでしょう。
# SSH 鍵を生成して自ホストにセット

[root@dlp ~]#
ssh-keygen -q -N ""

Enter file in which to save the key (/root/.ssh/id_rsa):
[root@dlp ~]#
mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

[root@dlp ~]#
ssh 10.0.0.30 hostname

dlp.srv.world
[root@dlp ~]#
virsh list --all

 Id   Name         State
-----------------------------
 1    rx-7         running
 -    centos-st9   shut off
 -    rx-8         shut off

# [rx-8] に VirtualBMC を設定
# [--libvirt-uri] は KVM ホストを指定

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc add rx-8 --port 6231 --username vbmcadmin --password adminpassword --libvirt-uri qemu+ssh://root@10.0.0.30/system

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc start rx-8
[root@dlp ~]#
/opt/virtualbmc/bin/vbmc list

+-------------+---------+---------+------+
| Domain name | Status  | Address | Port |
+-------------+---------+---------+------+
| rx-7        | running | ::      | 6230 |
| rx-8        | running | ::      | 6231 |
+-------------+---------+---------+------+

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc show rx-8

+-----------------------+----------------------------------+
| Property              | Value                            |
+-----------------------+----------------------------------+
| active                | True                             |
| address               | ::                               |
| domain_name           | rx-8                             |
| libvirt_sasl_password | ***                              |
| libvirt_sasl_username | None                             |
| libvirt_uri           | qemu+ssh://root@10.0.0.30/system |
| password              | ***                              |
| port                  | 6231                             |
| status                | running                          |
| username              | vbmcadmin                        |
+-----------------------+----------------------------------+

# Firewalld 稼働中の場合は 設定したポートを許可

[root@dlp ~]#
firewall-cmd --add-port=6231/udp

[root@dlp ~]#
firewall-cmd --runtime-to-permanent


# 以上で設定完了
# なお KVM ホストで生成した SSH 鍵のプライベートキー [id_rsa] は事前に VirtualBMC を操作したいホストに要転送
# 例として [rx-7] ホストから [rx-8] を [ipmitool] で操作
# 事前に KVM ホストのプライベートキー [id_rsa] を取得済み

[root@rx-7 ~]#
ll .ssh

total 8
-rw-------. 1 root root 2602 Feb  4 19:04 id_rsa
-rw-r--r--. 1 root root  171 Feb  4 19:04 known_hosts
[root@rx-7 ~]#
ssh 10.0.0.30 hostname

dlp.srv.world
[root@rx-7 ~]#
ipmitool -I lanplus -H 10.0.0.30 -p 6231 -U vbmcadmin -P adminpassword power status

Chassis Power is off
[root@rx-7 ~]#
ipmitool -I lanplus -H 10.0.0.30 -p 6231 -U vbmcadmin -P adminpassword power on

Chassis Power Control: Up/On
[root@rx-7 ~]#
ssh 10.0.0.30 "virsh list"

 Id   Name   State
----------------------
 1    rx-7   running
 2    rx-8   running
関連コンテンツ