ESX 6.0でストレージアクセス関連の調査を行った際に使ったesxcliコマンドメモ


esxcli storage core device list

現在認識してるストレージについてのいろんな情報

[root@esxi10:~] esxcli storage core device list
eui.9fa59185cb34c2ab6c9ce9003faf076a
   Display Name: Nimble iSCSI Disk (eui.9fa59185cb34c2ab6c9ce9003faf076a)
   Has Settable Display Name: true
   Size: 5242880
   Device Type: Direct-Access
   Multipath Plugin: NMP
   Devfs Path: /vmfs/devices/disks/eui.9fa59185cb34c2ab6c9ce9003faf076a
   Vendor: Nimble
   Model: Server
   Revision: 1.0
   SCSI Level: 5
   Is Pseudo: false
   Status: on
   Is RDM Capable: true
   Is Local: false
   Is Removable: false
   Is SSD: false
   Is VVOL PE: false
   Is Offline: false
   Is Perennially Reserved: false
   Queue Full Sample Size: 0
   Queue Full Threshold: 0
   Thin Provisioning Status: yes
   Attached Filters:
   VAAI Status: supported
   Other UIDs: vml.01000000003966613539313835636233346332616236633963653930303366616630373661536572766572
   Is Shared Clusterwide: true
   Is Local SAS Device: false
   Is SAS: false
   Is USB: false
   Is Boot USB Device: false
   Is Boot Device: false
   Device Max Queue Depth: 128
   No of outstanding IOs with competing worlds: 32
   Drive Type: unknown
   RAID Level: unknown
   Number of Physical Drives: unknown
   Protection Enabled: false
   PI Activated: false
   PI Type: 0
   PI Protection Mask: NO PROTECTION
   Supported Guard Types: NO GUARD SUPPORT
   DIX Enabled: false
   DIX Guard Type: NO GUARD SUPPORT
   Emulated DIX/DIF Enabled: false

[root@esxi10:~]

個別で見る場合は「esxcli storage core device list -d ストレージ指定」

[root@esxi10:~] esxcli storage core device list -d eui.9fa59185cb34c2ab6c9ce9003faf076a
eui.9fa59185cb34c2ab6c9ce9003faf076a
   Display Name: Nimble iSCSI Disk (eui.9fa59185cb34c2ab6c9ce9003faf076a)
   Has Settable Display Name: true
   Size: 5242880
   Device Type: Direct-Access
   Multipath Plugin: NMP
   Devfs Path: /vmfs/devices/disks/eui.9fa59185cb34c2ab6c9ce9003faf076a
   Vendor: Nimble
   Model: Server
   Revision: 1.0
   SCSI Level: 5
   Is Pseudo: false
   Status: on
   Is RDM Capable: true
   Is Local: false
   Is Removable: false
   Is SSD: false
   Is VVOL PE: false
   Is Offline: false
   Is Perennially Reserved: false
   Queue Full Sample Size: 0
   Queue Full Threshold: 0
   Thin Provisioning Status: yes
   Attached Filters:
   VAAI Status: supported
   Other UIDs: vml.01000000003966613539313835636233346332616236633963653930303366616630373661536572766572
   Is Shared Clusterwide: true
   Is Local SAS Device: false
   Is SAS: false
   Is USB: false
   Is Boot USB Device: false
   Is Boot Device: false
   Device Max Queue Depth: 128
   No of outstanding IOs with competing worlds: 32
   Drive Type: unknown
   RAID Level: unknown
   Number of Physical Drives: unknown
   Protection Enabled: false
   PI Activated: false
   PI Type: 0
   PI Protection Mask: NO PROTECTION
   Supported Guard Types: NO GUARD SUPPORT
   DIX Enabled: false
   DIX Guard Type: NO GUARD SUPPORT
   Emulated DIX/DIF Enabled: false
[root@esxi10:~]

ESXiで認識しているファイルシステム一覧

esxcli storage filesystem list

[root@esxi10:~] esxcli storage  filesystem list
Mount Point                                           Volume Name                   UUID                                    Mounted  Type             Size           Free
----------------------------------------------------  ----------------------------  --------------------------------------  -------  ------  -------------  -------------
/vmfs/volumes/5bbc594e-3e173ecc-b3e7-90b11c536183     esxstore-vsphere10            5bbc594e-3e173ecc-b3e7-90b11c536183        true  VMFS-5  5497289703424  2186855579648
/vmfs/volumes/b49358e5-23dc34a5-1c9f-5af965bf7cb0                                   b49358e5-23dc34a5-1c9f-5af965bf7cb0        true  vfat        261853184       79454208
/vmfs/volumes/4aed47ef-d4e7ee55-f394-88684bc4443c                                   4aed47ef-d4e7ee55-f394-88684bc4443c        true  vfat        261853184       79417344
/vmfs/volumes/5d47ebcd-a4552bf1-c3e2-90b11c536183                                   5d47ebcd-a4552bf1-c3e2-90b11c536183        true  vfat        299712512       84172800
[root@esxi10:~]

指定したVMFSの情報を確認

「esxcli storage vmfs host list –volume-label 名前」

[root@esxi10:~] esxcli storage vmfs host list --volume-label esxstore-vsphere10
Heartbeat UUID                       MAC Address        Driver Version  Heartbeat Offset  Locking Mode  Status
-----------------------------------  -----------------  --------------  ----------------  ------------  ------
5d6c6d91-51b61938-424a-90b11c536183  90:b1:1c:53:61:83  5.61                     3178496  ATS-only      Normal
[root@esxi10:~]

ストレージアクセスのQueue関連設定変更

現在の値確認は「esxcli storage core device list -d ストレージ指定」で行う。

「Device Max Queue Depth」を「128」に設定する

[root@esxi10:~]esxcli storage core device set -d eui.9fa59185cb34c2ab6c9ce9003faf076a -m 128
[root@esxi10:~]

「No of outstanding IOs with competing worlds」を「32」に設定する

[root@esxi10:~]esxcli storage core device set -d eui.9fa59185cb34c2ab6c9ce9003faf076a -O 32
[root@esxi10:~]

ストレージパス関連

esxcli storage core path list

[root@esxi10:~] esxcli storage core path list
iqn.1998-01.com.vmware:esxi10-753076d4-00023d000001,iqn.2007-11.com.nimblestorage:esxstore-vsphere10-v371c7edc5d1bd1e3.000000ab.6a07af3f,t,2460-eui.9fa59185cb34c2ab6c9ce9003faf076a
   UID: iqn.1998-01.com.vmware:esxi10-753076d4-00023d000001,iqn.2007-11.com.nimblestorage:esxstore-vsphere10-v371c7edc5d1bd1e3.000000ab.6a07af3f,t,2460-eui.9fa59185cb34c2ab6c9ce9003faf076a
   Runtime Name: vmhba38:C0:T1:L0
   Device: eui.9fa59185cb34c2ab6c9ce9003faf076a
   Device Display Name: Nimble iSCSI Disk (eui.9fa59185cb34c2ab6c9ce9003faf076a)
   Adapter: vmhba38
   Channel: 0
   Target: 1
   LUN: 0
   Plugin: NMP
   State: active
   Transport: iscsi
   Adapter Identifier: iqn.1998-01.com.vmware:esxi10-753076d4
   Target Identifier: 00023d000001,iqn.2007-11.com.nimblestorage:esxstore-vsphere10-v371c7edc5d1bd1e3.000000ab.6a07af3f,t,2460
   Adapter Transport Details: iqn.1998-01.com.vmware:esxi10-753076d4
   Target Transport Details: IQN=iqn.2007-11.com.nimblestorage:esxstore-vsphere10-v371c7edc5d1bd1e3.000000ab.6a07af3f Alias= Session=00023d000001 PortalTag=2460
   Maximum IO Size: 131072
[root@esxi10:~]

各ストレージのパス選択アルゴリズム確認

「esxcli storage nmp device list」

[root@esxi10:~] esxcli storage nmp device list
eui.9fa59185cb34c2ab6c9ce9003faf076a
   Device Display Name: Nimble iSCSI Disk (eui.9fa59185cb34c2ab6c9ce9003faf076a)
   Storage Array Type: VMW_SATP_ALUA
   Storage Array Type Device Config: {implicit_support=on;explicit_support=off; explicit_allow=on;alua_followover=on; action_OnRetryErrors=off; {TPG_id=0,TPG_state=AO}}
   Path Selection Policy: VMW_PSP_MRU
   Path Selection Policy Device Config: Current Path=vmhba38:C0:T1:L0
   Path Selection Policy Device Custom Config:
   Working Paths: vmhba38:C0:T1:L0
   Is USB: false
[root@esxi10:~]

使用できるPSP一覧

[root@esxi10:~] esxcli storage nmp psp list
Name           Description
-------------  ---------------------------------
VMW_PSP_MRU    Most Recently Used Path Selection
VMW_PSP_RR     Round Robin Path Selection
VMW_PSP_FIXED  Fixed Path Selection
[root@esxi10:~]

指定できるSATP一覧

[root@esxi10:~] esxcli storage nmp satp list
Name                 Default PSP    Description
-------------------  -------------  -------------------------------------------------------
VMW_SATP_ALUA        VMW_PSP_MRU    Supports non-specific arrays that use the ALUA protocol
VMW_SATP_MSA         VMW_PSP_MRU    Placeholder (plugin not loaded)
VMW_SATP_DEFAULT_AP  VMW_PSP_MRU    Placeholder (plugin not loaded)
VMW_SATP_SVC         VMW_PSP_FIXED  Placeholder (plugin not loaded)
VMW_SATP_EQL         VMW_PSP_FIXED  Placeholder (plugin not loaded)
VMW_SATP_INV         VMW_PSP_FIXED  Placeholder (plugin not loaded)
VMW_SATP_EVA         VMW_PSP_FIXED  Placeholder (plugin not loaded)
VMW_SATP_ALUA_CX     VMW_PSP_RR     Placeholder (plugin not loaded)
VMW_SATP_SYMM        VMW_PSP_RR     Placeholder (plugin not loaded)
VMW_SATP_CX          VMW_PSP_MRU    Placeholder (plugin not loaded)
VMW_SATP_LSI         VMW_PSP_MRU    Placeholder (plugin not loaded)
VMW_SATP_DEFAULT_AA  VMW_PSP_FIXED  Supports non-specific active/active arrays
VMW_SATP_LOCAL       VMW_PSP_FIXED  Supports direct attached devices
[root@esxi10:~]

パス選択アルゴリズムの変更

[root@esxi10:~] esxcli storage nmp device set --psp=VMW_PSP_RR --device=eui.9fa59185cb34c2ab6c9ce9003faf076a
[root@esxi10:~]

変更確認

[root@esxi10:~] esxcli storage nmp device list -d eui.9fa59185cb34c2ab6c9ce9003faf076a
eui.9fa59185cb34c2ab6c9ce9003faf076a
   Device Display Name: Nimble iSCSI Disk (eui.9fa59185cb34c2ab6c9ce9003faf076a)
   Storage Array Type: VMW_SATP_ALUA
   Storage Array Type Device Config: {implicit_support=on;explicit_support=off; explicit_allow=on;alua_followover=on; action_OnRetryErrors=off; {TPG_id=0,TPG_state=AO}}
   Path Selection Policy: VMW_PSP_RR
   Path Selection Policy Device Config: {policy=rr,iops=1000,bytes=10485760,useANO=0; lastPathIndex=1: NumIOsPending=0,numBytesPending=0}
   Path Selection Policy Device Custom Config:
   Working Paths: vmhba38:C3:T1:L0, vmhba38:C0:T1:L0
   Is USB: false
[root@esxi10:~]

HBAドライバパラメータ調整

インストールされているドライババージョン等を確認

[root@esxi10:~] esxcli software vib list|grep qla
ima-qla4xxx                    2.02.18-1vmw.600.0.0.2494585           VMware  VMwareCertified   2019-08-05
scsi-qla4xxx                   5.01.03.2-7vmw.600.0.0.2494585         VMware  VMwareCertified   2019-08-05
[root@esxi10:~]

HBAで指定できるパラメータ確認

「esxcli system module parameters list -m モジュール名」

[root@esxi10:~] esxcli system module parameters list -m qlnativefc
Name                        Type  Value  Description
--------------------------  ----  -----  --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ql2name                     int          Option to have different node and port name for ISP82xxpass value based on the port used on the FCoE switch.
ql2xallocfwdump             int          Option to enable allocation of memory for a firmware dump during HBA initialization.  Memory allocation requirements vary by ISP type.  Default is 1 - allocate memory.
ql2xattemptdumponpanic      int          Attempt fw dump for each function on PSOD Default is 0 - Don't attempt fw dump.
ql2xbypass_log_throttle     int          Option to bypass log throttling.Default is 0 - Throttling enabled. 1 - Log all errors.
ql2xcmdtimeout              int          Timeout value in seconds for scsi command, default is 20
ql2xcmdtimermin             int          Minimum command timeout value. Default is 30 seconds.
ql2xdbwr                    int          Option to specify scheme for request queue posting. 0 -- Regular doorbell. 1 -- (Default) CAMRAM doorbell (faster).
ql2xdevdiscgoldfw           int          Option to enable device discovery with golden firmware Default is 0 - no discovery. 1 - discover device.
ql2xdisablenpiv             int          Option to disable/enable NPIV feature globally.        1 - NPIV disabled. Default is 0 - NPIV enabled.
ql2xdontresethba            int          1: Do not reset on failure, 0: Reset on failure, default is 0
ql2xdontresethba_83xx       int          1: Do not reset on failure, 0: Reset on failure, default is 0
ql2xenablehba_err_chk       int           Enable T10-CRC-DIF Error isolation by HBA:
 Default is 2.
  0 -- Error isolation disabled
  1 -- Error isolation enabled only for DIX Type 0
  2 -- Error isolation enabled for all Types
ql2xenablemd                int          82XX/8044: Option to enable/disable the minidump capture capability.     0 - disable minidump capture          1 - (Default) enable minidump capture
ql2xenablemsi2422           int          Enables MSI interrupt scheme on 2422sDefault is 0 - disable MSI-X/MSI. 1 - enable MSI-X/MSI.
ql2xenablemsi24xx           int          Enables MSIx/MSI interrupt scheme on 24xx cardsDefault is 1 - enable MSI-X/MSI. 0 - disable MSI-X/MSI.
ql2xenablemsix              int          Set to enable MSI or MSI-X interrupt mechanism. 0 = enable traditional pin-based interrupt mechanism. 1 = enable MSI-X interrupt mechanism (Default). 2 = enable MSI interrupt mechanism.
ql2xenablesmartsan          int          Enable HP Smart SAN management feature.Default is 1.
 0 - Disable the Smart SAN feature.  1 - Enable the Smart SAN feature.
ql2xexecution_throttle      int          IOCB exchange count for HBA.Default is 0, set intended value to override Firmware defaults.
ql2xextended_error_logging  int          Option to enable extended error logging, Default is 0 - no logging. 1 - log errors.
ql2xfabricpriorityqos       int           Option to set QoS mode
 Default is 2.
 0 - Fabric Priority QoS is disabled
 1 - Queue-based Fabric Priority QoS enabled.
 2 - IOCB-based Fabric Priority QoS enabled.
ql2xfdmienable              int          Enables FDMI registratons Default is 1 - perfom FDMI. 0 - no FDMI.
ql2xfwloadbin               int          Option to specify location from which to load ISP firmware: 2 -- load firmware via the requestFirmware() (hotplug)      interface. 1 -- load firmware from flash. 0 -- use default semantics.
ql2xiidmaenable             int          Enables iIDMA settings Default is 1 - perform iIDMA. 0 - no iIDMA.
ql2xintrdelaytimer          int          ZIO: Waiting time for Firmware before it generates an interrupt to the host to notify completion of request.
ql2xioctltimeout            int          IOCTL timeout value in seconds for pass-thur commands. Default is 66 seconds.
ql2xioctltimertest          int          IOCTL timer test enable - set to enable ioctlcommand timeout value to trigger before fw cmdtimeout value. Default is disabled
ql2xloadfwbin               int          Option to Load Firmware from the flash/driver source for qla82xx Default is 1, 0 = load firmware bundled with driver source 1 = load from Flash
ql2xloginretrycount         int          Specify an alternate value for the NVRAM login retry count.
ql2xlogintimeout            int          Login timeout value in seconds.
ql2xmaxlun                  int          Defines the maximum LUNs to register with the SCSI midlayer.    Default is 256. Maximum allowed is 65535.
ql2xmaxqdepth               int          Maximum queue depth to report for target devices.
ql2xmaxsgs                  int          Maximum scatter/gather entries per request,Default is the Max the OS Supports.
ql2xmdcapmask               int          82XX/8044: Option to set the driver capture mask for f/w minidump as follows:          0x00 - use f/w recommended capture mask         0x03 - capture mask 0x3         0x0F - capture mask 0x0F      0x1F - (Default) capture mask 0x1F      0x7F - capture mask 0x7F
ql2xmqcpuaffinity           int          Enables CPU affinity settings for the driver Default is 1 to turn on the cpu affinity.Set to 0 for no affinity of request and response IO.
ql2xmqqos                   int          Enables QoS settings Default is 1. Set it to enable            queues in MQ QoS mode.
ql2xoperationmode           int          Option to disable ZIO mode for ISP24XX:   Default is 1, set 0 to disable
ql2xplogiabsentdevice       int          Option to enable PLOGI to devices that are not present after a Fabric scan.  This is needed for several broken switches. Default is 0 - no PLOGI. 1 - perfom PLOGI.
ql2xshiftctondsd            int          Set to control shifting of command type processing based on total number of DSD.
ql2xt10difvendor            int           Vendor unique T10 DIF support.  Default is enabled.
 0 -- Disabled.
 1 -- Enabled.
ql2xt10enable               int           Enable T10-CRC-DIF  Default is 1 - DIF Support Enabled. 0 - Disable it
ql2xt10guard                int           Adapter guard type supported  Default is CRC checksumming and IP checksumming.
ql2xt10protmask             int           Adapter protection mask  Default is 0x55 - T10 PI Type 1/3, DIX Type 1/3 protection.
ql2xusedefmaxrdreq          int          Default is 0 - adjust PCIe Maximum Read Request Size. 1 - use system default.
ql2xuseshadowregisters      int           For ISP27XX/ISP28XX : Option to use shadow register for request/response queues :
 Default is 0.
  0 -- Don't use shadow registers for the request/response queue manipulation
  1 -- Use shadow registers for the request/response queue manipulation
ql2xvmidexpiration          int           Expiration time for VMID in minutes. 0 is no expiration. Default is 240 minutes (4 hours) with no I/O leads to de-registration.
ql2xvmidsupport             int           Enable VMID support in driver.  Default is disabled.
 0 -- Disabled.
 1 -- Enabled.
ql2xvmidtgtind              int           Ignore target settings for QoS VMID.  Default is disabled.
 0 -- Disabled.
 1 -- Enabled.
qlport_down_retry           int          Maximum number of command retries to a port that returns a PORT-DOWN status.
[root@esxi10:~]

「esxcfg-module –show-info モジュール名」

[root@esxi10:~] esxcfg-module --show-info qlnativefc
esxcfg-module module information
 input file: /usr/lib/vmware/vmkmod/qlnativefc
 License: BSD
Cannot access module instance.
[root@esxi10:~]

値の設定

[root@esxi10:~] esxcfg-module --get-options qlnativefc
qlnativefc enabled = 1 options = ''
[root@esxi10:~]

ESXi上でCentOS7なのにCentOS6だと言われる件


ESXi上でCentOS7をインストールした場合、open-vm-toolsをインストールされていても「CentOS6」だと言われてしまう件について調査した。

なお、何故かvCenter上から見た場合は警告されず、直接ESXi上で仮想マシンを見た際にだけ言われる。

結論めいたこと

open-vm-toolsのバグ(Fix CentOS 7.6 detection)で、open-vm-tools 10.3.10以降で修正されている。

しかし、2019/06/27時点でのCentOS7のopen-vm-toolsは10.2.5であり修正されていないバージョンであるため公式な手法では対処できない。

回避策としては2つある

/etc/centos-release を修正する

今回のバグは「CentOS Linux release 7.6.1810 (Core)」の文字列からOSバージョン判定をする際に「”6.”があればCentOS6」「”7.”があればCentOS7」「”8.”があればCentOS8」という順番で行っているせいで、「7.6.1810」の中にある「6.」を読み取ってしまい「CentOS6」と判定されていることにより発生している。

このため、/etc/centos-release 内の誤判定要素を無くすことで対処できなくもない。

例えば「 CentOS Linux release 7.6 1810 (Core) 」と、「.」を抜いてしまうとか。

ただ、このファイルは他のソフトウェアでもディストリビューション判別に使用されており、そこでの条件の書き方によっては正しく判定できなくなってしまう恐れもあるため、注意が必要である。

もしくはCentOS 7.7以降ではれば、「6.」に引っかかることがなくなるので、アップデートする、という手もとれる。

vSphere仮想マシンオプションのゲストOSを修正する

vSphere6.5以降(仮想マシンバージョン13以降)でCentOS7を使用する場合、仮想マシンオプションで「ゲストOS:Linux」と「ゲストOSのバージョン:CentOS 7(64ビット)」を設定する。

誤判定で「CentOS 6(64ビット)」と認識されているんだったら、仮想マシンオプションの「ゲストOSのバージョン」も「CentOS 6 (64ビット)」にしちゃえばいいじゃん。

という非常に雑な対応手法。

なんでこんなことに

githubにあるopen-vm-toolsのソースコードからopen-vm-tools/open-vm-tools/lib/misc/hostinfoPosix.c を見てみるとひたすら条件が列挙されている。

いままではバージョン表記の中に「.」が2個登場するという想定が無かったようで、Debianでも同様の手法で判定しています。

今回のCentOSでの対応は、いままで「6.」をキーにしていたものを「 6.」と数字の前にスペースが入っていることを検出するようにした、というものになっている。

個人的に結構意外だったのはRedHat Enterprise LinuxとCentOSの判定ルーチンが独立しているという点。

   if (strstr(distroLower, "red hat")) {
      if (strstr(distroLower, "enterprise")) {

         /*
          * Looking for "release x" here instead of "x" as there could be
          * build version which can be misleading. For example Red Hat
          * Enterprise Linux ES release 4 (Nahant Update 3)
          */

         int release = 0;
         char *releaseStart = strstr(distroLower, "release");

         if (releaseStart != NULL) {
            sscanf(releaseStart, "release %d", &release);
            if (release > 0) {
               snprintf(distroShort, distroShortSize, STR_OS_RED_HAT_EN"%d",
                        release);
            }
         }

         if (release <= 0) {
            Str_Strcpy(distroShort, STR_OS_RED_HAT_EN, distroShortSize);
         }

      } else {
         Str_Strcpy(distroShort, STR_OS_RED_HAT, distroShortSize);
      }
   }
   } else if (StrUtil_StartsWith(distroLower, "centos")) {
      if (strstr(distroLower, " 6.")) {
         Str_Strcpy(distroShort, STR_OS_CENTOS6, distroShortSize);
      } else if (strstr(distroLower, " 7.")) {
         Str_Strcpy(distroShort, STR_OS_CENTOS7, distroShortSize);
      } else if (strstr(distroLower, " 8.")) {
         Str_Strcpy(distroShort, STR_OS_CENTOS8, distroShortSize);
      } else {
         Str_Strcpy(distroShort, STR_OS_CENTOS, distroShortSize);
      }
   } 

そして、Oracle LinuxはCentOSと同様の記載になっているという点。

   } else if (StrUtil_StartsWith(distroLower, "enterprise linux") ||
              StrUtil_StartsWith(distroLower, "oracle")) {
      /*
       * [root@localhost ~]# lsb_release -sd
       * "Enterprise Linux Enterprise Linux Server release 5.4 (Carthage)"
       *
       * Not sure why they didn't brand their releases as "Oracle Enterprise
       * Linux". Oh well. It's fixed in 6.0, though.
       */
      if (strstr(distroLower, "6.")) {
         Str_Strcpy(distroShort, STR_OS_ORACLE6, distroShortSize);
      } else if (strstr(distroLower, "7.")) {
         Str_Strcpy(distroShort, STR_OS_ORACLE7, distroShortSize);
      } else if (strstr(distroLower, "8.")) {
         Str_Strcpy(distroShort, STR_OS_ORACLE8, distroShortSize);
      } else {
         Str_Strcpy(distroShort, STR_OS_ORACLE, distroShortSize);
      }
   }

Oracle Linux 7の /etc/oracle-release の表記はどういう風になってるんだろうかな・・・

PowerCLIを使ってvSphere仮想マシンをテンプレートから連続デプロイ


RedHat OpenShift環境を作るためのansible hostsファイルがすごく難解。

おかげでいろんなhostsファイル記述を実験する羽目に・・・

仮想マシンテンプレートを作ったあと、仮想マシンのカスタマイズ仕様を元にデプロイするだけとは言え、マスタ2台、インフラノード2台、ノード2台とかを毎回作り直すのが面倒。

簡略化するためにPowerCLIを使って一括作成できるようなスクリプトを作成した。

$vcenter="testvcenter"       # 接続先vCenterホスト名 or IPアドレス
$vcenterusername="administrator@vsphere.local" # vCenterユーザ名
$vcenterpassword="test"       # vCenterパスワード
$vmtemplatename="rhel7-os311" # 仮想マシンテンプレート名
$vmcustomizespec="rhel7-base" # 仮想マシンのカスタマイズ仕様名
$datastore="vsphere10"          # デプロイ先データストア
$esxserver="172.17.44.10"       # デプロイ先ESXiサーバ
$subnetmask="255.255.0.0"       # 仮想マシンのサブネット
$defaultgw="172.17.0.1"         # 仮想マシンのデフォルトゲートウェイ

connect-vcenter -Server $vcenter -User $vcenterusername -Password $vcenterpassword -WarningAction 0

deployvm -vmname "master221" -ipaddr "172.17.44.221" -cpu 4 -memory 16
deployvm -vmname "master222" -ipaddr "172.17.44.222" -cpu 4 -memory 16
deployvm -vmname "infra-node223" -ipaddr "172.17.44.223" -cpu 2 -memory 8
deployvm -vmname "node224" -ipaddr "172.17.44.224" -cpu 2 -memory 8
deployvm -vmname "node225" -ipaddr "172.17.44.225" -cpu 2 -memory 8

Disconnect-VIServer -Confirm:$false


###########################################
### 関数名: connect-vcenter
### 役割:   指定したvCenterサーバに接続
### 入力: 「-Server vCenterサーバ名」 
###      「-User ユーザ名」
###      「-Password パスワード」 
###      「-Credential パスワードの暗号化文字列」
###       「-Password」か「-Credential」かは排他指定
### 注意: パイプライン処理不可
###########################################
function connect-vcenter{
    param(
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$Server,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$User,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$Password,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][SecureString]$Credential
    )

    # $global:DefaultVIServers が存在している場合はすでにvCenterに接続されているので処理を飛ばす
    #  vROpsと異なり接続がなくなったら変数もなくなるようだが、念のためこちらも接続中のユーザ名があることを確認
    if([String]::IsNullOrEmpty($global:DefaultVIServers.User)){
        Try {
            if($Credential){
                $pscredential=New-Object System.Management.Automation.PSCredential($User,$Credential)
                Connect-VIServer -Server $Server -Credential $pscredential -WarningAction 0 | Out-Null
                if($? -eq $false){ throw }
            }else{
                Connect-VIServer -Server $Server -User $User -Password $Password -WarningAction 0 | Out-Null
                if($? -eq $false){ throw }
            }
        } Catch {
            Write-Host "vCenterサーバへの接続に失敗しました"
            Write-Host $Error[0]
            exit 1
        }
    }
    return
}

###########################################
### 関数名: deployvm
### 役割:   仮想マシンテンプレートから仮想マシンをデプロイ
### 入力: 「-vmname 仮想マシンホスト名」 
###      「-ipaddr IPアドレス」
###      「-cpu CPU数」 
###      「-memory メモリ容量」
### 注意: 簡略化のため、下記の前提がある
###    デプロイ先のESXiサーバを、グローバル変数 $esxserver で指定していること
###    デプロイ先のデータストアを、グローバル変数 $datastore で指定していること
###    仮想マシンテンプレートを、グローバル変数 $vmtemplatename で指定していること(作成済みであること)
###    仮想マシンのカスタマイズ仕様を、グローバル変数 $vmcustomizespec で指定していること(作成済みであること)
###    グローバル変数で仮想マシンのサブネットマスク $subnetmask とデフォルトゲートウェイ $defaultgw を指定していること
###########################################
function deployvm{
    Param(
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$vmname,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$ipaddr,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][int]$cpu,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][int]$memory
    )
    Get-OSCustomizationSpec $vmcustomizespec | New-OSCustomizationSpec -Name vmtemp -Type NonPersistent
    Get-OSCustomizationNicMapping vmtemp | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $subnetmask -DefaultGateway $defaultgw
    Get-OSCustomizationSpec vmtemp | Set-OSCustomizationSpec -NamingScheme vm

    New-VM -Name $vmname -VMHost $esxserver -Template $vmtemplatename -OSCustomizationSpec vmtemp -Datastore $datastore -Confirm:$false
    Set-VM -VM $vmname -MemoryGB $memory -NumCpu $cpu -Confirm:$false
    Start-VM -VM $vmname -Confirm:$false
    Remove-OSCustomizationSpec vmtemp -Confirm:$false
}

なお、vCenterへの接続部分がごっつい関数にしてあるのは、他で使ったものの流用であるためです。

deployvmで行っていることの詳細については「PowerShellを使ってVMwareのテンプレートからデプロイで「既存のカスタマイズ仕様を使用してカスタマイズする」を行う方法」を参照のこと。

WindowsServer 2016にVMware PowerCLIをインストールする際のメモ


Windows Server 2016環境にVMware PowerCLIをインストールしたので、その手順のメモ
なお、2020年4月以降、PowerShell GalleryへのアクセスがTLS 1.2必須となったため、後半に書かれている対処方法を行う必要がある。

(1) PowerShellを起動

(2)「Install-Module -Name VMware.PowerCLI」を実行

途中、NuGetプロバイダーのインストールと、PowerCLIがあるレポジトリの追加が要求されるので、両方許可する。

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> Install-Module -Name VMware.PowerCLI

続行するには NuGet プロバイダーが必要です
PowerShellGet で NuGet ベースのリポジトリを操作するには、'2.8.5.201' 以降のバージョンの NuGet
プロバイダーが必要です。NuGet プロバイダーは 'C:\Program Files\PackageManagement\ProviderAssemblies' または
'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'
に配置する必要があります。'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' を実行して NuGet
プロバイダーをインストールすることもできます。今すぐ PowerShellGet で NuGet
プロバイダーをインストールしてインポートしますか?
[Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y

信頼されていないリポジトリ
信頼されていないリポジトリからモジュールをインストールしようとしています。このリポジトリを信頼する場合は、Set-PSReposit
ory コマンドレットを実行して、リポジトリの InstallationPolicy の値を変更してください。'PSGallery'
からモジュールをインストールしますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): y
PS C:\Users\Administrator>

(3) 以上!


なお、その後のメモ

自己証明書を使ってるvCenterサーバに接続しようとすると下記のエラーがでる。

PS C:\Users\Administrator> Connect-VIServer -Server vcenterサーバ -User administrator@vsphere.local -Password "パスワード"
Connect-VIServer : 2018/12/20 11:25:08  Connect-VIServer                Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect once or to add a permanent exception for this server.
Additional Information: 機関 'vcenterサーバ' との SSL/TLS のセキュリティで保護されているチャネルに対する信頼関係を確立できませんでした。
発生場所 行:1 文字:1
+ Connect-VIServer -Server vcenterサーバ -User administrator@vsphere.loca ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : セキュリティ エラー: (: ) [Connect-VIServer]、ViSecurityNegotiationException
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.
   Cmdlets.Commands.ConnectVIServer

PS C:\Users\Administrator>

以前は「」オプションで回避できていたが、今のPowerCLIでは「Set-PowerCLIConfiguration -InvalidCertificateAction Ignore」を設定する必要がある。(参考:New Release: VMware PowerCLI 10.0.0 )

Users\Administrator> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

Perform operation?
Performing operation 'Update PowerCLI configuration.'?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds
-----    -----------     ------------------- ------------------------  -------------------------- -------------------
Session  UseSystemProxy  Multiple            Ignore                    True                       300
User                                         Ignore
AllUsers


PS C:\Users\Administrator>

これで接続できるようになる。

PS C:\Users\Administrator> Connect-VIServer -Server vCenterサーバ -User administrator@vsphere.local -Password "パスワード"

Name                           Port  User
----                           ----  ----
vCenterサーバ                    443   VSPHERE.LOCAL\Administrator

PS C:\Users\Administrator>

2020/07/16追記

久しぶりにやってみたら、以下のエラーになった。

PS C:\Users\Administrator> Install-Module -Name VMware.PowerCLI

続行するには NuGet プロバイダーが必要です
PowerShellGet で NuGet ベースのリポジトリを操作するには、'2.8.5.201' 以降のバージョンの NuGet
プロバイダーが必要です。NuGet プロバイダーは 'C:\Program Files\PackageManagement\ProviderAssemblies' または
'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'
に配置する必要があります。'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' を実行して NuGet
プロバイダーをインストールすることもできます。今すぐ PowerShellGet で NuGet
プロバイダーをインストールしてインポートしますか?
[Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"):
警告: URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' から '' へダウンロードできません。
警告: 利用可能なプロバイダーの一覧をダウンロードできません。インターネット接続を確認してください。
PackageManagement\Install-PackageProvider : プロバイダー 'NuGet' について、指定された検索条件に一致するものが見つかりま
せんでした。パッケージ プロバイダーには 'PackageManagement' タグと 'Provider' タグが必要です。指定されたパッケージにこ
れらのタグがあるかどうかを確認してください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7405 文字:21
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
   kageProvider]、Exception
    + FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro
   vider

PackageManagement\Import-PackageProvider : プロバイダー名 'NuGet' について、指定された検索条件に一致するものが見つかり
ませんでした。'Get-PackageProvider -ListAvailable' を使用して、このプロバイダーがシステム上に存在するか確認してください
。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7411 文字:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider]、Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv
   ider

警告: URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' から '' へダウンロードできません。
警告: 利用可能なプロバイダーの一覧をダウンロードできません。インターネット接続を確認してください。
PackageManagement\Get-PackageProvider : パッケージ プロバイダー 'NuGet' が見つかりません。まだインポートされていない可
能性があります。'Get-PackageProvider -ListAvailable' を実行してみてください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7415 文字:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvi
   der], Exception
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka
   geProvider

Install-Module : NuGet ベースのリポジトリを操作するためには、NuGet プロバイダーが必要です。'2.8.5.201' 以降のバージョン
の NuGet プロバイダーがインストールされていることを確認してください。
発生場所 行:1 文字:1
+ Install-Module -Name VMware.PowerCLI
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Install-Module]、InvalidOperationException
    + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module

PS C:\Users\Administrator>

しかし、該当サーバでブラウザから「https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409」にアクセスしてみると、正常にファイルが取得できる。

調べて見ると、TLS 1.2アクセス必須となったためのエラーのようである。
 MasayaSawada「NuGet がmsg:unabletodownload エラーでインストールできない!
 PowerShell devblog「PowerShell Gallery TLS Support

現状SSL3とTLS1のサポートとなっている設定をTLS1.2サポートにする、という設定変更を行うことになる。

現状値の確認と変更は下記の様に行う。

PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls
PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol
Tls12
PS C:\Users\Administrator>

これを設定した後に「Install-Module -Name VMware.PowerCLI」を再実行することでダウンロードとインストールが実施されます。

なお、下記サイトに書かれている様に「[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12」というコマンドは保存されない設定を行うものであるため、PowerShell窓を閉じてしまうと元の設定に戻ります。
 しばたテックブログ「Windows PowerShellとTLS 1.2

RHEL7のvSphereテンプレートからの仮想マシンデプロイでカスタマイズができない



RHEL7仮想マシンテンプレートでvSphereの「テンプレートからの仮想マシンデプロイ」で「カスタマイズ」を行ってホスト名、IPアドレスを変更してみたところ、うまくいかなかった。

調査したところ、最小パッケージでは失敗することが判明。
RHEL 7, open-vm-tools, and guest customization

「perl」と「net-tools」が必須であるとのこと。
(open-vm-toolsについては標準でインストールされていた)

で、perl,net-toolsを追加したところ、カスタマイズしてのデプロイに成功した。