Linux中的timedatectl时间设置及ntp时间同步服务搭建

一、timedatectl

1.设定系统时间

timedatectl  set-time  "2020-04-10 10:41:55"     ##设定系统时间

2.设定系统时区

  1. timedatectl list-timezones                        ##显示系统的所有时区
  2. timedatectl set-timezone "Asia/Shanghai"         ##设定系统时区
  3.                                                                           ##设定世界地点为上海
  4. [root@foundation69 ~]# timedatectl                      ##发现CST和utc时间不同
  5.       Local time: Fri 2020-04-10 10:48:41 CST           ##本地时间
  6.   Universal time: Fri 2020-04-10 02:48:41 UTC           ##国际标准时间
  7.         RTC time: Fri 2020-04-10 02:48:42               ##硬件时间
  8.        Time zone: Asia/Shanghai (CST, +0800)
  9. System clock synchronized: no
  10.               NTP service: inactive
  11.           RTC in local TZ: no
     

3.设定系统时间计算方式

  1. timedatectl set-local-rtc 0|1             ##设定系统时间计算方式
  2.                             ##0表示使用utc时间计算方式
  3. timedatectl set-local-rtc 0                     ##将硬件时间与国际标时间
  4. timedatectl set-local-rtc 1                     ##将硬件时间与本地时间同步

五、 时间同步服务   

  • #服务名称: chronyd.service
  • #配置文件: /etc/chrony.conf

在Horizon_carry作为时间源carry同步horizon时间

1.在Horizon_carry中

  1. vim /etc/chrony.conf
  2. 26 allow 172.25.254.0/24     ##允许172.25.254.0网段主机同步时间
  3. 29 local stratum 10          ##开启时间同步服务器功能并设定级别为10
  4. systemctl restart chronyd.service
  5. systemctl stop firewalld 

2.在carry中

  1. vim /etc/chrony.conf
  2. pool 172.25.254.10 iburst
  3. systemctl restart chronyd.service

3.使用chronyc 命令查看时间效果

在carry里查看时间:已经变成了Horizon_carry中的时间

[root@carry ~]# 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
||      Reachability register (octal) -.           |  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.10                 3   6   377     3  -5190us[  -26ms] +/-  135ms

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值