Simple NTP Setup On Your Linux Servers

The Network Time Protocol (NTP) runs over port 123 UDP at transport Layera and is used to synchronize a computer’s time with another computer- usually a centralized time server. Not all clocks run at exactly at same speed. After a long enough period, the time of one clock will either end up ahead or behind another, causing what's called a "time drift". This situation can lead to inconsistent time issues, especially on servers. Issues like wrong times in log files, for cron jobs, for servers resources or databases replicatation etc. The NTP server package are already available from official CentOS repositories and can be installed using the following command.

LinuxSuit ~# yum install ntp

When the package is successfully installed it's time to configure the NTP server. NTP is configured and controlled via a control file called conveniently called "ntp.conf," and you can find it in /etc/ntp.conf directory. NTP configuration is usually comprised of two parts. First is list of servers for our NTP to sync time with and second is list of networks that are allowed to query our server for time synchronization . For first part, we are going to add a server list provided by www.pool.ntp.org. You can choose your Continent , then search for your Country and a list of NTP servers will be provided. Then you just need to copy+paste that list into the configuration file. It should look something like this

server 0.centos.pool.ntp.org server 1.centos.pool.ntp.org server 2.centos.pool.ntp.org server 3.centos.pool.ntp.org

For 2nd part we are going to allow our local network to query our server and localhost to get full access to query or modify.

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap restrict 127.0.0.1

We also can specify the drift file and the log file location in our configuration.

driftfile /var/lib/ntp/ntp.drift logfile /var/log/ntp.log

When the configuration is finished, save and close the configuration file, then restart the ntp service.

LinuxSuit ~# service ntp restart

That's basically it. Your NTP should be set up, ensuring that your server is synchronized with your regional time allowing you to avoid time-sensitive errors. Just in case you were wondering, ServerSuit does offer NTP already preconfigured to just add to your servers whenever you might need it. Not that it's hard to set up, but we got a whole set of software available, also preconfigured, so why not include NTP?

That's it for this article. Our next one will cover disk performance monitoring, so look out for that in the near future!



Until next time!