Having the correct time on your server is important for both you and your clients. The problem is that the locks on most servers tend to drift a bit. This can cause problems with your clients sites (forum posts, for example can get out of order if the time drifts a lot) or if you need to compare / share server logs with anyone else.
The ‘old school’ method to keep the server time in sync was using the rdate command. While this method works, rdate was typically run via cron (once per day) and the clock can drift a lot in 24 hours.
We suggest using the ntp daemon to keep your time in sync. ntp stands for network time protocal. The difference between ntp and rdate is that ntp constantly micro-adjusts the clock keeping it totally accurate. ntpd does this by communicating with different ntp servers.
Installing ntp is quite easy.
On CentOS/Fedora servers:
yum install ntp
on Debian/Ubuntu servers
apt-get install ntp
The configuration file is located at /etc/ntp.conf. You don’t really need to change anything in the configuration file as the default configuration has several ntp servers listed. If you do want to use different ntp servers you simply change the “server” lines. The default CetnOS configuration looks like this:
# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). server 0.centos.pool.ntp.org server 1.centos.pool.ntp.org server 2.centos.pool.ntp.org
Changes would look something like this:
# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). server my.ntp.server1 server my.ntp.server2
You can list as many servers as you like, but it’s suggested to have a minimum of two. ntp will automatically switch between servers if it can’t contact the server that it’s currently using.
The last thing we need to do is start ntp and set it to start on boot. In Debian and Ubuntu this is done automatically by apt-get. In CentOS and Fedeora we have to do it ourselves, but it’s quite easy:
service ntpd start chkconfig ntpd on
The ntpd daemon will now keep your server clock constantly synchronized and you’ll no longer have to deal with the clock drifting.
2 Responses to "Syncing your server time with ntp"
Leave a Reply Click here to cancel reply.
Categories
Tag Cloud
ATT Blog CloudFlare CloudLinux CMS cPanel dedicated Drupal email FTP Joomla lizzie Magento MySQL nds ntp Railgun Reseller Hosting security Shared Hosting Softaculous VPS W3 Total Cache WooCommerce WordPress WP Super CacheArchives
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- September 2011
- July 2011
- June 2011
Hey Guys,
Thanks for the very straightforward tutorial. I do have a question. How can I check that ntp is actually working?
Hello PitaBread,
The best way to check it is using the ntpq command. You’ve just given me an idea for another ‘how to’.