CentOS Stream 8
Sponsored Link

KVM : SPICE サーバーの設定2021/03/10

 
デスクトップ仮想化 SPICE ( Simple Protocol for Independent Computing Environment ) をインストールし、仮想マシンにリモート接続できるようにします。接続先ホストが待ち受けるのではなく、KVM ホスト側で仮想マシンへの接続を待ち受けるため、接続先の仮想マシンのネットワークはつながっていなくとも、KVM ホストさえネットワークにつながっていれば仮想マシンへリモート接続できます。
[1] 通常は依存関係でインストールされていますが、もしインストールされていない場合は SPICE サーバーをインストールします。
[root@dlp ~]#
dnf -y install spice-server

[2] 既存の仮想マシンの設定ファイルを編集して SPICE 対応で起動します。
当サイトの仮想マシン作成例と同様に作成した場合、グラフィクスなしで作成しているため以下の変更のみで OK ですが、グラフィクスありで作成した場合は、設定ファイル中の、<graphics>~ と <video>~ のセクションは削除して以下のように変更します。
ちなみに、当例は SPICE サーバーの設定例ですが、下例で指定している [graphics type='spice' ***] の箇所を [graphics type='vnc' ***] とすると、VNC で接続可能です。
# 仮想マシンの設定編集

[root@dlp ~]#
virsh edit centos-st8
<domain type='kvm'>
  <name>centos-st8</name>
  <uuid>6847e863-be2d-4055-97b4-0eccd59f944d</uuid>
  <metadata>
    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domm
ain/1.0">
      <libosinfo:os id="http://centos.org/centos-stream/8"/>
    </libosinfo:libosinfo>
  </metadata>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-rhel8.2.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  .....
  .....
    # 以下のように追記
    # [passwd=***] は任意のパスワードを設定
    # [slot='0x0*'] は他と重複しない任意の番号を指定
    <graphics type='spice' port='5900' autoport='no' listen='0.0.0.0' passwd='password'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </sound>
    <video>
      <model type='qxl' ram='65536' vram='32768' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
    </memballoon>
    <rng model='virtio'>
      <backend model='random'>/dev/urandom</backend>
      <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
    </rng>
  </devices>
</domain>

Domain centos-st8 XML configuration edited.

[root@dlp ~]#
virsh start centos-st8

Domain centos-st8 started
[3] Firewalld を有効にしている場合は、必要に応じて、割り当てるポートの許可が必要です。
[root@dlp ~]#
firewall-cmd --add-port=5900-5910/tcp --permanent

[root@dlp ~]#
firewall-cmd --reload

[4]
以上で SPICE 対応での仮想マシン起動は完了です。SPICE クライアントからの接続は次項を参照ください
[5] 仮想マシン作成時から SPICE を有効にしたいのであれば、以下のように指定します。
Windows のようにインストールに GUI が必要な OS をインストールする際に、KVM ホストマシンに GUI 環境を用意しなくとも、SPICE 有効で起動すればインストールできます。
なお、VNC 接続の場合は、[spice] を [vnc] に置換するのみです。
[root@dlp ~]#
virt-install \
--name Win2k19 \
--ram 6144 \
--disk path=/var/kvm/images/Win2k19.img,size=100 \
--vcpus 4 \
--os-variant win2k19 \
--network bridge=br0 \
--graphics spice,listen=0.0.0.0,password=password,keymap=ja \
--video qxl \
--cdrom /tmp/Win2019_JA-JP.ISO
関連コンテンツ