time synchronization in linux

Time synchronization:

Share time on the server side:

vim /etc/chrony.conf

29 local stratum 10

Turn on time sharing and set the sharing level

After this parameter is turned on, the machine does not synchronize other people's time to this machine

22 allow 172.25.254.0/24  which clients are allowed to share the local time

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


On the client side:

vim /etc/chrony.conf

server 172.25.254.100 iburst

systemctl restart chronyd


chronyc sources -v View time synchronization progress

[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

*Indicates that the time synchronization is complete, if so? Check the firewall and see if chronyd has restarted.


[root@node2 ~]# date

Sat Apr 14 03:05:17 EDT 2018

You can also use watch -n 1 date to monitor the time, and you can see the effect more intuitively.

timedatectl command:

[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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325654011&siteId=291194637