どうも、Tです。
ESXiホストのNTP設定方法です。
スポンサーリンク
やりたいこと
NTP関連の設定をPowerCLIで行いたい。
NTP設定
設定方法
NTPサーバーの設定
形式
Add-VMHostNtpServer -VMHost $ESXiホスト名もしくはIP -NtpServer $NTPサーバー
サンプル
Add-VMHostNtpServer -VMHost (Get-VMHost -name testesxi001*) -NtpServer "192.168.10.132","192.168.10.137"
| パラメーター | 説明 |
| -VMHost | ESXiのFQDN・ホスト名・IPアドレス |
| -NtpServer | NTPサーバー。複数のときはカンマ区切り。 |
NTPサービスの起動
形式
Get-VmHostService -VMHost $ESXiホスト名もしくはIP | Where-Object {$_.key -eq 'ntpd'} | Start-VMHostServiceサンプル
Get-VmHostService -VMHost (Get-VMHost -name testesxi001*) | Where-Object {$_.key -eq 'ntpd'} | Start-VMHostServiceNTPの起動ポリシー
形式
Get-VmHostService -VMHost $ESXiホスト名もしくはIP | Where-Object {$_.key -eq 'ntpd'} | Set-VMHostService -policy $ポリシータイプサンプル
Get-VmHostService -VMHost (Get-VMHost -name testesxi001*) | Where-Object {$_.key -eq 'ntpd'} | Set-VMHostService -policy 'on'NTPのポリシータイプ
| ポリシータイプ | vSphere Client上の表示 |
| off | 手動で起動および停止 |
| on | ホストと連動して起動および停止 |
| automatic | ポートの使用状況にしたがった起動および停止 |
NTP設定削除
NTP設定の削除
形式
Remove-VMHostNtpServer -VMHost $ESXiホスト名もしくはIP -NtpServer $NTPサーバー
サンプル
Remove-VMHostNtpServer -VMHost (Get-VMHost -name testesxi001*) -NtpServer "192.168.10.132","192.168.10.137" -Confirm:$false
NTPサービスの停止
形式
Get-VmHostService -VMHost $ESXiホスト名もしくはIP | Where-Object {$_.key -eq 'ntpd'} | Stop-VMHostServiceサンプル
-Confirm:$falseを付けると確認なしで停止する。
Get-VmHostService -VMHost (Get-VMHost -name testesxi001*) | Where-Object {$_.key -eq 'ntpd'} | Stop-VMHostService -Confirm:$false
NTP設定確認
NTPの設定確認
形式
Get-VMHostNtpServer -VMHost $ESXiホスト名もしくはIP
サンプル
Get-VMHostNtpServer -VMHost (Get-VMHost -name testesxi001*)
複数台のホスト一括で出力しても、見にくいため1台ずつ確認の方がよさそう?
NTPサービス状態・起動ポリシー確認
形式
Get-VmHostService -VMHost $ESXiホスト名もしくはIP | Where-Object {$_.key -eq 'ntpd'}サンプル
Get-VmHostService -VMHost (Get-VMHost -name testesxi001*) | Where-Object {$_.key -eq 'ntpd'}
NTPファイアウォールの確認
NTPのサービスの起動停止によって自動的にFirewallが設定されますが、下記のコマンドでファイアウォールの状態も確認できます。
形式
Get-VMHostFirewallException -VMHost $ESXiホスト名もしくはIP | Where-Object {$_.name -eq 'NTP client'}サンプル
Get-VMHostFirewallException -VMHost (Get-VMHost -name testesxi001*) | Where-Object {$_.name -eq 'NTP client'} | Format-Table -AutoSize -Wrap
参考
公式
https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/add-vmhostntpserver/#Default
外部
VMWare Powercli: Time Configuration (NTP - Network Time Protocol) on multiple Esxi server
まとめ
下記のでvSphere上のすべてのホストに一括でNTP設定が行えます。
#ESXiホストのリストを取得
$VMHOSTS = Get-VMHost | sort-object
# NTPサーバー設定
Add-VMHostNtpServer -VMHost $VMHOSTS -NtpServer "192.168.10.132","192.168.10.137"
# NTPサービス起動
Get-VmHostService -VMHost $VMHOSTS | Where-Object {$_.key -eq 'ntpd'} | Start-VMHostService
# NTPポリシー設定
Get-VmHostService -VMHost $VMHOSTS | Where-Object {$_.key -eq 'ntpd'} | Set-VMHostService -policy 'on'
時刻同期の確認は、ESXiにSSHしてntpqコマンドから確認するしかなさそうですねぇ・・・・。
