Best way to sync time on a Linux machine

I wanted to know which should be the best way to sync time for a linux machine. We have an application server and a database server, both using RHEL 5.8 as the OS. It is important that the time on both these servers match together and also sync with a common time source. As per my knowledge, these are the 2 ways which can be explained as follows considering the common source as instructor.example.com, it can also be assumed that desktop1.example.com & desktop2.example.com are the hostnames of the other 2 machines

1) Add a cron job with the command, ntpdate to sync with the time on instructor.example.com. The cron job could be scheduled once a day something as follows:

* 1 * * * /usr/sbin/ntpdate -b instructor.example.com

2) Configure the /etc/ntp.conf on the 2 machines, desktop1.example.com & desktop2.example.com to include the line like:

server instructor.example.com

and line

peer desktop1.example.com

for desktop2.example.com and vice-versa for desktop1.example.com.

There are few observations in this also:

1) By adding server 0.rhel.pool.ntp.org, it should be aligning the time with public time server but would it be reliable?

2) By including the peer, should it help maintaining the time for desktop1.example.com & desktop2.example.com to be close to each other. This would mean that the 3 machines in picture including the server would have a time close to each other.

I had put this query in another forum but I have not got any replies from that.

I hope my question is clear.

Please revert with the reply to my query.

Regards

---------- Post updated 10-01-13 at 12:03 AM ---------- Previous update was 09-30-13 at 01:29 AM ----------

Request people in this forum to please revert.

Regards

I'm not commenting on your approach in general. But, if you are in an area that observes daylight savings time shifts or the server you're connecting to as a time server is in an area that observes daylight savings time shifts, NEVER use 1am or 2am or anytime between 1am and 2am as the time to kick off a cron job to synchronize times.

Don't bother with the peer line, just let the two servers sync to a reliable common time source, using the same ntp.conf. There are many examples in the documentation how to set this up. If the local clock of the servers is too far off, then initially servers will have trouble syncing, that is why usually when a server boots the ntpd start script first performs an ntpdate to leap to the right time before ntpd takes over. Once the server's time is in sync with ntpd there should be no need for any further ntpdate commands..

Thanks for your answer. I had 2 points to put fo which I would request elaborate & detailed answers:

1) Are the public servers as put by me a reliable source? Also, I am located in India, so which public server should be ideal as a time source.

2) Is the peer command going to help by having the 3 machines in picture including the server have a time close to each other?

Regards

---------- Post updated at 09:16 AM ---------- Previous update was at 09:12 AM ----------

Thanks for your answer but may I request you to please give a detailed &
elaborate answer on what should be the ideal configuration with the scenario given by me in mind.

Regards

In general, it would be better to use time servers based in India. See NTP Servers in India (in.pool.ntp.org) for example.

You don't need to use cron to run ntpdate - it's a service.

# chkconfig --level 345 ntpdate on
#!/bin/bash
#
# chkconfig: - 57 75
# description: set the date and time via NTP
...

Thanks for your answer. Is it possible to know the time on the servers before syncing? the servers mentioned are

server 3.in.pool.ntp.org
server 1.asia.pool.ntp.org
server 0.asia.pool.ntp.org.

I hope my question is clear of knowing the time on the mentioned servers before putting these servers in the configuration files of the NTP service.

Request you to please revert.

Regards

---------- Post updated at 03:25 AM ---------- Previous update was at 03:17 AM ----------

My basic requirement was to set the time on my RHEL system to a reference time on another machine like:

ntpdate -b instructor.example.com.

So, in the scenario mentioned by me above, it should be one of the options to run a cron job.

I hope, my question is clear.

Regards

I don't see how. Test NTP on a non-production system with these time servers before deploying it to production. The point of having multiple servers is to mitigate against errors.

Also, reading the man page, it's not necessary to run ntpdate at all. ntpd supports this functionality. Add -q to the ntpd startup options instead.

I guess there is some confusion, what I meant is that if the ntpd service is not running and we need to sync the clock once or at regular intervals, only then the ntpdate command would be helpful.

I hope, my query is clear now that the ntpdate command to be used only if the service ntpd service is not running.

Regards

If time is a critical issue for your server then it makes no sense not to run ntpd. But if you only want to update the time periodically, as you suggest, then ntpdate is fine.

Thanks for your answer, I tried ntpdate but it giving error like:

ntpdate[5771]: no server suitable for synchronization found

I tried to sync server1 with server2 where the time difference between the servers is less than 1 minute. For e.g. I gave,

ntpdate -b <server2> 

from server1.

Request you to throw light on this so that the understanding can become completely clear on this.

Regards

server2 isn't an NTP server.

You'll notice that your account it read-only. It will be so for one day. That should give you enough time to re-read the rules. For your convenience, I have copied a link to them here. Perhaps in the future you will kindly revert to our requests to use

```text
```

tags.

1 Like