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

Steps of building ntp server under linux

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

Share

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

This article mainly explains "the steps of building a ntp server under linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the steps of building a ntp server under linux.

First, set up a time server

1. Install ntp server on a linux server

Tar zxvf ntp-4.2.6.tar.gz

Cd ntp-4.2.6

. / configure-- prefix=/usr/local/ntp-- enable-all-clocks-- enable-parse-clocks

Make & & make install

2. Modify ntp.conf configuration file

Vi / etc/ntp.conf

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

# restrict default kod nomodify notrap nopeer noquery

Restrict default nomodify

(allows any client of IP to synchronize time, if only clients of a certain network segment are allowed to synchronize time

Restrict 10.58.26.0 mask 255.255.255.0 nomodify)

Restrict-6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface. This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

Restrict 127.0.0.1

Restrict-6:: 1

# Hosts on local network are less restricted.

# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool

# server 0.rhel.pool.ntp.org (default time server)

# server 1.rhel.pool.ntp.org (default time server)

# server 2.rhel.pool.ntp.org (default time server)

Server 10.128.14.25 (manually set time server)

(if you can connect directly to the public network, you can use the three groups of standard time servers provided by LINUX by default, otherwise you can specify a synchronization time source yourself)

# broadcast 192.168.1.255 key 42 # broadcast server

# broadcastclient # broadcastclient

# broadcast 224.0.1.1 key 42 # multicast server

# multicastclient 224.0.1.1 # multicastclient

# manycastserver 239.255.254.254 # manycastserver

# manycastclient 239.255.254.254 key 42 # manycastclient

# Undisciplined Local Clock. This is a fake driver intended for backup

# and when no outside source of synchronized time is available.

Server 127.127.1.0 # local clock

Fudge 127.127.1.0 stratum 10

3. Start ntpd with daemon

# / etc/rc.d/init.d/ntpd-c / etc/ntp.conf-p / tmp/ntpd.pid

# / etc/rc.d/init.d/ntpd start

# ps-ef | grep ntpd

4. After starting the ntp service on ntp server, it takes a period of time for ntp server itself or its server to synchronize, which may take 5 minutes. During this time, a no server suitable for synchronization found error will occur when the client runs the ntpdate command to synchronize.

So how do you know when ntp server has finished synchronizing with itself?

Use the command on ntp server:

# watch ntpq-p

The following picture appears:

Notice that this in LOCAL is the ntp server that is synchronized with itself.

Note the value of reach, which increases from 0 after starting the ntp server service. When it increases to 17, there are 5 changes from 0 to 17, and each time is the number of seconds of the value of poll, which is 64 seconds * 5 seconds 320 seconds.

Configure the time synchronization client

Vi / var/spool/cron/root (or crontab-e)

Add one line to synchronize with the time synchronization server and write to BIOS at 01:10, 09:10 and 17:10 every day

10 1,9 root 17 * root / usr/sbin/ntpdate 10.128.14.25; / sbin/hwclock-w

* / 2 * root / usr/sbin/ntpdate 10.128.14.25; / sbin/hwclock-w

If the synchronization is not normal, you can add the output log or view the system log

How to output the log:

10 1,9 sbin/hwclock 17 * root / usr/sbin/ntpdate 10.128.14.25 > > / tmp/1.txt; / sbin/hwclock-w

You can view the output of time synchronization in 1.txt.

Or check / var/mail/root system log

Subject: Cron / usr/sbin/ntpdate 10.128.14.25

X-Cron-Env:

X-Cron-Env:

X-Cron-Env:

X-Cron-Env:

X-Cron-Env:

Message-Id:

Date: Tue, 27 Nov 2012 18:30:01 + 0800 (CST)

27 Nov 18:29:59 ntpdate [6917]: step time server 10.128.14.25 offset-1.361968 sec

You can see that the synchronization is successful, and an error will be reported if it is not successful.

Third, the problem of unable to synchronize

Check the firewall of the ntp server host. It may be that ntp server's firewall blocks upd port 123.

You can use commands.

# service iptables stop

To shut down the iptables service and then try to synchronize from the ntp client. If successful, it is proved to be a firewall problem and you need to change the iptables settings.

At this point, I believe you have a deeper understanding of "the steps to build a ntp server under linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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: 0

*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