E-commerce sites need to know the correct time. Network Time Protocol (NTP) and the identically named
ntp time server software (notice the small letters) are tools you can use to make sure your systems constantly sync their time with other, more accurate time servers. Time is a crucial component of scaling websites to multiple servers. Timestamps provide all the individual servers a common time with which to create timestamps.
Finding Time Servers
In order to update your server’s time, you first need to find servers with which to synchronize. The NTP Pool Project provides a directory of network time servers that are close geographically to your server and that are free to use.
Remember to find a time server close to your e-commerce server, not close to where you are. For example, if you are located in Australia but your e-commerce server is located in the United States, be sure to find time servers located in the United States. By going through the NTP Pool Project, I was able to find the time server pool for the US
Make sure you don’t just copy these servers replacing us with a different country code as the pool servers might be different. As an example, the server pool for Iceland is
As you can see, the server pool can vary drastically from country to country.
Manual Updates With ntpdate
Before I explain how to set up automatic updates in the next section, I wanted to touch on how to do a simple one-off synchronization. A manual update might be necessary if you have a brand new server and you want to synchronize as soon as possible or if you want to make sure you are synchronized right away with a particular time server. Manual time updates are easy with the
On your Debian GNU/Linux server, begin by installing
# apt-get install ntpdate
Then simply run the
ntpdate command providing your desired time server as an argument. Assuming you want to sync with
2.us.pool.ntp.org, run the command
# ntpdate 2.us.pool.ntp.org
Your server’s time will then be synchronized one-time, right now with
2.us.pool.ntp.org. ntpdate is not a good long-term solution however as the time between the actual time and your server’s time will diverge. The longer the times are not synchronized, the more divergence there will be. For true, automatic time synchronization, use the ntp tool as described in the next section.
For true, automated and repeated server time synchronization, ntp is the best solution. ntp is a time server that runs on your Linux server which automatically syncs with a time server pool (see the section above for more on finding your nearest pool).
Installing ntp is simple if you have root access to your server. On Debian, simply run
# apt-get install ntp
Basic NTP Configuration
ntp configuration can be a very complex topic as it requires an understanding of much more than the need for synching time. For that reason, I will go into more detail on configuration in future articles. For now, the most important thing you need to know is that the configuration file is
/etc/ntp.conf. Open up that file and add your pool time servers, replacing the time server pool listed. After that simply restart ntp:
# service ntp restart
That’s it! You have a perfectly configured NTP time server ready to keep your E-commerce server or servers up to date.