Solve the problem of time synchronization on Linux: Ntp__linux

Source: Internet
Author: User

This article is mainly about their own work in the problems encountered and how to solve, for what is NTP and how to use NTP these concepts are not involved, because these are the content of the Internet, I also refer to these content.

Download the ntp-4.2.4p4.tar.gz compression pack under Windows and unzip it in the Ubuntu virtual machine according to the http://www.51testing.com/html/28/116228-202637.html article. After compiling and installing, the ntp.conf configuration file is not generated in the/etc directory, so it is impossible to talk about modifying the configuration file.

So according to the method of this article: http://www.latelee.org/using-gnu-linux/ubuntu-ntp-note.html

Server-side NTP:

Operating in the company's production environment:

Perform the sudo apt-get install NTP command on the machine that you want to use as the server to install NTP, and after the installation, you will find that the/etc/directory is generated

ntp.conf configuration file, and then for NTP server-side settings follow this article.

The contents of my/etc/ntp.conf file are:

#/etc/ntp.conf, configuration for ntpd; Ntp.conf (5) for help

Driftfile/var/lib/ntp/ntp.drift
# Enable This if you are want statistics to be logged.
#statsdir/var/log/ntpstats/

Statistics Loopstats peerstats clockstats
Filegen loopstats file Loopstats type Day enable
Filegen peerstats file Peerstats type Day enable
Filegen 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). 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

Server 127.127.1.0
Fudge 127.127.1.0 Stratum 8

# use Ubuntu ' s NTP server as a fallback.
Server ntp.ubuntu.com

# Access control configuration; See/usr/share/doc/ntp-doc/html/accopt.html for
# details. The Web page # might also be helpful.
#
# "Restrict" applies to both servers and clients, so a configuration
# that might is intended to the requests from certain clients could
# up blocking replies from your own upstream servers.

# By default, Exchange time with everybody, but don ' t allow configuration.
#modified by Zhangjianjun
#restrict-4 default kod notrap nomodify nopeer noquery
Restrict-4 default Noquery
restrict-6 default Kod notrap nomodify nopeer noquery

# Local Users may interrogate the NTP server more closely.
Restrict 127.0.0.1
Restrict:: 1

# Clients from-(example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 Mask 255.255.255.0 notrust

# If you are want to provide time to your local subnet and change the next line.
# (Again, the address is a example only.)
#broadcast 192.168.123.255

# If you are want to listen to broadcasts on your local subnet, de-comment the
# Next lines. Please does this is only if your everybody on the network!
#disable Auth
#broadcastclient


NTP Client:

Use your Ubuntu virtual machine as an NTP client, then unzip, compile, and install ntp-4.2.4p4.tar.gz on the virtual machine.

Ntpdate-d (10.0.xx.xx) (server-side IP address), to be successful, the client must be able to ping the IP address on the server side,

This discovery can be performed successfully.

linux@ubuntu:~ $sudo ntpdate-d 10.0.24.25
14:33:10 ntpdate[6515]: ntpdate 4.2.6p3@1.2290-o Tue June 5 20:12:12 UTC 2012 (1)
Looking for host 10.0.24.25 and service NTP
Host found:10.0.24.25
Transmit (10.0.24.25)
Receive (10.0.24.25)
Transmit (10.0.24.25)
Receive (10.0.24.25)
Transmit (10.0.24.25)
Receive (10.0.24.25)
Transmit (10.0.24.25)
Receive (10.0.24.25)
Transmit (10.0.24.25)
Server 10.0.24.25, Port 123
Stratum 3, precision-22, Leap, trust 000
refID [10.0.24.25], delay 0.02652, dispersion 0.00002
Transmitted 4, in filter 4
Reference time:de193b90.11525693 Mon, 29 2018 14:20:00.067
Originate Timestamp:de193e0f.43fffb69 Mon, 29 2018 14:30:39.265
Transmit timestamp:de193ebb.8f7b7817 Mon, 29 2018 14:33:31.560
Filter delay:0.02652 0.02654 0.02654 0.02658
0.00000 0.00000 0.00000 0.00000
Filter Offset: -172.295-172.295-172.295-172.295
0.000000 0.000000 0.000000 0.000000
Delay 0.02652, dispersion 0.00002
offset-172.295461


14:33:33 ntpdate[6515]: Step time Server 10.0.24.25 offset-172.295461 sec

But found that the client's time has not changed at all, the client's time deliberately adjusted, although the implementation of success, the client's time has not been corrected,
After a number of attempts to finally find: The following methods to implement, there is no problem
Execute First: Sudontpdate-u 10.0.24.25
Re-execution: sudontpdate-d 10.0.24.25

Print information output after execution of the second line some changes, see the red part
15:13:04 ntpdate[6581]: ntpdate 4.2.6p3@1.2290-o Tue June 5 20:12:12 UTC 2012 (1)
Looking for host 10.0.24.25 and service NTP
Host found:10.0.24.25
Transmit (10.0.24.25)
Receive (10.0.24.25)
Transmit (10.0.24.25)
Receive (10.0.24.25)
Transmit (10.0.24.25)
Receive (10.0.24.25)
Transmit (10.0.24.25)
Receive (10.0.24.25)
Transmit (10.0.24.25)
Server 10.0.24.25, Port 123
Stratum 3, precision-22, Leap, trust 000
refID [10.0.24.25], delay 0.02647, dispersion 0.00005
Transmitted 4, in filter 4
Reference time:de1947b9.084ab653 Mon, 29 2018 15:11:53.032
Originate TIMESTAMP:DE194815.5E2B1C2A Mon, 29 2018 15:13:25.367
Transmit TIMESTAMP:DE194815.5DDECFC4 Mon, 29 2018 15:13:25.366
Filter delay:0.02657 0.02655 0.02649 0.02647
0.00000 0.00000 0.00000 0.00000
Filter offset:0.000530 0.000550 0.000625 0.000664
0.000000 0.000000 0.000000 0.000000
Delay 0.02647, dispersion 0.00005
Offset 0.000664

15:13:27 ntpdate[6581]: Adjust time server10.0.24.25 offset 0.000664 sec

By contrast, it is found that only the output print information is adjust time server to take effect.

Specifically why this operation, I do not know, this is only inadvertently this operation when found that the client's time with the client has been synchronized

Another problem encountered in the project is that the time zone of the Linux system running on each machine is not the same, but so even if we get through it,

Time is not the same when it is displayed, so it is necessary to change the time zone under Linux, we first modify the time zone on each Linux system to the same time zone, and then

In the time synchronization can be.

Reference Link: http://blog.51cto.com/13178102/2055701


To this thought will change the end, but there is a problem, that is, our program is running on the target version (MIPS architecture), not running on the x86 architecture. Therefore, you cannot use

The above method to set NTP server, because no longer MIPS architecture Linux using the apt-get command to install the NTP server program, you must find the source code and then cross-compile the line.

Therefore must use the source code to cross compiles, through the experiment to know, uses previously downloaded ntp-4.2.4p4.tar.gz (best uses this version, because we experimented several versions, is not the configuration error, is compiles the error, only this version does not have any question) to be possible.

As mentioned earlier, using decompression, compilation, and installation is not going to get the ntp.conf configuration file, so I kept a copy of the configuration file that was generated using sudo apt-get install NTP (if you use Apt-get Remove to uninstall the installed software, All the configuration files will be deleted, before I have the/etc directory of the ntp.conf copies of a copy of the Ntp.conf.bak, the results were removed when the software was deleted, in this case, the copy of the/etc directory,

After the installation is successful, you will generate some executable files in the bin directory under the specified directory, such as NTPD, ntpdate ..., this time does not mean that the NTP Server service has been implemented, we need to manually start NTP server

Execute the following command:

/usr/local/ntp/bin/ntpd-c/etc/ntp.conf

/USR/LOCAL/NTP/BIN/NTPD represents the absolute path of the NTPD, the-c parameter is the specified configuration file, and the parameter information for the specific information can be viewed using the-h parameter.

Finish execution Using Ps-e | grep "NTPD" can see the NTPD has been running in the background, note that the server started about 10 minutes before they can connect, otherwise the client synchronization will appear no server suitable for synchronization found. At this point, the client can synchronize time.

Refer to the server section of this article only, Link: http://www.51testing.com/html/28/116228-202637.html

In fact, we can also do without the NTP client, you can write a client program, and then compile, run directly also with the NTP server to synchronize time.

Download Address: http://download.csdn.net/download/zhangjianjun521/10233029



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.