ntp时间同步服务的搭建

一、timedatectl命令

1.timedatectl

[root@node1 ~]# timedatectl list-timezones                 ##查看所有时区

[root@foundation69 ~]# timedatectl set-timezone Asia/Shanghai  ##设定世界地点为上海
[root@foundation69 ~]# timedatectl                      ##发现CST和utc时间不同
      Local time: Wed 2018-10-17 21:56:32 CST           ##本地时间
  Universal time: Wed 2018-10-17 13:56:32 UTC           ##国际标准时间
        RTC time: Wed 2018-10-17 21:56:32               ##硬件时间
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: yes
      DST active: n/a

设定为UTC时间(通用时间)
[root@node1 ~]# timedatectl set-local-rtc 0    ##将硬件时间与国际标时间
[root@node1 ~]# vim /etc/adjtime
[root@node1 ~]# timedatectl set-local-rtc 1    ##将硬件时间与本地时间同步
[root@node1 ~]# vim /etc/adjtime

 


[root@node1 ~]# timedatectl set-time "2017-9-9 11:11:11"  ##设定时间
[root@node1 ~]# date
Sat Sep  9 11:11:13 CST 2017
[root@node1 ~]# timedatectl set-time "2018-10-14 09:45"  ##查看时间
[root@node1 ~]# date
Sun Oct 14 09:45:01 CST 2018

二、服务端和客户端的时间同步

在服务端:

[root@foundation69 ~]# vim /etc/chrony.conf
22 allow 172.25.254.0/24       ##允许网络位相同的所有客户端来访问本机共享的时间
29 local stratum 10            ##共享时间共享功能,并设定共享级别为10,即以自己的时间戳为基准
[root@foundation69 ~]# systemctl restart chronyd     ##重新启动服务
[root@foundation69 ~]# systemctl stop firewalld      ##关闭火墙

在客户端:

[root@node1 Desktop]# vim /etc/chrony.conf 
[root@node1 Desktop]# systemctl restart chronyd.service 

[root@node1 Desktop]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||                                                /   xxxx = adjusted offset,
||         Log2(Polling interval) -.             |    yyyy = measured offset,
||                                  \            |    zzzz = estimated error.
||                                   |           |                         
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 172.25.254.69                10   6    17    34   +138ns[-1000ns] +/-  961us

注意:只有底下出现*号时间,同步时间成功。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值