Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux NTP server building

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Construction of Linux time synchronization server

NTP (Network Time Protocol) is a protocol used to synchronize computer time. It uses UDP protocol port 123 to provide external services. It enables computers to synchronize time to their servers or clock sources (such as quartz clock, GPS, etc.). It can provide high precision time correction (the difference between LAN and standard is less than 1 millisecond, tens of milliseconds on WAN). And can be confirmed by encryption to prevent malicious protocols. Time propagates according to the level of the NTP server. All servers are grouped into different Stratum (tiers) according to the distance from the external UTC source.

To do a project today, you need to configure a NTP time synchronization server as a time server for other applications. The environment used is CentOS 6.5, which is done using its own NTP service.

Install the NTP service

[root@ntp ~] # rpm-qa | grep ntp

Ntpdate-4.2.6p5-1.el6.centos.x86_64

Ntp-4.2.6p5-1.el6.centos.x86_64

Fontpackages-filesystem-1.41-1.1.el6.noarch

Use the RPM tool to query, if there are three packages above, the system has already installed the NTP service; if not, mount the installation image, use the following command to install

[root@ntp] # rpm-ivh ntp-4.2.6p5-1.el6.centos.x86_64

[root@ntp] # rpm-ivh ntpdate-4.2.6p5-1.el6.centos.x86_64

Or configure yum for installation

[root@ntp ~] # yum install ntp

Configure the NTP server configuration file

(1) Edit configuration file / etc/ntp.conf file

# restrict192.168.1.0 mask 255.255.255.0 nomodify notrap

/ / find the above configuration, remove the previous # sign, and modify the address range to allow access to the NTP service, such as

Restrict192.168.30.0 mask 255.255.255.0 nomodify notrap

/ / the range of addresses allowed to receive synchronization requests in this example is 192.168.30.0Universe 24.

(2) configure upstream NTP server

Before configuring the upstream NTP server, check that the upstream server is connected properly. If available, modify the NTP configuration file as follows:

Server 210.72.145.44 # China Time Center

Server cn.pool.ntp.org # Pulbic Time Server

Server 202.112.10.36

Server 127.127.1.0 # local clock

Fudge 127.127.1.0 stratum 10

/ / if both server 210.72.145.44 and cn.pool.ntp.org configured in step 2 are invalid, the NTP server will use its own time as the time of the NTP server, that is, synchronize with itself according to the configuration here.

(3) configure NTP service to start

[root@ntp ~] # chkconfig ntpd on

[root@ntp ~] # chkconfig-- list | grep ntpd

Ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off

/ / configure the NTP service to boot automatically

[root@ntp ~] # service ntpd restart

Shutting downntpd: [OK]

Startingntpd: [OK]

/ / restart the NTP service

[root@ntp ~] # service ntpd status

Ntpd (pid 2027) is running...

/ / check whether the NTP service is running properly

[root@ntp ~] # iptables-F

/ / turn off the firewall

(4) Test NTP service

After startup, it usually takes about 5-10 minutes to start synchronizing time with the external time server. You can query the NTPD service through the command.

[root@ntp] # ntpq-p

Remote refid st t when poll reach delay offset jitter

=

210.72.145.44 .INIT. 16u-64 0 0.000 0.000 0.000

85.199.214.101.INIT .16u-64 0 0.000 0.000 0.000

202.112.10.36. Int. 16 u-64 0 0.000 0.000 0.000

* LOCAL (0) .LOCL. 10 l 20 64 77 0.000 0.000 0.000

/ / check the connection to the upstream server.

Find a host to test within the range of addresses that allow the use of time synchronization services

[root@lvuxbcms~] # ntpdate 192.168.100.100

28 May 18:07:50ntpdate [15670]: adjust time server 192.168.100.100 offset 0.444003 sec

/ / use the ntpdate command for time synchronization on host 192.168.30.100

The synchronization is successful and the NTP server is built.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 288

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report