Visit Our UNIX and Linux User Community


Best way to sync time on a Linux machine

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Best way to sync time on a Linux machine
# 1  
Old 10-01-2013
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:

Code:
* 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:
Code:
server instructor.example.com

and line

Code:
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

Last edited by Scrutinizer; 10-01-2013 at 03:11 AM.. Reason: ct
# 2  
Old 10-01-2013
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.
# 3  
Old 10-01-2013
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..
# 4  
Old 10-01-2013
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
# 5  
Old 10-01-2013
In general, it would be better to use time servers based in India. See NTP Servers in India (in.pool.ntp.org) for example.
# 6  
Old 10-03-2013
You don't need to use cron to run ntpdate - it's a service.

Code:
# chkconfig --level 345 ntpdate on

Code:
#!/bin/bash
#
# chkconfig: - 57 75
# description: set the date and time via NTP
...

# 7  
Old 10-03-2013
Thanks for your answer. Is it possible to know the time on the servers before syncing? the servers mentioned are

Code:
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:

Code:
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

Last edited by Scott; 10-03-2013 at 05:28 AM.. Reason: The next time you post without code tags or bump a post, I will ban you.

Previous Thread | Next Thread
Test Your Knowledge in Computers #783
Difficulty: Medium
Microsoft launched its first retail version of Microsoft Windows in 1983.
True or False?

9 More Discussions You Might Find Interesting

1. Solaris

Rebooting Windows machine leads to continue sync reset on UNIX

Hello, We have Windows 10 machine connected to Sparc T5440 server via serial cable. We access the server from the Windows 10 machine using putty via serial connection. This allows us to access ILOM and Unix. We have recently noticed that whenever we reboot the windows machine (Windows 10),... (11 Replies)
Discussion started by: jasonu
11 Replies

2. Shell Programming and Scripting

Rsync from remote machine via ssh and sync by uisng find by modified time

Hi I have a requirement to rsync from remote to local machine via ssh and sync files that are changed in last n hours. pgrep to check if no other sync is running pgrep -f rsync.*/opt > /dev/null || rsync --bwlimit=10000 -avz --delete root@X.X.X.X:/var/source/ /opt/dest/ >> /home/log 2>&1... (0 Replies)
Discussion started by: robo
0 Replies

3. Red Hat

How to sync time with bios in rhel7?

Hi All, I deployed the rhel7 server in the bare metal hardware. I want to configure the rhel7 server to sync time with bios. I tired the below commands. Still it did not sync the time with bios. Thanks, Kalai (3 Replies)
Discussion started by: kalpeer
3 Replies

4. Linux

Questions about the NTP time server sync

Hi folks, I have developed a Linux server for my customer. After migrating the server to my customer site, I was trying to sync its time to the NTP time servers at my customer site. Below is the ntp.conf: % vi /etc/ntp.conf # Permit time synchronization with our time source, but do not # permit... (2 Replies)
Discussion started by: kimurayuki
2 Replies

5. Red Hat

Time Sync issue on RHEL 5.3

Hi, My Linux VMs are running on citrix XEN.Somehow the time drift is too high (going very fast). Even if the correct time configured using date -s command, for every 1 hr it is differing almost 5 - 10 mins. Tried configuring ntpd (local NTP server) and still it is not synchronized. Machine... (2 Replies)
Discussion started by: uday123
2 Replies

6. Solaris

NTP time sync in Solaris 10

Ok, I have 4 production systems. There is one NTP server for all four systems. In each system there is one Solaris 10 box that points to that NTP server. All of the other machines in the system point to the Solaris 10 machine to get their time sync. All four Solaris 10 machines have essentially... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

7. SuSE

unable to sync the time with ntp server

Hi folks, The server time is no tgetiing synched up with the NTP server. I tried ntpdate -u <ipadress> this is not working. please help out. regards, Sag. (7 Replies)
Discussion started by: sag71155
7 Replies

8. UNIX for Advanced & Expert Users

How To Provide Time Sync Using Nts-150 Time Server On Unix Network?

can anybody tel lme,how to instal NTS -150 on a unix network,it needs some patch to fetch time frm serve,,?? (2 Replies)
Discussion started by: pesty
2 Replies

9. UNIX for Dummies Questions & Answers

TIME SYNC (NTP)

Is there a utility which offers the ability to utilize NTP to sync time on machine. If so please point to man page or web site (3 Replies)
Discussion started by: SmartJuniorUnix
3 Replies

Featured Tech Videos