VMware Cloud Community
GlobalHero
Contributor
Contributor

ESX 4.1 - Enable NTP-Client via Script

Hey Guys,

I need your help.

I'm scripting the ESX-Installation and all that stuff.

Now I found that in ESX 4.1 the configuration of the ntp-service isn't that easy - I'm using the following script:

############################################################

/etc/init.d/ntpd start

echo "restrict 127.0.0.1" > /etc/ntp.conf

echo "restrict kod nomodify notrap noquery nopeer" >> /etc/ntp.conf

echo "server ntpserver1" >> /etc/ntp.conf

echo "server ntpserver2" >> /etc/ntp.conf

echo "server ntpserver3" >> /etc/ntp.conf

echo "server 127.127.1.0" >> /etc/ntp.conf

echo "driftfile /var/lib/ntp/drift" >> /etc/ntp.conf

echo "ntpserver1" > /etc/ntp/step-tickers

echo "ntpserver2" >> /etc/ntp/step-tickers

echo "ntpserver3" >> /etc/ntp/step-tickers

/etc/init.d/ntpd restart

chkconfig --level 345 ntpd on

############################################################

After running all these nice commands everything is fine - The ntp-daemon ist started (/etc/init.d), all my ntp-servers are set in the files (/etc/ntp.conf & /etc/ntp/step-tickers) and the service is set to "autostart" (chkconfig).

But now there is the problem:

If I reboot the server than the ntp-service is stopped and the chkconfig-settings are set to default (disabled all runlevels)!

I found that if I set the option "NTP Client Enabled" (see screenshot) via the GUI / vSphere-Client than the settings stay also after a reboot.

11610_11610.jpg

So does anyone know how to script the "NTP Client Enabled" option or is there another way?

Thank you

Reply
0 Kudos
8 Replies
GlobalHero
Contributor
Contributor

No solution yet?

Where are the Pros?! Smiley Happy

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal

here's an example of a s script we use to configure NTP

########################################
# Configure NTP, and also add our timeserver
######################################## 
# where to get time when starting 
/bin/echo "server 1.1.1.1" >> /etc/ntp/step-tickers
/bin/echo "server 1.1.1.2" >> /etc/ntp/step-tickers


# /etc/ntp.conf
/bin/cp /etc/ntp.conf /etc/ntp.conf.orig
/bin/cat /dev/null>/etc/ntp.conf
/bin/cat <<EOF >>/etc/ntp.conf
restrict kod nomodify notrap noquery nopeer
restrict 127.0.0.1
server 1.1.1.1
server 1.1.1.2
driftfile /var/lib/ntp/drift

EOF


########################################
# NTP Hardware Sync
########################################
/sbin/chkconfig --level 345 ntpd on 
/etc/init.d/ntpd start 
/sbin/hwclock --systohc

Reply
0 Kudos
GlobalHero
Contributor
Contributor

Hi Troy Clavell,

sorry but this is exactly what I'm already using in my script!

Do you use this in ESX 4.1? - Does it work? - Also after a system-reboot?

As I said, everything is fine but after a reboot of the ESX-Server the NTP-Client is not running because in chkconfig the autostart of the

ntp-daemon is disabled!

I think the Option "Enable NTP-Client" in vSphere Client (see my screenshot before) overwrites my settings because it's not set via the GUI?!

I already tried to get support from VMware (opened a ticket) - But to get support with scripting you need "Mission Critical" support contract!

Can anyone help please?

Thanx

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal

you may try using PowerCLI then. Below is a good example

Reply
0 Kudos
GlobalHero
Contributor
Contributor

Hi I'm back 🙂

I found something in this thread:

http://communities.vmware.com/thread/95844

The NTP-Client depends on the esx firewall-ports!

In our environment we're disabling the esx-firewall - But as I found now, we have to open the ports as well:

esxcfg-firewall -e ntpClient

The reason is the following option:

NTP-Client.jpg

So I'm asking (as the guy in the linked article) does anyone know how to set that option via commandline?

Thank you

Reply
0 Kudos
GlobalHero
Contributor
Contributor

No ideas out there? :smileyconfused:

Reply
0 Kudos
dmustakasjr
Contributor
Contributor

I am also interested in setting NTP at %firstboot during the provisionnig of a new host. I had found the firewall work around (esxcfg-firewall -e ntpClient) but I am at the same impasse with regards to the other settings (apparently so easily accessable via the GUI) Smiley Happy

vRico Virtualization Enthusiast VCP 3&4, MCITP EA and a bunch of other stuff
Reply
0 Kudos
GlobalHero
Contributor
Contributor

Yeah,

another guy having the same question out there!  Smiley Happy

So is there nobody who can help?

Reply
0 Kudos