The Network Time Protocol daemon (ntpd) is a daemon of the Linux operating system. It is a complete implementation of NTP and is used to correct the time difference between the local system and the clock source server. Unlike ntpdate, which updates time periodically, ntpd corrects time continuously without time gaps. This document uses CentOS 7.5 as an example to describe how to install and configure ntpd.
systemctl is-active ntpd.servicecommand to see if ntpd is running.
systemctl is-enabled ntpd.servicecommand to see if ntpd is configured to launch automatically at startup.
Run the following command to check whether ntpd has been installed.
rpm -qa | grep ntp
yum install ntpcommand to install it.
yum -y install ntp
ntpd uses the client mode by default.
Run the following command to open the configuration file of the NTP service.
Press i to switch to the editing mode and locate the
server configurations. Change the value of
server to the NTP clock source server you want to use (such as
time1.tencentyun.com) and delete unwanted values, as shown below:
Press Esc and enter :wq to save and close the file.
Run the following command to restart the ntpd service.
systemctl restart ntpd.service
Run the following commands to check the status of ntpd as needed.
If the following result is returned, the listening is normal.
service ntpd status
If the following result is returned, the ntpd status is normal.
The following result will be returned:
pollvalue will be smaller, which indicates a higher synchronization frequency, so that the time can be adjusted to the correct time range as soon as possible. Later, the
pollvalue will gradually increase, and the synchronization frequency will decrease accordingly.
Run the following command to automatically launch ntpd at startup.
systemctl enable ntpd.service
Run the following command to check whether chrony is set to launch at startup.
systemctl is-enabled chronyd.service
If chrony is set to launch at startup, run the following command to remove chrony from the auto-start list.
chrony is not compatible with ntpd, which may lead to ntpd start failure.
systemctl disable chronyd.service
Run the following commands sequentially to enhance the security of the
/etc/ntp.conf configuration file.
interface ignore wildcard
interface listen eth0