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

9.linux ntp server building

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

Share

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

First, introduce several common concepts related to time.

GMT:Greenwich Mean Time Greenwich time

In theory, noon GMT refers to the time when the sun crosses the Greenwich meridian (that is, at the highest point above Greenwich). Due to the uneven speed of the earth in its elliptical orbit, this moment may differ from the actual solar time by 16 minutes.

UTC:Coordinated Universal Time coordinated Universal time

World standard time

CST: (Chinese Standard Time)

CST can also represent the following four different time zones:

Central Standard Time (USA) UT-6:00

Central Standard Time (Australia) UT+9:30

China Standard Time UT+8:00

Cuba Standard Time UT-4:00

Two kinds of time on the operating system

Software clock: also known as system time, based on the total number of seconds calculated since 1970-01-01

View system time: [root@node1 ~] View current time Wed Jun 28 19:57:53 CST 2017 [root@node1 ~] # date + "% Y-%m-%d" # set current time format 2017-06-28 [root@node1 ~] # date + "% Y-%m-%d% H:%M:%S" # set current time Format 2017-06-28 19:58:42 [root@node1 ~] # date +% s # total seconds from 1970-01-01 to now 1498651211 set time: date-s "20120523 01:01:01" # set the current system time It is generally not recommended to execute directly on the production host. Date-s "dd/mm/yyyy hh:mm:ss"

Hardware clock: the clock on the host hardware system. The time in the BIOS on the motherboard is maintained by the motherboard battery, which should be read when the system is powered on and set the system time according to it.

When to check the hardware: hwclock or clock setting: hwclock-- set-- date= "06max 18max 14 14:55"

Conversion between hardware time and system time:

Clock-hctosys # adjusts the system time to the current hardware time; when Linux starts, the system clock reads the setting of the hardware clock, and then the system clock operates independently. Clock-systohc # adjusts the hardware clock to the current system clock; saves the system time back to the hardware clock

III. Installation and setup of NTP server

1. The required software

Ntp main software

Tzdata provides the display format for each time zone.

two。 Related documents

/ etc/ntp.conf main configuration file

/ usr/share/zoneinfo/ is provided by tzdata and corresponds to the time format of each time zone.

/ etc/sysconfig/clock sets the configuration file for whether the time zone uses the UTC clock.

[root@node1 zoneinfo] # cat / etc/sysconfig/clock ZONE= "Asia/Shanghai" # indicates that our time configuration file will use the file / usr/share/zoneinfo/Asia/Shanghai

Time profile for the local side of / etc/localtime

A simple example: at present in Shanghai, if you go to the United States, how to adjust the time? First vim / etc/sysconfig/clock ZONE= "America/New_York" and then cp / usr/share/zoneinfo/America/New_York / etc/localtime last date

3. Master configuration file

[root@node1] # cat / etc/ntp.conf # For more information about this file, see the man pages# ntp.conf (5), ntp_acc (5), ntp_auth (5), ntp_clock (5), ntp_misc (5), ntp_mon (5). Driftfile / var/lib/ntp/drift # 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 noqueryrestrict-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: 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 (http://www.pool.ntp.org/join.html).#server 0.rhel.pool.ntp.org iburst#server 1.rhel.pool.ntp.org iburst#server 2. Rhel.pool.ntp.org iburst#server 3.rhel.pool.ntp.org iburstserver 1.cn.pool.ntp.org#broadcast 192.168.1.255 autokey # broadcast server#broadcastclient # broadcastclient # broadcast 224.0.1.1 autokey # multicast server#multicastclient 224.0.1.1 # multicastclient # manycastserver 239.255.254.254 # manycastserver # manycastclient 239 .255.254.254 autokey # manycast client# Enable public key cryptography.#cryptoincludefile / etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. Keys / etc/ntp/keys# Specify the key identifiers which are trusted.#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.#requestkey 8# Specify the key identifier to use with the ntpq utility.#controlkey 8# Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats

Parameter explanation:

(1) driftfile recording time difference

(2) restrict management authority control

Restrict [ip] mask [netmask_ip] [parameter] parameter mainly include: ignore: reject all types of NTP connections nomodify: the client cannot use ntpc/ntpq to modify the server's time parameters, but the client can perform network time calibration noquery: the client cannot use ntpq/ntpc to query the time server Equal to network time calibration notrap that does not provide NTP: do not provide trap this remote event login notrust: reject clients without authentication. If it is not set in [parameter], it means that the network segment is not subject to any restrictions.

(3) server: set the NTP server on the upper layer

Server [ip or hostname] [prefer]

4. Start the server NTP service

# / etc/init.d/ntpd start # Startup Service # chkconfig ntpd on # Boot # tail / var/log/messages # View Log View Port: [root@node1 ~] # netstat-tulnp | grep ntpudp 0 0192.168.209.128tail 123 0.0.0.0 * 2766/ntpd udp 0 0 127.0.0.1 2766/ntpd udp 123 0.0.0.0 fe80::20c * 2766/ntpd udp 0 0 fe80::20c : 29ff:fe67:be62:123: * 2766/ntpd udp 0 0:: 1 2766/ntpd udp 00: 123:: * 2766/ntpd usually connects to the upper NTP server only after starting NTP15 for a few minutes. # ntpstat to see if the ntp server is connected to the upper layer. The upper NTP + in action represents a successful connection. The name of the higher-level server that can be used as the next candidate to provide update time for the refid:NTP server is st: stratum hierarchy when: time synchronization updates were done a few seconds ago. Seconds since the last successful request poll: the next update is in a few seconds. How long does it take for local and remote servers to synchronize? in seconds, at the beginning of running NTP, the poll value is relatively small, and the frequency of server synchronization is large, which 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 correspondingly reduce reach: the number of updates has been requested from the upper NTP server. Used to test the ability to connect to the server, is an octal value, each successful connection will increase the value of delay: the delay during network transmission. Send the round trip time offset from the synchronization request to the ntp server from the local machine: the result of time compensation. The time offset between the host and the synchronized time source is synchronized by the NTP clock in milliseconds. The closer the offset is to 0, the closer the time of the host and the ntp server is to the difference between the jitter:Linux system time and the hardware time. The smaller the absolute value of this value, the more accurate the time of the host.

Time for the client to synchronize the NTP server

Method 1: ntpdate 192.168.209.128 edits the scheduled task crontab, automatically synchronizes every 30 minutes, and writes to the hardware clock. * / 30 * (/ usr/sbin/ntpdate 192.168.209.128 & & hwclock-w) & > / dev/null method 2: modify the / etc/ntp.conf configuration file and enable the ntpd service to automatically synchronize the upper ntp server. Add server 1.cn.pool.ntp.org / etc/init.d/ntpd start chkconfig ntpd on

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