跳转至

ntp时间同步服务器

安装ntp

1.主服务器:
    (1) yum -y install ntp
2.客户端:
    (1) yum -y install ntp 

配置文件

1.主服务器配置
(1)vim /etc/ntp.conf
restrict 127.0.0.1
restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap

server 120.25.115.20
server 203.107.6.88
server 127.127.1.0n
fudge 127.127.1.0 stratum 10
2. 客户端
(1)vim /etc/ntp.conf
restrict 172.16.1.5 mask 255.255.255.0 nomodify notrap

定时任务

2.客户端:定时任务
(1)vim /etc/crontab
* * * * * root (/usr/sbin/ntpdate ntp1.aliyun.com && /sbin/hwclock -w || /usr/sbin/ntpdate ntp.sjtu.edu.cn) &> /var/log/ntpdate.log



apt install ntpdate -y
systemctl start ntpd
systemctl enable ntpd
 apt install ntp

 sntp --version

 ntpq -p
配置 NTP Pool
Pool 的配置文件位于 /etc/ntp.conf 文件中,这个 Pool 的用途主要是告诉 Ubuntu 的 NTP 客户端到哪里去找时间服务器。

通常已经会默认的配置好了。

pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst


 systemctl status ntp
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Leap seconds definition provided by tzdata
leapfile /usr/share/zoneinfo/leap-seconds.list

# Enable this if you 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). See http://www.pool.ntp.org/join.html for
# more information.
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
pool ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Needed for adding pool entries
restrict source notrap nomodify noquery

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


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

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

同步系统硬件时间

  1. date 查看系统时间 clock 查看硬件时间
  2. date -s ‘19990730’ //手动配置时间
  3. yum -y install ntpdate //下载ntpdate时间自动同步器
  4. ntpdate ntp1.aliyun.com //自动同步到系统时间
  5. hwclock -w //同步系统时间到硬件时间