Tuesday, May 24, 2016

How to sync time between servers.

Recently when I was working with a WSO2 Identity server cluster I needed server time to be sync between all nodes (servers). I used Centos and below are the steps I used.

1. Install ntpdate using

sudo yum install ntpdate

2. Synced time with 'sltime.org' time server

3. Created a shell script to run above command every 6 hours.


  • Create a file given .sh as the extension  (vi synctime.sh)
  • Add below into the created file. (This loop runs 120 times. System is syncing time to time server every 6 hours.)

for i in {1..120}
do
  sudo ntpdate sltime.org
  sleep 6h
done

  • Give execute permission to 'synctime.sh' file created before. 
  • Run the shell script in background.
./synctime.sh &

When I searched I also came across below blog post which I think is a better approach. Also check that our :)

http://www.cyberciti.biz/faq/howto-install-ntp-to-synchronize-server-clock/
http://www.pool.ntp.org/zone/lk

No comments:

Post a Comment