Jaybanuan's Blog

どうせまた調べるハメになることをメモしていくブログ

VyOSのNATでポートフォワード

VyOSのNATでのポートフォワードの設定方法について。 eth0へのポート10022へのアクセスに対して、192.168.9.2のポート22に転送する設定は以下。

$ configure
# set nat destination rule '10' inbound-interface 'eth0'
# set nat destination rule '10' destination port '10022'
# set nat destination rule '10' protocol 'tcp'
# set nat destination rule '10' translation address '192.168.9.2'
# set nat destination rule '10' translation port '22'
# commit
# save

作業後の設定情報は以下。

$ show configuration
(略)
nat {
    destination {
        rule 10 {
            destination {
                port 10022
            }
            inbound-interface eth0
            protocol tcp
            translation {
                address 192.168.9.2
                port 22
            }
        }
    }
(略)

参考

VyOSにSSHの鍵認証でログイン

以下の公開鍵があるとする。

$ cat id_rsa.pub
ssh-rsa AAAAB3Nz....

ユーザvyosに対して、この公開鍵を利用してSSHの鍵認証でログインできるようにする。 作業前の設定情報は以下。

$ show configuration
(略)
    login {
        user vyos {
            authentication {
                encrypted-password ****************
                plaintext-password ****************
            }
            level admin
        }
    }
(略)

設定するには、以下のコマンドを実行する。

$ configure
# set system login user 'vyos' authentication public-keys 'admin' key 'AAAAB3Nz....'
# set system login user 'vyos' authentication public-keys 'admin' type 'ssh-rsa'                                                             
# commit
# save

識別子(上記ではadmin)は、任意の文字列でよいはず。 作業後の設定情報は以下。

$ show configuration
(略)
    login {
        user vyos {
            authentication {
                encrypted-password ****************
                plaintext-password ****************
                public-keys admin {
                    key ****************
                    type ssh-rsa
                }
            }
            level admin
        }
    }
(略)

参考

ESXiの環境にVyOSを利用してプライベートネットワークを構築

はじめに

ESXiの環境にVyOSを利用してプライベートネットワークを構築したときの手順を残しておく。 ただし、ESXiの話を盛り込むとややこしくなるので、ここではVyOSの構築手順に絞る。 まず、次のようなネットワーク192.168.8.0/24があったとする。

                (Internet)
                     |
                     |
                +----+----+
                | Gateway |
                | DNS     |
                |         |
                +----+----+
                     | 192.168.8.1
192.168.8.0/24       |
            o--------+------------------o

ここで、VyOSを利用して以下のようなプライベートネットワーク192.168.9.0/24を構築する。 なお、結線(仮想スイッチやポートグループの設定)は完了しているとする。

                (Internet)
                     |
                     |
                +----+----+
                | Gateway |
                | DNS     |
                |         |
                +----+----+
                     | 192.168.8.1
192.168.8.0/24       |
            o--------+----+-------------o
                          |
                          | 192.168.8.21
                     +-[eth0]--+
                     | NAT     |
                VyOS | DHCP    |
                     | DNS(FWD)|
                     +-[eth1]--+
                          | 192.168.9.1
192.168.9.0/24            |
            o-----+-------+-------+-----o
                  |               |     
                  |               |     
             +----+----+     +----+----+
             | DHCP    |     | DHCP    |
             | Client  |     | Client  |
             |         |     |         |
             +---------+     +---------+

VyOSのVMの構築

以下のVyOSのサイトからISOファイルあるいはVMイメージをダウンロードし、VyOSのVMを構築する。 今回はVyOS 1.1.8のVMイメージ(.ova)を利用した。

初期状態の確認

ESXiのVMのコンソールからユーザvyos(パスワードもvyos)でVyOSにログインする。 コマンドshow configurationを実行し、初期状態を確認する。 eth0はDHCPとなっており、SSHも有効化されていないことが分かる。

$ show configuration
interfaces {
    ethernet eth0 {
        address dhcp
        duplex auto
        hw-id 00:0c:29:75:f1:58
        smp_affinity auto
        speed auto
    }
    ethernet eth1 {
        duplex auto
        hw-id 00:0c:29:75:f1:62
        smp_affinity auto
        speed auto
    }
    loopback lo {
    }
}
system {
    config-management {
        commit-revisions 100
    }
    console {
    }
    host-name vyos
    login {
        user vyos {
            authentication {
                encrypted-password ****************
                plaintext-password ****************
            }
            level admin
        }
    }
    ntp {
        server 0.pool.ntp.org {
        }
        server 1.pool.ntp.org {
        }
        server 2.pool.ntp.org {
        }
    }
    package {
        auto-sync 1
        repository community {
            components main
            distribution helium
            password ****************
            url http://packages.vyos.net/vyos
            username ""
        }
    }
    syslog {
        global {
            facility all {
                level notice
            }
            facility protocols {
                level debug
            }
        }
    }
    time-zone UTC
}

SSHの設定

多数の設定コマンドの入力を(コピペできない)コンソールから行うのは辛いので、最初にSSHでリモートから接続できる程度の、最小限の設定を行う。

$ configure
# delete interfaces ethernet 'eth0' address 'dhcp'
# set interfaces ethernet 'eth0' address '192.168.8.21/24'
# set service ssh port 22
# commit
# save
# exit
$

まず最初にDHCPの設定を削除している点に注意する。 これがないと、コミットしたときに以下のエラーが発生して、コミットに失敗する。

# commit
[ interfaces ethernet eth0 address 192.168.8.21/24 ]
Can't configure static IPv4 address and DHCP on the same interface.

残りの設定

残りの設定は、他のマシンからSSHで接続して実施する。

$ ssh vyos@192.168.8.21

sshでの接続が成功したならば、以下のように設定を入力する。 入力するコマンドは読めば大体分かると思うので、細かい説明は省略する。

$ configure

# set interfaces ethernet 'eth1' address '192.168.9.1/24'

# set system host-name 'sw'
# set system gateway-address '192.168.8.1'

# set system name-server '192.168.8.1'
# set service dns forwarding system
# set service dns forwarding listen-on 'eth1'
# set service dns forwarding listen-on 'lo'

# set service dhcp-server shared-network-name 'nw1' authoritative 'enable'
# set service dhcp-server shared-network-name 'nw1' subnet '192.168.9.0/24' default-router '192.168.9.1'
# set service dhcp-server shared-network-name 'nw1' subnet '192.168.9.0/24' dns-server '192.168.9.1'
# set service dhcp-server shared-network-name 'nw1' subnet '192.168.9.0/24' start '192.168.9.128' stop '192.168.9.254'

# set nat source rule '10' source address '192.168.9.0/24'
# set nat source rule '10' outbound-interface 'eth0'
# set nat source rule '10' translation address 'masquerade'

# commit
# save
# exit

設定の確認

再びshow configurationを実行して、設定が反映されていることを確認する。

$ show configuration
interfaces {
    ethernet eth0 {
        address 192.168.8.21/24
        duplex auto
        hw-id 00:0c:29:75:f1:58
        smp_affinity auto
        speed auto
    }
    ethernet eth1 {
        address 192.168.9.1/24
        duplex auto
        hw-id 00:0c:29:75:f1:62
        smp_affinity auto
        speed auto
    }
    loopback lo {
    }
}
nat {
    source {
        rule 10 {
            outbound-interface eth0
            source {
                address 192.168.9.0/24
            }
            translation {
                address masquerade
            }
        }
    }
}
service {
    dhcp-server {
        disabled false
        shared-network-name nw1 {
            authoritative enable
            subnet 192.168.9.0/24 {
                default-router 192.168.9.1
                dns-server 192.168.9.1
                lease 86400
                start 192.168.9.128 {
                    stop 192.168.9.254
                }
            }
        }
    }
    dns {
        forwarding {
            cache-size 150
            listen-on eth1
            listen-on lo
            system
        }
    }
    ssh {
        port 22
    }
}
system {
    config-management {
        commit-revisions 100
    }
    console {
    }
    gateway-address 192.168.8.1
    host-name sw
    login {
        user vyos {
            authentication {
                encrypted-password ****************
                plaintext-password ****************
            }
            level admin
        }
    }
    name-server 192.168.8.1
    ntp {
        server 0.pool.ntp.org {
        }
        server 1.pool.ntp.org {
        }
        server 2.pool.ntp.org {
        }
    }
    package {
        auto-sync 1
        repository community {
            components main
            distribution helium
            password ****************
            url http://packages.vyos.net/vyos
            username ""
        }
    }
    syslog {
        global {
            facility all {
                level notice
            }
            facility protocols {
                level debug
            }
        }
    }
    time-zone UTC
}

VMware OVF Toolを利用してESXi 6.7からVMをエクスポート

はじめに

VMware OVF Toolというコマンドラインツールを利用して、ESXi 6.7からVMをエクスポートする手順を記しておく。

作業マシンの準備

VMのエクスポートの作業を実施するマシンを準備する。 ここでは、Ubuntu 18.04を利用する。

$ uname -srvm
Linux 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64

VMware OVF Toolのインストール

VMのエクスポート用のツール「VMware OVF Tool」を作業マシンにインストールする。 まずは、以下のWebサイトからダウンロードする。

執筆時点の最新版はRelease 4.3.0だった。 「VMware OVF Tool for Linux 64-bit」を選択すると、「VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle」というファイル名でインストーラがダウンロードされる。 このファイルに実行権限を与えておく。

$ chmod a+x VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle

このインストーラは、GUICUIに対応している。 このインストーラを引数なしで実行するとGUIが起動するが、ここでは詳細は割愛する。 CUIでインストールする場合は、オプション--consoleを付与して以下のようにコマンドを実行する。

$ sudo ./VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle --console
Extracting VMware Installer...done.
You must accept the VMware OVF Tool component for Linux End User
License Agreement to continue.  Press Enter to proceed. ←●Enterを入力
VMWARE END USER LICENSE AGREEMENT

PLEASE NOTE THAT THE TERMS OF THIS END USER LICENSE AGREEMENT SHALL GOVERN YOUR
USE OF THE SOFTWARE, REGARDLESS OF ANY TERMS THAT MAY APPEAR DURING THE
INSTALLATION OF THE SOFTWARE.
(略)

Do you agree? [yes/no]: yes ←●「yes」を入力

The product is ready to be installed.  Press Enter to begin
installation or Ctrl-C to cancel.

Installing VMware OVF Tool component for Linux 4.3.0
    Configuring...
[######################################################################] 100%
Installation was successful.

一応、以下のように実行することで、CUIでサイレントインストールすることができる。

$ sudo ./VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle --console --eulas-agreed --required
Extracting VMware Installer...done.
Installing VMware OVF Tool component for Linux 4.3.0
    Configuring...
[######################################################################] 100%
Installation was successful.

「一応」と書いたのは、オプション--requiredが「必須の入力項目のみプロンプトを表示する」というものであり、このインストーラはたまたま必須の入力項目がなかっただけのように思えるから。

VMのエクスポート

まずはコマンドovftoolのヘルプを表示してみる。

$ ovftool --help
Usage: ovftool [options] <source> [<target>]
where
<source>: Source URL locator to an OVF package, VMX file, or virtual machine in
          vCenter or on ESX Server. 
<target>: Target URL locator which specifies either a file location, or a 
          location in the vCenter inventory or on an ESX Server. 
(以下略)

VMをエクスポートする場合、<source>はESXi上のVMを示すURIに、<target>は出力先のローカルの.ovaファイルを指定することになる。 <source>について、ESXiに直接接続する場合のURIのフォーマットは以下の通り。

vi://[ユーザ名]:[パスワード]@[ESXiホスト]/[VMの名前]

これは妥当なURIでなければならないので、必要に応じてパーセントエンコードする必要がある。 特にパスワードには記号が含まれる場合が多いので、注意が必要になる。 エンコードの方法は色々あるが、Pythonでパスワード「Hello,World!」をエンコードする例は以下のようになる。

$ python3 -c 'import urllib.parse; import os; print(urllib.parse.quote_plus("Hello,World!"))'
Hello%2CWorld%21

これを受けて、例えば以下の環境では、

項目
ユーザ名 root
パスワード Hello,World!
ESXiホスト 192.168.8.20
VMの名前 test-vm

<source>URIは以下になる。

vi://root:Hello%2CWorld%21@192.168.8.20/test-vm

これでコマンドを組み立てる準備が整った。 以下のようにコマンドovftoolを実行する。

$ ovftool vi://root:Hello%2CWorld%21@192.168.8.20/test-vm exported-vm.ova
Accept SSL fingerprint (23:E5:B3:5E:26:16:88:44:8B:DC:F1:DC:97:C7:D8:35:8B:3D:FE:08) for host 192.168.8.20 as source type.
Fingerprint will be added to the known host file
Write 'yes' or 'no'
yes ←●「yes」を入力
Opening VI source: vi://root@192.168.8.20:443/test-vm
Opening OVF target: exported-vm.ovf
Writing OVF package: exported-vm.ovf
Transfer Completed                    
Completed successfully

SSLのフィンガープリントの保存のプロンプトを抑止したければ、以下のようにオプション--noSSLVerifyを付与してovftoolを実行すればよい。

$ ovftool --noSSLVerify vi://root:Hello%2CWorld%21@192.168.8.20/test-vm exported-vm.ova

コマンドが成功すると、ファイルexported-vm.ovaが生成されている。

動作確認 (ovftoolを利用)

以下のようにコマンドovftoolを実行して、exported-vm.ovaがインポートできることを確認する。

$ ovftool --noSSLVerify exported-vm.ova vi://root:Hello%2CWorld%21@192.168.8.20
Opening OVA source: exported-vm.ova
The manifest validates
Opening VI target: vi://root@192.168.8.20:443/
Deploying to VI: vi://root@192.168.8.20:443/
Transfer Completed                    
Completed successfully

コマンドが成功すると、exported-vmという名前のVMが作成されている。

動作確認 (Embedded Web Clientを利用)

生成されたexported-vm.ovaをEmbedded Web Clientを利用してインポートしようとすると、以下のような「必要なディスクイメージが見つかりませんでした」という謎のエラーメッセージが表示される。

f:id:redj:20190208021258p:plain

一応インポートは成功するのだが、なんとも気持ちが悪い。 試行錯誤してみたところ、exported-vm.ovaの中に含まれるexported-vm.ovfの中の、nvramファイル関連の要素が影響していることが分かった。

<?xml version="1.0" encoding="UTF-8"?>
<Envelope ... >
  <References>
    <File ovf:href="exported-vm-disk1.vmdk" ovf:id="file1" ovf:size="655692288"/>
    <File ovf:href="exported-vm-file1.nvram" ovf:id="file2" ovf:size="8684"/> ←●これ
(略)
      <vmw:ExtraConfig ovf:required="false" vmw:key="nvram" vmw:value="ovf:/file/file2"/> ←●これ
    </VirtualHardwareSection>
  </VirtualSystem>
</Envelope>

ネットで公開されているova形式のVMをいくつか見てみたが、どうもnvramは必須ではないように思える。 なので、これらの要素を削除して、exported-vm.ovaを再作成してみる

$ ovftool exported-vm.ova exported-vm.ovf
Opening OVA source: exported-vm.ova
The manifest validates
Opening OVF target: exported-vm.ovf
Writing OVF package: exported-vm.ovf
Transfer Completed                    
Completed successfully

$ sed -i -e '/nvram/d' exported-vm.ovf

$ rm exported-vm-file1.nvram

$ rm exported-vm.mf

$ ovftool exported-vm.ovf exported-vm-modified.ova
Opening OVF source: exported-vm.ovf
Opening OVA target: exported-vm-modified.ova
Writing OVA package: exported-vm-modified.ova
Transfer Completed                    
Warning:
 - No manifest file found.
 - No manifest entry found for: 'exported-vm-disk1.vmdk'.
Completed successfully

このexported-vm-modified.ovaはエラーなくEmbedded Web Clientでインポートできた。 ただ、ovftoolではnvramを削除しなくても正常にインポートできているし、ESXi 6.5のときのEmbedded Web Clientはバグが多すぎて使い物にならなかったという経験もあるので、この現象はEmbedded Web Clientのバグのように思える。

参考

OVF Toolのインストーラのヘルプ

$ ./VMware-ovftool-4.3.0-7948156-lin.x86_64.bundle --console --help
Extracting VMware Installer...done.
Usage: vmware-installer [options]

VMware Installer

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit

  Manage:
    Install or uninstall products

    -i FILE, --install-bundle=FILE
                        Install bundle from FILE
    --install-component=FILE
                        Install a component
    --uninstall-component=NAME
                        Force uninstallation of a component
    -u NAME, --uninstall-product=NAME
                        Uninstall a product
    -r, --resolve-system
                        Force the system to resolve the current state
    --register-file=COMPONENT_NAME (config|regular) FILE
                        Register a file in the database
    -x DIR, --extract=DIR
                        Extract the contents of the bundle into DIR
    -p DIR, --prefix=DIR
                        Set a custom install location

  Information:
    Look up information on installed products

    -l, --list-products
                        List installed products
    -t, --list-components
                        List the installed components
    -L COMPONENT, --list-files=COMPONENT
                        List files for a given component
    -S FILE, --find-file=FILE
                        List components and files matching the given pattern

  Settings:
    Set and retrieve settings

    -g COMPONENT KEY, --get-setting=COMPONENT KEY
                        Get setting
    -s COMPONENT KEY VALUE, --set-setting=COMPONENT KEY VALUE
                        Set setting
    -d COMPONENT KEY, --delete-setting=COMPONENT KEY
                        Delete setting

  Options:
    --gtk               Use the Gtk+ UI (Default)
    --console           Use the console UI
    --custom            Allow customization of the install, including file
                        locations.
    --regular           Displays questions that have no good defaults
                        (Default)
    --required          Displays only questions absolutely required
    -I, --ignore-errors
                        Ignore component script errors
    --eulas-agreed      Agree to the EULA

コマンドovftoolのヘルプ

$ ovftool --help
Usage: ovftool [options] <source> [<target>]
where
<source>: Source URL locator to an OVF package, VMX file, or virtual machine in
          vCenter or on ESX Server. 
<target>: Target URL locator which specifies either a file location, or a 
          location in the vCenter inventory or on an ESX Server. 

If <target> is not specified, information about the source is displayed to the 
console. 

Options:
     --acceptAllEulas            : Accept all end-user licenses agreements 
                                   without being prompted. 
     --allowAllExtraConfig       : Whether we allow all the ExtraConfig 
                                   options. These options are a security risk 
                                   as they control low-level and potential 
                                   unsafe options on the VM. 
     --allowExtraConfig          : Whether we allow ExtraConfig options. These 
                                   options are a security risk as they control 
                                   low-level and potential unsafe options on 
                                   the VM. 
     --annotation                : Add annotation to vi, vmx, vapprun, vCloud, 
                                   OVF, and OVA source locators 
     --authdPortSource           : Use this to override default vmware authd 
                                   port (902) when using a host as source. 
     --authdPortTarget           : Use this to override default vmware authd 
                                   port (902) when using a host as target. 
     --chunkSize                 : Specifies the chunk size to use for files in
                                   a generated OVF package. The default is not 
                                   to chunk. The chunk size without unit is 
                                   assumed to be in megabytes. Accepted units 
                                   are b, kb, mb, gb; e.g., 2gb or 100kb. 
     --compress                  : Compress the disks in an OVF package. Value 
                                   must be between 1 and 9. 1 is the fastest, 
                                   but gives the worst compression, whereas 9 
                                   is the slowest, but gives the best 
                                   compression. 
     --computerName              : Sets the computer name in the guest for a VM
                                   using the syntax --computerName:<VM 
                                   ID>=<value>. Only applies to vCloud targets 
                                   version 5.5 or newer. 
     --coresPerSocket            : Specifies the distribution of the total 
                                   number of CPUs over a number of virtual 
                                   sockets using the syntax 
                                   --coresPerSocket:<VM ID>=<value>. Only 
                                   applies to vCloud targets version 5.5 or 
                                   newer. 
 -ds/--datastore                 : Target datastore name for a VI locator.
     --decodeBase64              : Decode option values with Base64.
     --defaultStorageProfile     : The storage profile for all VMs in the OVF 
                                   package. The value should be an SPBM profile
                                   ID. Only applies to VI targets version 5.5 
                                   or newer. 
     --defaultStorageRawProfile  : The storage profile for all VMs in the OVF 
                                   package. The value should be raw SPBM 
                                   profile. The value will overwrite that in 
                                   --defaultStorageProfile. Only applies to VI 
                                   targets version 5.5 or newer. 
     --deploymentOption          : Selects what deployment option to use (if 
                                   the source OVF package supports multiple 
                                   options.) 
     --disableVerification       : Skip validation of signature and 
                                   certificate. 
 -dm/--diskMode                  : Select target disk format. Supported formats
                                   are: monolithicSparse, monolithicFlat, 
                                   twoGbMaxExtentSparse, twoGbMaxExtentFlat, 
                                   seSparse (VI target), eagerZeroedThick (VI 
                                   target), thin (VI target), thick (VI 
                                   target), sparse, and flat 
     --diskSize                  : Sets the size of a VM disk in megabytes 
                                   using the syntax --diskSize:<VM ID>,<disk 
                                   instance ID>=<value>. Only applies to vCloud
                                   targets version 5.5 or newer. 
     --eula                      : EULA to be inserted in the first virtual 
                                   system or virtual system collection in the 
                                   OVF. If the EULA is in a file, use the 
                                   option --eula@=filename instead. 
     --exportDeviceSubtypes      : Enables export of resource subtype for 
                                   CD/Floppy/Parallel/Serial devices. This can 
                                   limit portability as not all device backings
                                   are supported on all hypervisors. The 
                                   default is false. 
     --exportFlags               : Specifies one or more export flags to 
                                   control what gets exported. The supported 
                                   values for VI sources are mac, uuid, and 
                                   extraconfig. Supported value for vCloud 
                                   sources are preserveIdentity. One or more 
                                   options can be provided, separated by 
                                   commas. 
     --extraConfig               : Sets an ExtraConfig element for all 
                                   VirtualHardwareSections. The syntax is 
                                   --extraConfig:<key>=<value>. Applies to vi, 
                                   vmx, vapprun, vCloud, ovf, and ova source 
                                   locators. 
     --fencedMode                : If a parent network exists on the vCloud 
                                   target, this property specifies the 
                                   connectivity to the parent. Possible values 
                                   are bridged, isolated, and natRouted. 
 -h /--help                      : Prints this message.
     --hideEula                  : In OVF probe mode, hides the EULA.
     --importAsTemplate          : Import VM as a Template when deployed on a 
                                   VI target. 
     --ipAllocationPolicy        : IP allocation policy for a deployed OVF 
                                   package.Supported values are: dhcpPolicy, 
                                   transientPolicy, fixedPolicy, 
                                   fixedAllocatedPolicy. 
     --ipProtocol                : Select what IP protocol to use (IPv4, IPv6).
     --lax                       : Relax OVF specification conformance and 
                                   virtual hardware compliance checks. Use only
                                   if you know what you are doing. 
     --locale                    : Selects locale for target.
     --machineOutput             : Output OVF Tool messages in a machine 
                                   friendly manner. 
     --makeDeltaDisks            : Build delta disk hierarchy from the given 
                                   source locator. 
     --maxVirtualHardwareVersion : The maximal virtual hardware version to 
                                   generate. 
     --memorySize                : Sets the memory size in megabytes of a VM 
                                   using the syntax --memorySize:<VM 
                                   ID>=<value>. Only applies to vCloud targets 
                                   version 5.5 or newer. 
 -n /--name                      : Specifies target name (defaults to source 
                                   name). 
     --net                       : Set a network assignment in the deployed OVF
                                   package. A network assignment is set using 
                                   the syntax --net:<OVF name>=<target name>. 
                                   If the target is vCloud 5.5 or newer, a 
                                   fence mode can also be specified using the 
                                   syntax --net:<OVF name>=<target name>,<fence
                                   mode>. Possible fence mode values are: 
                                   bridged, isolated, and natRouted. 
 -nw/--network                   : Target network for a VI deployment.
     --nic                       : Specifies NIC configuration in a VM using 
                                   the syntax --nic:<VM ID>,<index>=<OVF net 
                                   name>,<isPrimary>,<ipAddressingMode>,<ipAddress>.
                                   Possible values for ipAddressingMode are: 
                                   DHCP, POOL, MANUAL, and NONE. ipAddress is 
                                   optional and should only be used when 
                                   ipAddressingMode is set to MANUAL. Only 
                                   applies to vCloud targets version 5.5 or 
                                   newer. 
     --noDisks                   : Disable disk conversion.
     --noImageFiles              : Do not include image files in destination.
     --noSSLVerify               : Skip SSL verification for VI connections.
     --numberOfCpus              : Sets the number of CPUs for a VM using the 
                                   syntax --numberOfCpus:<VM ID>=<value>. Only 
                                   applies to vCloud targets version 5.5 or 
                                   newer. 
 -o /--overwrite                 : Force overwrites of existing files.
     --powerOffSource            : Ensures a VM/vApp is powered off before 
                                   importing from a VI source. 
     --powerOffTarget            : Ensures a VM/vApp is powered off before 
                                   overwriting a VI target. 
     --powerOn                   : Powers on a VM/vApp deployed on a VI target.
     --privateKey                : Sign OVF package with the given private key 
                                   (.pem file). The file must contain a private
                                   key and a certificate. 
     --privateKeyPassword        : Password for the private key. Should be used
                                   in conjunction with privateKey if the 
                                   private key requires password 
                                   authentication. If required and not 
                                   specified, the tool will prompt for the 
                                   password. 
     --prop                      : Set a property in the deployed OVF package. 
                                   A property is set using the syntax 
                                   --prop:<key>=<value>. 
     --proxy                     : Proxy used for HTTP[S] access.
     --proxyNTLMAuth             : Enable NTLM authentication for proxy.
 -q /--quiet                     : No output to screen except errors.
     --schemaValidate            : Validate OVF descriptor against OVF schema.
     --shaAlgorithm              : Select SHA digest algorithm when creating 
                                   OVF package. Supported values are SHA1, 
                                   SHA256 and SHA512. Default value is SHA256. 
     --skipManifestCheck         : Skip validation of OVF package manifest.
     --skipManifestGeneration    : Skip generation of OVF package manifest.
     --sourcePEM                 : File path to PEM formatted file used to 
                                   verify VI connections. 
     --sourceSSLThumbprint       : SSL fingerprint of SOURCE. OVF Tool verifies
                                   the SSL fingerprint it gets from SOURCE if 
                                   the value is set. 
 -st/--sourceType                : Explicitly express that source is OVF, OVA, 
                                   VMX, VI, vCloud, ISO, FLP, vApprun 
     --sslCipherList             : Use this to override default OpenSSL ciphers
                                   suite. 
     --sslVersion                : Use this to set preferred TLS/SSL version 
                                   for HTTPS connections. The valid values are 
                                   as following: 
                                     TLSv1_0: Set preferred TLS/SSL version to 
                                   TLSv1.0. 
                                     TLSv1_1: Set preferred TLS/SSL version to 
                                   TLSv1.1. 
                                     TLSv1_2: Set preferred TLS/SSL version to 
                                   TLSv1.2. 
     --storageProfile            : Sets the storage profile for a VM using the 
                                   syntax --storageProfile:<VM ID>=<value>. 
                                   Only applies to vCloud targets version 5.5 
                                   or newer. 
     --targetPEM                 : File path to PEM formatted file used to 
                                   verify VI connections. 
     --targetSSLThumbprint       : SSL fingerprint of TARGET. OVF Tool verifies
                                   the SSL fingerprint it gets from TARGET if 
                                   the value is set. 
 -tt/--targetType                : Explicitly express that target is OVF, OVA, 
                                   VMX, VI, vCloud, ISO, FLP, vApprun 
     --vCloudTemplate            : Create only a vApp template. Default value 
                                   is false 
     --vService                  : Set a vService assignment in the deployed 
                                   OVF package. A vService assignment is set 
                                   using the syntax 
                                   --vService:<dependencyId>=<providerId>. 
     --verifyOnly                : Do not upload the source but only verify it 
                                   against the target host. Applies to VI 4 
                                   targets only. 
 -v /--version                   : Prints the version of this tool.
     --viCpuResource             : Specify the CPU resource settings for 
                                   VI-locator targets. The syntax is 
                                   --viCpuResource=<shares>:<reservation>:<limit>.
     --viMemoryResource          : Specify the CPU resource settings for 
                                   VI-locator targets. The syntax is 
                                   --viMemoryResource=<shares>:<reservation>:<limit>.
 -vf/--vmFolder                  : Target VM folder in VI inventory (relative 
                                   to datacenter). 

For more help, type: --help <topic>, where topics are:
 locators    : For detailed source and destination locator syntax
 examples    : For examples of use
 config      : For syntax of configuration files
 debug       : For debug purpose
 integration : For a list of options primarily used when ovftool is exec'ed 
               from another tool or shellscript. 

コマンドovftoolの実行例の表示

$ ovftool --help examples
Source Locator Examples:

   /ovfs/my_vapp.ovf

   /vms/my_vm.vmx

   ~/my_vApprun_workspace/MyVm

   vi://username:pass@localhost/my_datacenter/vm/    \
      my_vms_folder/my_vm_name

Destination Locator Examples:

   /ovfs/my_vapp.ovf

   /vms/my_vm.vmx

   ~/my_vApprun_workspace/MyVM

   vi://username:pass@localhost/my_datacenter/host/    \
      esx01.example.com
   vi://username:pass@localhost/my_datacenter/host/    \
      esx01.example.com/Resources/my_resourcepool

   Note: the /host/ and /Resources/ part of the above inventory path are
         fixed and must be specified when using a vi destination locator.
         The /Resources/ part is only used when specifying a resource
         pool.

Examples:

   ovftool --vService:vDep1=provider_1 /ovfs/my_vapp.ovf
     vi://username:pass@localhost/my_datacenter/host/esx01.example.com
   (specify a vService dependency)

   ovftool -tt=vmx /ovfs/my_vapp.ovf /vms/
   (.ovf file to .vmx file. Result files are /vms/my_vapp/my_vapp.[vmx|vmdk])

   ovftool /vms/my_vm.vmx /ovfs/my_vapp.ovf
   (.vmx file to .ovf file. Result is put in /ovfs/my_vapp.[ovf|vmdk])

   ovftool https://my_ovf_server/ovfs/my_vapp.ova /vm/my_vm.vmx
   (.ova file to .vmx file)

   ovftool /ovfs/my_vapp.ovf vi://username:pass@my_esx_host
   (.ovf file to ESX host using default mappings)

   ovftool /ovfs/my_vm.vmx vi://username:pass@my_esx_host
   (.vmx file to ESX host using default mappings)

   ovftool http://my_ovf_server/ovfs/my_vapp.ovf \
           vi://username:pass@my_esx_host
   (.ovf file from a web server to ESX host using defaults)

   ovftool /ovfs/my_vapp.ovf \
           vi://username:pass@my_vc_server/?ip=10.20.30.40
   (.ovf file to vCenter server using managed ESX host ip address)

   ovftool vi://username:pass@my_vc_server/my_datacenter?ds=\
           [Storage1] foo/foo.vmx c:\ovfs\
   (VM on ESX/vCenter server to OVF using datastore location query)

   ovftool /ovfs/my_vapp.ovf \
           vi://username:pass@my_vc_server/my_datacenter/host/my_host
   (.ovf file to vCenter server using vCenter inventory path)

   ovftool vi://username:pass@my_host/my_datacenter/vm/my_vm_folder/my_vm_name \
           /ovfs/my_vapp.ovf
   (VC/ESX vm to .ovf file)

   ovftool /virtualmachines/MyVM.vmx \
           ~my_vApprun_workspace/ 
   (Imports a .vmx file into a vApprun workspace using default name)

   ovftool https://my_ovflib/vm/my_vapp.ovf
   (shows summary information about the OVF package [probe mode])

   ovftool http://my_ovflib/vm/my_vapp.ovf \
           vcloud://username:pass@my_cloud?org=MyOrg&vdc=MyVDC&catalog=MyCatalog&vapp=myVapp
   (Imports an OVF from http into a vCloud instance and name the vApp myVapp)

    ovftool http://my_ovflib/vm/my_vapp.ovf \
           vcloud://username:pass@my_cloud?org=MyOrg&vdc=MyVDC&catalog=MyCatalog&vappTemplate=myTemplate
   (Imports an OVF from http into a vCloud instance and create vApp template)

   ovftool vi://username:pass@my_host/my_datacenter/vm/my_vm_folder/my_vm_name \
           vcloud://username:pass@my_cloud?org=MyOrg&vdc=MyVDC&catalog=MyCatalog&vapp=myVapp
   (Imports a VM from VI into a vCloud instance and name the vApp myVapp)

   ovftool vcloud://username:pass@my_cloud?org=MyOrg&vdc=MyVDC&catalog=MyCatalog&vapp=myVapp \
           /ovfs/myVapp.ovf
   (Exports a VM from a vCloud instance into an OVF package)

ESXi 6.7でコマンドからVMを作成

はじめに

ESXi 6.7でのVMの作成を自動化したいので、そのための手順とコマンドを調査した。

まず結論

ESXiにsshでログインして、以下のようなスクリプトを実行すればよい。

#!/bin/sh -ue

# (0) パラメータ定義
DATASTORE_PATH=/vmfs/volumes/datastore1
ISO_FILE=/vmfs/volumes/datastore1/iso/CentOS-7-x86_64-DVD-1810.iso
VM_NAME=test-vm
VM_HW_VER=vmx-09
VM_MEM_SIZE=2048
VM_NETWORK_NAME="VM Network"
VM_GUEST_OS=centos-64
VM_CDROM_DEVICETYPE=cdrom-image  # cdrom-image / atapi-cdrom
VM_DISK_SIZE=20g
VM_DISK_PATH=$DATASTORE_PATH/$VM_NAME/$VM_NAME.vmdk
VM_VMX_FILE=$DATASTORE_PATH/$VM_NAME/$VM_NAME.vmx

# (1) ダミーVMの作成
VM_ID=`vim-cmd vmsvc/createdummyvm $VM_NAME $DATASTORE_PATH $VM_HW_VER`

# (2) vmxファイルの編集
sed -i -e '/^guestOS /d' $VM_VMX_FILE
cat << __EOF__ >> $VM_VMX_FILE
guestOS = "$VM_GUEST_OS"
memSize = "$VM_MEM_SIZE"
ethernet0.present = "TRUE"                                       
ethernet0.networkName = "$VM_NETWORK_NAME"                             
ethernet0.addressType = "generated"                              
ethernet0.wakeOnPcktRcv = "FALSE"                                
ide0:0.present = "TRUE"                         
ide0:0.deviceType = "$VM_CDROM_DEVICETYPE"                                
ide0:0.fileName = "$ISO_FILE"
__EOF__

# (3) ディスク容量の拡張
vmkfstools -X $VM_DISK_SIZE $VM_DISK_PATH 

# (4) VMの情報のリロード
vim-cmd vmsvc/reload $VM_ID

以降で各ステップの説明を行う。

(0) パラメータ定義

各種パラメータを変数化しているだけ。

(1) ダミーVMの作成

コマンドvim-cmd vmsvc/createdummyvmを実行して、最小限(ですらない)ダミーのVMを作成し、それのvmxファイルを編集するという手順らしい。 ちなみに、別のコマンドであるPowerCLIにはNew-VMというコマンドレットがあり、ダミーなしで一発でVMを作成できるようだが、残念ながら無償のESXiでは利用できない。 コマンドvim-cmd vmsvc/createdummyvmの使い方は、以下のようにヘルプで確認できる。

$ vim-cmd help vmsvc/createdummyvm
Usage: createdummyvm vm_name datastore_path [hw_version]

Create a pre-configured dummy vm.

パラメータhw_versionには、コマンドvim-cmd solo/querycfgoptdescの出力のkeyの値で、なおかつcreateSupported = trueであるものを指定すればよいようだ。 例えば以下の出力結果の場合は、vmx-04とvmx-07~vmx-14が指定可能である。

$ vim-cmd solo/querycfgoptdesc
(vim.vm.ConfigOptionDescriptor) [
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-03", 
      description = "ESX 2.x virtual machine", 
      host = <unset>, 
      createSupported = false, 
      defaultConfigOption = false, 
      runSupported = false, 
      upgradeSupported = false
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-04", 
      description = "ESX 3.x virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = false, 
      runSupported = true, 
      upgradeSupported = true
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-07", 
      description = "ESX/ESXi 4.x virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = false, 
      runSupported = true, 
      upgradeSupported = true
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-08", 
      description = "ESXi 5.0 virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = false, 
      runSupported = true, 
      upgradeSupported = true
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-09", 
      description = "ESXi 5.1 virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = false, 
      runSupported = true, 
      upgradeSupported = true
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-10", 
      description = "ESXi 5.5 virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = false, 
      runSupported = true, 
      upgradeSupported = true
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-11", 
      description = "ESXi 6.0 virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = false, 
      runSupported = true, 
      upgradeSupported = true
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-12", 
      description = "Workstation 12 virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = false, 
      runSupported = true, 
      upgradeSupported = true
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-13", 
      description = "ESXi 6.5 virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = false, 
      runSupported = true, 
      upgradeSupported = true
   }, 
   (vim.vm.ConfigOptionDescriptor) {
      key = "vmx-14", 
      description = "ESXi 6.7 virtual machine", 
      host = <unset>, 
      createSupported = true, 
      defaultConfigOption = true, 
      runSupported = true, 
      upgradeSupported = true
   }
]

(2) vmxファイルの編集

createdummyvmの実行で、以下の内容のvmxファイルが生成された。

これに対して、ゲストOSとメモリサイズを指定し、NICとCD-ROMドライブを追加。 vmxファイルを編集するためのコマンドはないようなので、 直接編集する。

(3) ディスク容量の拡張

ダミーVMのハードディスクの容量は1MBのサイズしかないので、20GBに拡張しておく。

(4) VMの情報のリロード

vmxファイルを編集したり、ディスクを拡張したりしても、ESXiが保持している管理情報は元のままになっている。 そのため、コマンドvim-cmd vmsvc/reloadを利用して管理情報をリロード(更新)しておく。

ESXi 6.7のパッチの適用手順

はじめに

ESXi 6.7にパッチを適用した際の作業記録を記しておく。 前提となるESXiホストの環境は以下とする。

項目 状態
バージョン 6.7 (パッチ未適用)
IPアドレス 192.168.8.20
ssh接続 enabled

ESXiはVMそのものは安定しているが、周辺ツールにバグが多い印象があり、パッチは適用しておきたい。 しかし、VMWare固有のモジュール管理の仕組みを理解する必要があり、少々ハードルが高い。

用語

VMWareのモジュール管理で利用される用語を理解しておく必要がある。

  • VIB (VMware Infrastructure Bundle)

  • プロファイル

    • 特定の構成のESXiであり、必要なVIBをグループ化したもの。 例えば、「標準のESXi」や「VMWare toolsを含まないESXi」など
  • デポ

    • ひとつ又は複数のプロファイルをまとめてzipファイルにしたもの。 いわゆる「パッチ」はこのzipファイルのこと。

より正確な定義については、以下を参照。

パッチのダウンロード

以下のWebサイトからパッチをダウンロード。

製品は「ESXi (Embedded and Installable)」で、バージョンは「6.7.0」で検索。 執筆時点の最新版はESXi670-201811001で、ESXi670-201811001.zipというファイル名でダウンロードされる。 ちなみに、ハードウェアベンダがプリインストールするものがEmbedded、ユーザがダウンロードしてインストールするものがInstallableらしい。

パッチをデータストアに転送

ここでは以下のようにscpで転送する。

$ scp ESXi670-201811001.zip root@192.168.8.20:/vmfs/volumes/datastore1

データストアブラウザを利用して転送してもよい。

ESXiホストにsshで接続

$ ssh root@192.168.8.20

現在のプロファイルの確認

$ esxcli software profile get
ESXi-6.7.0-8169922-standard
   Name: ESXi-6.7.0-8169922-standard
   Vendor: VMware, Inc.
   Creation Time: 2018-12-15T11:38:01
   Modification Time: 2018-12-15T11:38:31
   Stateless Ready: True
   Description: 
      
      The general availability release of VMware ESXi Server 6.7.0
      brings whole new levels of virtualization performance to
      datacenters and enterprises.

   VIBs: ata-libata-92 3.00.9.2-16vmw.670.0.0.8169922, (以下略)

ここでは、現在のプロファイルが「ESXi-6.7.0-8169922-standard」であることが分かる。

パッチの内容の確認

まずはパッチ(デポ)に含まれるプロファイルのリストを取得する。

$ esxcli software sources profile list -d /vmfs/volumes/datastore1/ESXi670-201811001.zip 
Name                             Vendor        Acceptance Level  Creation Time        Modification Time
-------------------------------  ------------  ----------------  -------------------  -------------------
ESXi-6.7.0-20181104001-no-tools  VMware, Inc.  PartnerSupported  2018-11-08T08:39:27  2018-11-08T08:39:27
ESXi-6.7.0-20181104001-standard  VMware, Inc.  PartnerSupported  2018-11-08T08:39:27  2018-11-08T08:39:27

名前がstandardで終わっているものが標準構成、no-toolsで終わっているものがVMWare tools (のISOイメージ?)を含まない構成。 プロファイルの命名規則などについては以下を参照。

今回は標準構成のESXi-6.7.0-20181104001-standardを適用することにする。 ESXi-6.7.0-20181104001-standardの詳細な内容は、以下のようにコマンドを実行することで確認できる。

$ esxcli software sources profile get -p ESXi-6.7.0-20181104001-standard -d /vmfs/volumes/datastore1/ESXi
670-201811001.zip
ESXi-6.7.0-20181104001-standard
   Acceptance Level: PartnerSupported
   Name: ESXi-6.7.0-20181104001-standard
   Vendor: VMware, Inc.
   Creation Time: 2018-11-08T08:39:27
   Modification Time: 2018-11-08T08:39:27
   Stateless Ready: True
   Description: 
      
      Updates ESXi 6.7 Image Profile-ESXi-6-7-0-20181104001-standard

   VIBs: ata-libata-92 3.00.9.2-16vmw.670.0.0.8169922, (以下略)

パッチの適用

まずは、メンテナンスモードに移行する。

$ vim-cmd hostsvc/maintenance_mode_enter

そして、プロファイルESXi-6.7.0-20181104001-standardを適用する。

$ esxcli software profile update -d /vmfs/volumes/datastore1/ESXi670-201811001.zip -p ESXi-6.7.0-20181104001-standard
Update Result
   Message: The update completed successfully, but the system needs to be rebooted for the changes to be effective.
   Reboot Required: true
   VIBs Installed: VMW_bootbank_bnxtroce_20.6.101.0-20vmw.670.1.28.10302608, (以下略)
   VIBs Removed: VMW_bootbank_brcmfcoe_11.4.1078.0-8vmw.670.0.0.8169922, (以下略)
   VIBs Skipped: VMW_bootbank_ata-libata-92_3.00.9.2-16vmw.670.0.0.8169922, (以下略)

ここで、出力結果で「Reboot Required: true」となっているので、リブートを実行する。

$ reboot

再度sshでESXiのホストに接続し、メンテナンスモードを解除する。

$ vim-cmd hostsvc/maintenance_mode_exit

確認

現在のプロファイルを表示して、アップデートされていることを確認する。

$ esxcli software profile get
(Updated) ESXi-6.7.0-20181104001-standard
   Name: (Updated) ESXi-6.7.0-20181104001-standard
   Vendor: VMware, Inc.
   Creation Time: 2018-12-16T17:42:02
   Modification Time: 2018-12-16T17:42:18
   Stateless Ready: True
   Description: 
      
      2018-12-16T17:42:01.737859+00:00: The following VIBs are
      installed:
        vmkusb        0.1-1vmw.670.1.28.10302608
        vsan  6.7.0-1.31.10720746
        (略)
        lsi-mr3       7.702.13.00-5vmw.670.1.28.10302608
        esx-ui        1.30.0-9946814
      ----------
      The general availability release of VMware ESXi Server 6.7.0
      brings whole new levels of virtualization performance to
      datacenters and enterprises.

   VIBs: ata-libata-92 3.00.9.2-16vmw.670.0.0.8169922, (以下略)

参考

KVM上にESXi 6.7のVMを構築する手順

はじめに

実験のためにESXi 6.7の環境が必要になったので、KVM上にESXi 6.7のVMを構築した。 ここでは、その構築手順を記しておく。 と言っても、KVM固有の手順はあまりなく、ほぼ単にESXiを構築する手順だが。

1. ESXiのISOイメージのダウンロード

以下のWebサイトからダウンロード。 ユーザアカウント(無料)を作成して、ログインする必要がある。

執筆時点での最新版はESXi 6.7.0。 ダウンロードのページで無償利用のためのライセンスキーも表示されるので、控えておく。

2. KVMホストのBIOSIntel VTを有効化

入れ子の仮想化(nested virtualization)になるので、KVMホストのBIOSIntel VTを有効化しておく。 理由は分からないけど、サーバマシンを含めて大抵のマシンではデフォルトではIntel VTは無効化されている。

3. Virt ManagerでESXiの仮想マシンを作成

ここではVirt Managerを利用してESXiの仮想マシンを作成する。 virshでもできるとは思う。

3.1. インストール方法を選択

f:id:redj:20181215232817p:plain

3.2. ESXiのISOイメージを選択

f:id:redj:20181215233052p:plain

3.3. メモリとCPUを指定

f:id:redj:20181215233954p:plain

3.4. ディスクサイズを指定

f:id:redj:20181215234107p:plain

3.5. 名前の指定とカスタマイズの指定

NICを変更する必要があるため、「インストールの前に設定をカスタマイズする」にチェックを入れておく。

f:id:redj:20181215234408p:plain

3.6. NICの変更

NICの設定で「デバイスのモデル」を「e1000」に変更する。 その他のモデルではESXiがNICを認識できなかった。

f:id:redj:20181215235051p:plain

そして「インストールの開始」をクリック。

4. ESXiのインストール

4.1. ESXiのインストールの開始

VMが起動するとブートメニューが表示されるので、「ESXi-6.7.0-8169922-standard Installer」を選択する。

f:id:redj:20181215235829p:plain

4.2. ウェルカム画面

f:id:redj:20181216000021p:plain

4.3. ライセンス許諾

f:id:redj:20181216000311p:plain

4.4. インストール先のディスクの選択

ここではデフォルトのままにしておく。

f:id:redj:20181216000640p:plain

4.5. キーボードレイアウトの選択

「Japanese」を選択する。

f:id:redj:20181216000752p:plain

4.6. rootのパスワードの設定

f:id:redj:20190202184003p:plain

4.7. 警告の表示

ひとつ警告が出た。

f:id:redj:20190202184238p:plain

非推奨のNICであるIntel e1000が原因で出ている。 非推奨とはいえ現状では一応動いているし、他のNICはESXiが認識しなかったので、無視することにする。

4.8. インストール実行の確認

f:id:redj:20181216003600p:plain

4.9. インストール完了画面

Enterを押下するとリブートする。

f:id:redj:20181216003820p:plain

5. ESXiの設定

5.1. ESXiの初期画面

起動が完了すると以下の画面が表示される。 設定変更を行うので、画面左下にあるとおりF2を押下する。

f:id:redj:20181216004123p:plain

5.2. Troubleshooting Optionsを選択

f:id:redj:20181216004349p:plain

5.3. ESXi ShellとSSHを有効化

f:id:redj:20181216004525p:plain

ESCを押下して前の画面に戻る。

5.4. Configure Management Networkを選択

f:id:redj:20181216004733p:plain

5.5. IPv4 Configurationを選択

f:id:redj:20181216004835p:plain

5.6. IPv4の設定

インストール直後のESXiはDHCPを利用しているので、静的IPに変更する。

f:id:redj:20181216005344p:plain

ESCを押下して前の画面に戻る。

5.7. IPv6 Configurationを選択

f:id:redj:20181216005520p:plain

5.8. IPv6の無効化

余計なトラブル防止のため、IPv6は無効化しておく。

f:id:redj:20181216005724p:plain

ESCを押下して前の画面に戻る。

5.9. DNS Configurationを選択

f:id:redj:20181216010152p:plain

5.10. DNSとホスト名の指定

DHCPを利用しないので、DNSとホスト名を静的に指定する。

f:id:redj:20181216010246p:plain

ESCを押下して前の画面に戻る。

5.11. リブート

IPv6を無効化したので、リブートを求められる。

f:id:redj:20181216010451p:plain

コンソールからの設定はこれで完了。

6. SSHの鍵認証の設定

ESXiのホストに鍵認証でSSHできるようにしておく。

6.1. KVMのホスト側からsshで接続

$ ssh root@192.168.8.20  ←● sshコマンド実行
The authenticity of host '192.168.8.20 (192.168.8.20)' can't be established.
RSA key fingerprint is SHA256:KkaJl6NMquDYlPwbqA7AsmuefrZF5uweLZv5xEtAV2E.
Are you sure you want to continue connecting (yes/no)? yes  ←● yesを入力
Warning: Permanently added '192.168.8.20' (RSA) to the list of known hosts.
Password:  ←● パスワードを入力
The time and date of this login have been sent to the system logs.

WARNING:
   All commands run on the ESXi shell are logged and may be included in
   support bundles. Do not provide passwords directly on the command line.
   Most tools can prompt for secrets or accept them from standard input.

VMware offers supported, powerful system administration tools.  Please
see www.vmware.com/go/sysadmintools for details.

The ESXi Shell can be disabled by an administrative user. See the
vSphere Security documentation for more information.
[root@esxi:~]  ←● ESXiのホストのプロンプトが表示された

6.2. SSHのauthorized_keysの登録

rootのauthorized_keysは以下のファイルなので、ここにSSHで利用する公開鍵を追加しておく。

  • /etc/ssh/keys-root/authorized_keys

あとは任意でKVMホスト側などで~/.ssh/configに以下のエントリを追加しておく。

Match host 192.168.8.20 user root
  IdentityFile /path/to/private-key

7. ライセンス登録

ESXiに無償利用のライセンスを登録しておかないと、評価期間の60日が経過すると利用できなくなってしまう。 登録方法を2パターン記載しておく。

7.1. Embedded Host Clientからのライセンス登録

以下のアドレスにブラウザでアクセスし、rootなどでログインする。

  • https://[ESXiホストのIP]

そして、以下のように画面を辿ってライセンスを登録する。

f:id:redj:20181216021324p:plain

7.2. コマンドラインからのライセンス登録

sshでESXiホストに接続して、以下のコマンドを実行する。

$ vim-cmd vimsvc/license --set [ライセンスコード]

8. その他

8.1. Embedded Host Clientのキーボードレイアウトの変更

Embedded Host Clientのデフォルトのキーボドレイアウトは英語なので、日本語に変更する。 英語だとコンソールの操作がしんどい。 ESXi本体のキーボドレイアウトとは別の設定になっているようだ。

f:id:redj:20181216041709p:plain

参考