Build an NTP server in Linux
Background
When there are too many servers, it is a big problem whether the time is accurate or not. Although this problem is always ignored, it is necessary to unify the time. The following describes how to configure the Linux time server in the LAN.
For example, if the IP address range is 50.50.50.0/24, the IP address range is IP50.50.50.14.
The 50.50.50.14 server can connect to the Internet and can be synchronized with the authoritative public network time server.
Other machines in the same network segment automatically synchronize time to 50.50.50.14 every hour.
Configuration method
1. Configure the NTP server (assuming the IP address of the server to be configured is 50.50.50.14)
1. The main configuration file of the NTP server is/etc/ntp. conf, which describes the items in/etc/ntp. conf.
# Back up data before configuration
Cd/etc/
Cp ntp. conf ntp. bak. conf
2. vi/etc/ntp. conf (the content of the ntp. conf file is as follows)
# Set the Default policy to allow time synchronization on any host
Restrict default ignore
# Enable the internal Recursive Network Interface lo
Restrict 127.0.0.1
# Enable machines in the network segment of 50.50.50.0/24. You can use this server for network comparison, but you cannot modify the NTP time parameter.
Restrict 50.50.50.0 mask limit 255.0 nomodify
# Set the IP address for time synchronization on the server layer above. prefer means the preferred IP address.
The following servers feel that the time response speed is good.
Server 210.72.145.44 prefer
Server 218.21.130.42
Server 0.asia.pool.ntp.org
Server 1.asia.pool.ntp.org
Server 2.asia.pool.ntp.org
# Specify the class number as 10 to reduce its priority.
Server 127.127.1.0
Fudge 127.127.1.1 stratum 10
# Drifting files
Driftfile/var/lib/ntp/drift
3. Maintenance of NTP server
---- Add as service
Chkconfig -- level 345 ntpd on
---- Start
Service ntpd start
Or
/Etc/rc. d/init. d/ntpd start
---- Stop
Service ntpd stop
Or
/Etc/rc. d/init. d/ntpd stop
# View the time synchronization result between the local server and the upper-layer server
[Root @ dbserver1_14 etc] # ntpq-p
Remote refid st t when poll reach delay offset jitter
========================================================== ==============================================
210.72.145.44. INIT. 16 u-64 0 0.000 0.000
218.21.130.42. INIT. 16 u-64 0 0.000 0.000 0.000
125.62.193.121. INIT. 16 u-64 0 0.000 0.000 0.000
82.200.209.194. INIT. 16 u-64 0 0.000 0.000 0.000
218.189.210.4. INIT. 16 u-64 0 0.000 0.000 0.000
Ntptrace # It can be used to track the time correspondence between a Time Server
Ntpdate IP # The client must synchronize the clock with the NTP server.
3. NTP clent Configuration
# Disabling the nptd Service
Service ntpd stop
# Manual synchronization time with the server
Ntpdate 50.50.50.14
24 Feb 18:32:10 ntpdate [7192]: adjust time server 50.50.50.14 offset 0.050908 sec
# Create a crontab to write the ntp server time to the local clock at half past eight every day
Crontab-e
30 8 * root/usr/sbin/ntpdate 50.50.50.14;/sbin/hwclock-w
# Restart crontab
Service crontab restart
Note: The host firewall must open udp port 123 for Internet access.
CentOS NTP server installation and configuration
NTP servers in Linux
NTP client configurations for multiple operating systems
Build an enterprise-level NTP Time Server
Set up an ntp time synchronization server in Linux
Enable NTP time server in CentOS 6.3
This article permanently updates the link address: