LoginSignup
1
0

More than 5 years have passed since last update.

備忘:ESXiの初期構築

Last updated at Posted at 2018-04-14

はじめに

この記事は技術的な発信を目的としておらず、単なる自分用メモです。
PowerCLIでの初期構築スクリプト。kickstartを使う方が効率が良いが、そのあたりの仕組みで使う仮想マシンの基盤になる筐体なので。

Nested ESXiなどを動かす用途のESXi

この子は電気代が高いので必要のないときはシャットダウンしないと怒られる。

pesxi01.ps1
$Cred = Get-Credential
Get-Module -ListAvailable -Name VMware* | Import-Module
Connect-VIServer <My ESXi FQDN or IPAddress> -Credential $Cred
$VMhost = Get-VMHost

# 読み取り専用ユーザの作成
$VIRole = Get-VIRole -Name ReadOnly
New-VMHostAccount -Id monitor -Password VMw@re!
New-VIPermission -Entity $VMhost -Principal monitor -Role $VIRole

# サービス起動設定
$Services = Get-VMHostService
foreach ($Service in $Services){
    if ($Service.key -eq "ntpd"){
        Set-VMHostService -HostService $Service -Policy On -Confirm:$false
        Start-VMHostService -HostService $Service -Confirm:$false
        Add-VmHostNtpServer -NtpServer "ntp.nict.jp" -VMHost $VMhost    
    }
    if ($Service.key -eq "TSM"){
        Set-VMHostService -HostService $Service -Policy On -Confirm:$false
        Start-VMHostService -HostService $Service -Confirm:$false
    }
    if ($Service.key -eq "TSM-SSH"){
        Set-VMHostService -HostService $Service -Policy On -Confirm:$false
        Start-VMHostService -HostService $Service -Confirm:$false
    }        
}

# ESXシェルおよびSSH警告の無効化
Set-VMHostAdvancedConfiguration -VMHost $VMhost -Name UserVars.SuppressShellWarning -Value 1 -Confirm:$false

# 管理用仮想スイッチ設定
$vswitch_mng = Get-VirtualSwitch -VMHost $VMhost -Name "vSwitch0"
Get-VirtualPortGroup -VirtualSwitch $vswitch_mng -Name "VM Network" | Remove-VirtualPortGroup -Confirm:$false
Get-VirtualPortGroup -VirtualSwitch $vswitch_mng -Name "Management Network" | Set-VirtualPortGroup -Name "vmk_manage" -Confirm:$false
New-VirtualPortGroup -VirtualSwitch $vswitch_mng  -Name "ExternalNetwork"

# 仮想マシン用仮想スイッチ作成
$vswitch_VM = New-VirtualSwitch -VMHost $VMhost  -Name "VM"
Set-VirtualSwitch -VirtualSwitch $vswitch_VM -Nic vmnic1,vmnic2 -Confirm:$false
Get-VirtualSwitch -VirtualSwitch $vswitch_VM | Get-SecurityPolicy | Set-SecurityPolicy -AllowPromiscuousInherited $true 
$NicTeamingPolicy = Get-NicTeamingPolicy -VirtualSwitch $vswitch_VM
$NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy LoadBalanceIP -Confirm:$false
New-VirtualPortGroup -VirtualSwitch $vswitch_VM  -Name "InternalNetwork"

設定漏れなかったかな。。。

DCなど常時起動する仮想マシンを動かすESXi

この子は電気代をあまり喰わないのと(MAC MINIだし)、起動にお作法があるため常時起動する。
NICは一つしかない。

pesxi02.ps1
$Cred = Get-Credential
Get-Module -ListAvailable -Name VMware* | Import-Module
Connect-VIServer <My ESXi FQDN or IPAddress> -Credential $Cred
$VMhost = Get-VMHost

# 読み取り専用ユーザの作成
$VIRole = Get-VIRole -Name ReadOnly
New-VMHostAccount -Id monitor -Password VMw@re!
New-VIPermission -Entity $VMhost -Principal monitor -Role $VIRole

# サービス起動設定
$Services = Get-VMHostService
foreach ($Service in $Services){
    if ($Service.key -eq "ntpd"){
        Set-VMHostService -HostService $Service -Policy On -Confirm:$false
        Start-VMHostService -HostService $Service -Confirm:$false
        Add-VmHostNtpServer -NtpServer "ntp.nict.jp" -VMHost $VMhost    
    }
    if ($Service.key -eq "TSM"){
        Set-VMHostService -HostService $Service -Policy On -Confirm:$false
        Start-VMHostService -HostService $Service -Confirm:$false
    }
    if ($Service.key -eq "TSM-SSH"){
        Set-VMHostService -HostService $Service -Policy On -Confirm:$false
        Start-VMHostService -HostService $Service -Confirm:$false
    }        
}

# ESXシェルおよびSSH警告の無効化
Set-VMHostAdvancedCsonfiguration -VMHost $VMhost -Name UserVars.SuppressShellWarning -Value 1 -Confirm:$false

# 管理用仮想スイッチ設定
$vswitch_mng = Get-VirtualSwitch -VMHost $VMhost -Name "vSwitch0"
Get-VirtualPortGroup -VirtualSwitch $vswitch_mng -Name "VM Network" | Remove-VirtualPortGroup -Confirm:$false
Get-VirtualPortGroup -VirtualSwitch $vswitch_mng -Name "Management Network" | Set-VirtualPortGroup -Name "vmk_manage" -Confirm:$false
New-VirtualPortGroup -VirtualSwitch $vswitch_mng  -Name "ExternalNetwork"

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0