Linux系列之ntp时间同步

2019/3/28 星期四
Linux系列之ntp时间同步

[root@hadoop01-181 ins] yum -y install ntp
[root@hadoop01-181 ins]#vim /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 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 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0         (添加这两行)
fudge 127.127.1.0 stratum 8

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp1.aliyun.com iburst   (添加这三行)
server time.nist.gov iburst
server time.windows.com iburst

#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
"/etc/ntp.conf" 63L, 2140C written

[root@hadoop01-181 ins]# grep '^[a-Z]' /etc/ntp.conf  
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
server 127.127.1.0
fudge 127.127.1.0 stratum 8
server ntp1.aliyun.com iburst
server time.nist.gov iburst
server time.windows.com iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
[root@hadoop01-181 ins]#  systemctl start ntpd.service
[root@hadoop01-181 ins]# systemctl status ntpd.service 
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-03-27 18:31:35 CST; 16h ago
 Main PID: 6021 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─6021 /usr/sbin/ntpd -u ntp:ntp -g

Mar 27 18:31:41 hadoop01-181 ntpd_intres[6027]: DNS ntp1.aliyun.com -> 120.25.115.20
Mar 27 18:31:42 hadoop01-181 ntpd_intres[6027]: DNS time.nist.gov -> 132.163.97.1
Mar 27 18:31:42 hadoop01-181 ntpd_intres[6027]: DNS time.windows.com -> 52.163.118.68
Mar 27 18:47:27 hadoop01-181 ntpd[6021]: 0.0.0.0 0612 02 freq_set kernel -497.545 PPM
Mar 27 18:47:27 hadoop01-181 ntpd[6021]: 0.0.0.0 061c 0c clock_step -0.473662 s
Mar 27 18:47:28 hadoop01-181 ntpd[6021]: 0.0.0.0 c618 08 no_sys_peer
Mar 27 19:03:26 hadoop01-181 ntpd[6021]: 0.0.0.0 c612 02 freq_set kernel -15.769 PPM
Mar 27 19:03:26 hadoop01-181 ntpd[6021]: 0.0.0.0 c61c 0c clock_step +0.462023 s
Mar 27 19:03:26 hadoop01-181 ntpd[6021]: 0.0.0.0 c615 05 clock_sync
Mar 27 19:03:27 hadoop01-181 ntpd[6021]: 0.0.0.0 c618 08 no_sys_peer

[root@hadoop01-181 ins]# date +%F\ %T
2018-01-18 02:31:06
[root@hadoop01-181 ins]# ps -ef|grep ntp
ntp      18695     1  0 02:31 ?        00:00:00 /usr/sbin/ntpd -u ntp:ntp -g
root     18699  8441  0 02:31 pts/0    00:00:00 grep --color=auto ntp
[root@hadoop01-181 ins]# ntpq -p   (时间同步命令)
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           8 l    7   64    1    0.000    0.000   0.000
 time5.aliyun.co 202.118.1.46     2 u    -   64    1    0.215  -467986   0.103
 time-c-wwv.nist 202.118.1.46     2 u    1   64    1    0.233  -467986   0.045
 52.163.118.68   202.118.1.46     2 u    -   64    1    0.212  -467986   0.090
[root@hadoop01-181 ins]# ntpstat  (出现这个就表示ntp成功了)
synchronised to NTP server (132.163.97.3) at stratum 3 
   time correct to within 96 ms
   polling server every 1024 s
[root@hadoop01-181 ins]# systemctl list-unit-files|grep "ntp"
ntpd.service                                disabled
ntpdate.service                             disabled
[root@hadoop01-181 ins]# systemctl enable ntpd.service
ln -s '/usr/lib/systemd/system/ntpd.service' '/etc/systemd/system/multi-user.target.wants/ntpd.service'
[root@hadoop01-181 ins]# systemctl list-unit-files|grep "ntp"
ntpd.service                                enabled 
ntpdate.service                             disabled

剩余的服务器都要同步时间到 [root@hadoop01-181 ins]# 这要服务器上

其他两台要同步到hadoop01-181这台机器上
配置文件写成

[root@hadoop02-182 ins]# grep '^[a-Z]' /etc/ntp.conf 
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
server 127.127.1.0
fudge 127.127.1.0 stratum 8
server 192.168.83.181 iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

[root@hadoop02-182 ins]# systemctl start ntpd.service 
[root@hadoop02-182 ins]# systemctl enable ntpd.service
[root@hadoop02-182 ins]# ntpdate 192.168.83.181  (两台都要执行这个)
18 Jan 09:39:58 ntpdate[20110]: the NTP socket is in use, exiting
[root@hadoop02-182 ins]#ntpq -p                       
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           8 l   54   64    1    0.000    0.000   0.000
 hadoop01-181      LOCAL(0)         9 u   43   64    1    0.114  60529.3   0.102
[root@hadoop02-182 ins]# ntpstat                       
synchronised to local net at stratum 9 
   time correct to within 7948 ms
   polling server every 64 s

转载于:https://blog.51cto.com/12445535/2370391

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值