1. Overview
Network Time Protocol (NTP) is a protocol used to synchronize computer time. It can synchronize computers with their servers or clock sources (such as quartzels and GPS, it provides high-precision time correction (the difference between the LAN and the standard is less than 1 millisecond, And the Wan is dozens of milliseconds), and supports encrypted validation to prevent malicious protocol attacks. (From Baidu encyclopedia)
2. Cluster status
Now, select one of the four Ubuntu hosts as the server that provides the NTP service (server01 ).
3. Install the NTP service
Install ntpserver on the host that provides the NTP service:
apt-get install ntp
4. Configure NTP service parameters
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for helpdriftfile /var/lib/ntp/ntp.drift# Enable this if you want statistics to be logged.#statsdir /var/log/ntpstats/statistics loopstats peerstats clockstatsfilegen loopstats file loopstats type day enablefilegen peerstats file peerstats type day enablefilegen clockstats file clockstats type day enable# Specify one or more NTP servers.# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for# more information.#server 0.ubuntu.pool.ntp.org#server 1.ubuntu.pool.ntp.org#server 2.ubuntu.pool.ntp.org#server 3.ubuntu.pool.ntp.org# Use Ubuntu‘s ntp server as a fallback.#server ntp.ubuntu.comserver 127.127.1.0 minpoll 4 maxpoll 5fudge 127.127.1.0 stratum 2# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for# details. The web page 5. Test the NTP service.
Run the following command on the server that provides the NTP service:
ntpdate -q 127.0.0.1
Expected result:
server 127.0.0.1, stratum 3, offset -0.000018, delay 0.02568 2 Sep 16:11:07 ntpdate[5882]: adjust time server 127.0.0.1 offset -0.000018 sec
It indicates that the startup is normal.
6. Other hosts use it to synchronize time
Run the following command on the host whose synchronization time is required:
ntpdate server01
The result is as follows:
2 Sep 15:53:12 ntpdate[8420]: adjust time server 192.168.1.154 offset 0.497131 sec
Server01 can be either a host name or an IP address.
7. Set the scheduled synchronization time
Use crontab:
crontab -e
Set calibration once per hour:
* */1 * * * /usr/sbin/ntpdate server01
Configure the NTP service for a Ubuntu Cluster