What is NTP?
Its name is fairly self-explanatory — the Network Time Protocol is a protocol used to synchronize internal clock times on computers in a network. This applies to synchronizing clock times with a server on the Internet, as well as synchronizing machines on a local network. It’s typically used in a client-server configuration, but also supports peer-to-peer time synchronization. NTP is used to sync to Coordinated Universal Time (UTC), while timezone management is handled by the operating system. Keeping correct time is particularly important for logging, networking, and even more so on clustered and distributed computer systems.
Now, we can’t really install a protocol but what we will actually be installing is the NTP daemon, or ntpd. Daemons are operating system programs that run in the background without needing any intervention. While computers are very intelligent, they are still just machines which are subject to small fluctuations in the electronic components. This can cause a time drift . A time drift is a small inconsistency in timekeeping. The NTP daemon will handle clock time syncing automatically by querying an NTP server at regular time intervals to correct those discrepancies.
Installing ntpd
Installations on CentOS and other RedHat based distributions are typically best handled best using the yum tool.
yum install -y ntp
systemctl start ntp
systemctl enable ntpd
systemctl status ntpd ntpdate -u -s 0.centos.pool.ntp.org 1.centos.pool.ntp.org 2.centos.pool.ntp.org
systemctl restart ntpd
timedatectl hwclock -w
Add crontab to update after reboot
crontab -e
add the following line and save
@reboot /usr/sbin/ntpdate -b -s -u 1.asia.pool.ntp.org
Synchronize to an NTP server
The ntpdate command followed by the hostname or IP address of an NTPd server can be used to configure a client to use the target NTPd server.
ntpdate -u -s 1.asia.pool.ntp.org