linux中的时间同步

时间同步:

在服务器端共享时间:

vim /etc/chrony.conf

29 local stratum 10

开启时间共享功能并设定共享级别

这个参数开启后本机不去同步别人的时间到本机

22 allow 172.25.254.0/24  允许哪些客户来共享本机的时间

systemctl restart chronyd


[root@node1 ~]# vim /etc/chrony.conf

[root@node1 ~]# systemctl restart chronyd

[root@node1 ~]# date

Sat Apr 14 03:04:48 EDT 2018

[root@node1 ~]# date

Sat Apr 14 03:05:24 EDT 2018


在客户端:

vim /etc/chrony.conf

server 172.25.254.100 iburst

systemctl restart chronyd


chronyc sources -v   查看时间同步进度

[root@node2 ~]# vim /etc/chrony.conf

[root@node2 ~]# systemctl restart chronyd

[root@node2 ~]# date

Sat Apr 14 03:04:40 EDT 2018

[root@node2 ~]# 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.121               10   6    17    27    -12ms[  -12ms] +/-   17ms

*说明时间同步完成,如果为?检查防火墙再看看chronyd有没有重启。


[root@node2 ~]# date

Sat Apr 14 03:05:17 EDT 2018

还可以使用watch -n 1 date来监控时间,可以更加直观的看到效果。

timedatectl命令:

[kiosk@foundation21 Desktop]$ rht-vmctl start desktop

Starting desktop.

[kiosk@foundation21 Desktop]$ rht-vmctl view desktop

[kiosk@foundation21 Desktop]$ ssh [email protected]

[email protected]'s password:

Last login: Fri Apr 13 22:32:39 2018 from 172.25.254.221

[root@node1 ~]# timedatectl

      Local time: Sat 2018-04-14 04:01:58 EDT

  Universal time: Sat 2018-04-14 08:01:58 UTC

[root@node1 ~]# timedatectl list-timezones       显示时区列表

Africa/Abidjan

Africa/Accra

Africa/Addis_Ababa

Africa/Algiers

Africa/Asmara

Africa/Bamako


[root@node1 ~]# timedatectl set-timezone Asia/Shanghai        更改时区为上海

[root@node1 ~]# timedatectl

      Local time: Sat 2018-04-14 16:03:28 CST

  Universal time: Sat 2018-04-14 08:03:28 UTC

        RTC time: Sat 2018-04-14 08:03:28

        Timezone: Asia/Shanghai (CST, +0800)

     NTP enabled: yes

NTP synchronized: no

 RTC in local TZ: no

      DST active: n/a

[root@node1 ~]# date

Sat Apr 14 16:03:32 CST 2018


[root@node1 ~]# timedatectl set-local-rtc 0              0代表使用UTC

[root@node1 ~]# vim /etc/adjtime                         显示


[root@node1 ~]# timedatectl set-local-rtc 1              1代表使用本地时间

[root@node1 ~]# vim /etc/adjtime


[root@node1 ~]# timedatectl set-time "2018-11-11 11:11:11"   更改时间

[root@node1 ~]# date                             显示时间

Sun Nov 11 11:11:14 CST 2018

猜你喜欢

转载自blog.csdn.net/aaaaaab_/article/details/80145258
今日推荐