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

Build NTP time server under linux

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

Share

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

I. time and time zone configuration

Greenwich mean time (GMT), which is the time zone 0. But what is often seen in the computer is UTC. It is the abbreviation of Coordinated Universal Time. UTC has been recognized as an international standard, so we should all abide by the standard and only use UTC.

CST is Chinese Standard Time, which is what we usually call Beijing time

Related commands:

Date displays or modifies time and date

Hwclock modified BIOS time

The ntpd daemon configuration file is in / etc/ntp.conf

Ntpdate Link Sync time command

Ntpq NTP query command

Ntptime reads and sets kernel time variables

Ntpstat displays the status of network time synchronization

Related profile:

/ etc/ntp.conf NTP service profile

/ usr/share/zoneinfo time setting file for each time zone

/ etc/sysconfig/clock main time zone setting specified file "ZONE=Asia/Shanghai"

/ etc/localtime local system time setting file

[root@pjy ~] View time Wed Jun 7 12:36:19 CST 2017 [root@pjy ~] # zdump Shanghai # View the time of the corresponding time zone Shanghai Wed Jun 7 04:51:10 2017 Shanghai [root@pjy ~] # ln-sf / usr/share/zoneinfo/posix/Asia/Shanghai / etc/localtime # setting time zone method 1 [root@pjy ~] # tzselect # setting time zone method 2, you need to select a country and a city Finally, write the variable to the environment variable [root@pjy ~] # echo "TZ=Asia/Shanghai" > > / etc/profile [root@pjy ~] #. / etc/profile [root@pjy ~] # echo $TZ Asia/Shanghai [root@pjy zoneinfo] # cat / etc/sysconfig/clock # View the time zone profile ZONE= "Asia/Shanghai" [root@pjy zoneinfo] # date-R # View the system time zone Wed 07 Jun 2017 13:44:49 + 0800 [root@pjy zoneinfo] # hwclock-- show # View hardware time Wed Jun 7 13:48:21 2017-0.235036 seconds [root@pjy zoneinfo] # ntpdate cn.pool.ntp.org | hwclock-w # synchronize system time and hardware time

2. Configure NTP server

[root@pjy zoneinfo] # rpm-qa | grep ntp # check whether to install the NTP package, such as ntpdate-4.2.6p5-1.el6.centos.x86_64ntp-4.2.6p5-1.el6.centos.x86_64fontpackages-filesystem-1.41-1.1.el6.noarch [root@pjy zoneinfo] # yum-y install ntp # install NTP service without using YUM

Http://www.pool.ntp.org is the official website of NTP, on which we can find the nearest NTP Server to our city. NTP suggested that in order to ensure the accuracy of time, we should find at least two NTP Server.

Configure the NTP profile:

[root@pjy ~] # vim / etc/ntp.confdriftfile / var/lib/ntp/drift # stores the time difference to adjust broadcastdelay 0.008 restrict default nomodify # to define default access rules Modification of restrict 127.0.0.1 # definition allows all local operations restrict-6:: 1 # IPv6 definition server 202.120.2.101 prefer # priority upward synchronization server server cn.pool.ntp.orgserver 127.127.1.0 # local time server fudge 127.127.1.0 stratum 8 # use local time to give when the server loses its link to the public network server Client synchronization time includefile / etc/ntp/crypto/pw keys / etc/ntp/keys

Stratum sets the level of the server, 0 is the top level, and should not be set to 0 if you want to synchronize the time outward.

About the permission setting section

Permissions are mainly set by the parameter restrict, and the main syntax is:

Restrict IP address mask subnet mask parameter

Where IP can be IP address or default, and default refers to all IP.

The parameters are as follows:

Ignore: turn off all NTP online services

Nomodify: the client cannot change the time parameter of the server, but the client can calibrate the time on the network through the server.

Notrust: unless the client is authenticated, the client source will be considered an untrusted subnet

Noquery: no client time query is provided

Note: if the parameter is not set, it means that the IP (or subnet) does not have any restrictions!

The default is to reject all actions:

Restrict default kod nomodify notrap nopeer noquery

For example, only the host synchronization time on the 10.0.0.0 network segment is allowed and the time on the server is not allowed to be modified:

Restrict 10.0.0.0 mask 255.255.255.0 nomodify

Start the service:

/ etc/init.d/ntpd startchkconfig-- level 35 ntpd on

View the running status of the ntp service:

# watch ntpq-pEvery 2.0s: ntpq-p Tue Jun 6 22:54:30 2017 remote refid st t when poll reach delay offset jitter==== dns.sjtu.edu.cn .INIT .16u-64 0 0.000 0.000 0.000 biisoni.miuku.n 204.123.2.72 2 u 49 64 1 172.026 9.264 0.000*LOCAL (0) .LOCL .8 l 50 64 3 0.000 0.000 0.000

Remote: it refers to the remote NTP server to which the local machine is connected

Refid: it refers to a server that provides time synchronization to a remote server (e.g. 193.60.199.75)

St: the tier level (stratum) of the remote server. Because NTP is a layered structure, there is a top server, multi-tier Relay Server and then to the client. So the server from high to low level can be set to 1-16. In order to reduce load and network congestion, in principle, you should avoid connecting directly to level 1 servers.

When: I personally understand it as a timer to tell us how long before the local machine needs to synchronize with the remote server.

Poll: how often the local machine and the remote server synchronize (in seconds). This Poll value will be small at the beginning of running NTP, so the frequency of synchronization with the server will increase and can be adjusted to the correct time range as soon as possible. After that, the poll value will gradually increase, and the frequency of synchronization will decrease accordingly.

Reach: this is an octal value that is used to test whether you can connect to the server. Every time you connect successfully, its value increases.

Delay: round trip time that sends synchronization requests to the server from the local machine

Offset: this is the most critical value, which tells us the time difference between the local machine and the server. The closer the offset is to 0, the closer we are to the server.

Jitter: this is a value used for statistics. It calculates the distribution of offset in a specific number of consecutive connections. To put it simply, the smaller the absolute value of this number, the more accurate our time with the server will be.

Note: in the remote segment, NTP provides cluster services, so the server linked each time is different.

The front tag explains:

* it tells us that the remote server has been identified as our main NTP Server and that the time of our system will be provided by this machine

It will serve as a secondary NTP Server and a server with a * sign to provide synchronization services for us. When the * server is not available, it can take over.

-the remote server is considered as a substandard NTP Server by clustering algorithm

X remote server is not available

View the ntp update interval:

[root@pjy ~] # ntpstatsynchronised to NTP server (193.228.143.24) at stratum 3 # the server at this level is 3, and the time correct to within 655 ms # time has been corrected to the server within the difference of 655MS. Polling server every 64 s # polls the superior NTP for update time every 64 seconds

If you need to synchronize hardware time, you can also open it in the configuration file:

Vim / etc/sysconfig/ntpdSYNC_HWCLOCK=yes

III. Client time synchronization

Use timing to synchronize tasks:

[root@zabbix ~] # cat / var/spool/cron/root*/10 * / usr/sbin/ntpdate 10.0.0.100 | hwclock-w > / dev/null 2 > & 11

Hwclock-w is to use system time as hardware time

Note: when linux is asked to run the ntpdate update time, linux cannot open the NTP service, otherwise it will prompt the port to be occupied

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