【PowerCLI】ESXiホストのNTP設定

どうも、Tです。

ESXiホストのNTP設定方法です。

スポンサーリンク
アドセンス1

やりたいこと

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"
パラメーター説明
-VMHostESXiのFQDN・ホスト名・IPアドレス
-NtpServerNTPサーバー。複数のときはカンマ区切り。

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-VMHostService

NTPの起動ポリシー

形式

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

参考

公式

Add-VMHostNtpServer Command | VMware PowerCLI Reference
This cmdlet adds the specified NTP servers to the NTP server list of the specified hosts.

外部

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コマンドから確認するしかなさそうですねぇ・・・・。

スポンサーリンク
アドセンス1
アドセンス1
ブログランキング・にほんブログ村へ

シェアする

フォローする