CentOS7的时间同步方法
centos7 时间同步和时区设置
首先centos7的时间同步是使用chrony这个工具(
[plain] view plain copy
1.[root@localhost ~]# systemctl status chrony
2.● chrony.service
3.Loaded: not-found (Reason: No such file or directory)
4.Active: inactive (dead)
1.安装chrony
[plain] view plain copy
1.[root@localhost ~]# yum -y install chrony
2.Loaded plugins: fastestmirror, langpacks
3.Loading mirror speeds from cached hostfile
2.启动chrony
[plain] view plain copy
1.[root@localhost ~]# systemctl start chronyd
2.[root@localhost ~]# systemctl status chronyd
3.● chronyd.service - NTP client/server
4.Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
5.Active: active (running) since Mon 2016-10-24 17:52:52 CST; 3h 35min ago
6.Main PID: 807 (chronyd)
7.CGroup: /system.slice/chronyd.service
8.└─807 /usr/sbin/chronyd
9.
10.Oct 24 17:52:44 localhost.localdomain systemd[1]: Starting NTP
11.Oct 24 17:52:44 localhost.localdomain chronyd[807]: chronyd version 2.1.1&
12.Oct 24 17:52:45 localhost.localdomain chronyd[807]: Frequency -10.892 +/-&
13.Oct 24 17:52:52 localhost.localdomain systemd[1]: Started NTP client/server.
14.Oct 24 17:53:49 localhost.localdomain chronyd[807]: Forward time jump detected!
15.Oct 24 17:53:55 localhost.localdomain chronyd[807]: Selected source 202.118.1.81
16.Oct 24 17:53:55 localhost.localdomain chronyd[807]: System clock wrong by -45...
17.Oct 24 17:53:09 localhost.localdomain chronyd[807]: System clock was stepped ...
18.Oct 24 21:27:55 localhost.localdomain systemd[1]: Started NTP client/server.
19.Hint: Some lines were ellipsized, use -l to show in full.
3。用本机电脑同步另一台主机。做为服务器端需要配置 /f
等等。。先看一下本机的时间(localhost)
[plain] view plain copy
1.[root@localhost ~]# timedatectl
2.Local time: Mon 2016-10-24 21:30:33 CST
3.Universal time: Mon 2016-10-24 13:30:33 UTC
4.RTC time: Mon 2016-10-24 13:30:32
5.Time zone: Asia/Shanghai (CST, +0800)
6.NTP enabled: yes
7.NTP synchronized: yes
8.RTC in local TZ: no
9.DST active: n/a
在设置一下另一台主机的时间(recehost)(错误的时间)
[plain] view plaincentos vim命令 copy
1.[root@recvhost ~]# timedatectl set-time "2018-11-11 11:11:11"
2.[root@recvhost ~]# timedatectl
3.Local time: Sun 2018-11-11 11:11:17 CST
4.Universal time: Sun 2018-11-11 03:11:17 UTC
5.RTC time: Sun 2018-11-11 11:11:18
6.Timezone: Asia/Shanghai (CST, +0800)
7.NTP enabled: yes
8.NTP synchronized: no
9.RTC in local TZ: yes
10.DST active: n/a
好了,开始配置文件了(注意:现在是服务器端的修改)
[plain] view plain copy
1.22 allow 192.168.1.0/24
2.23
3.24 # Listen for commands only on localhost.
4.25 bindcmdaddress 127.0.0.1
5.26 bindcmdaddress ::1
6.27
7.28 # Serve time even if not synchronized to any NTP server.
8.29 local stratum 10
第22行设置为本网段
第29行的注释取消
重启时间同步服务,再关闭防火墙
[plain] view plain copy
1.[root@localhost ~]# vim /f
2.[root@localhost ~]# systemctl restart chronyd.service
3.[root@localhost ~]# systemctl stop firewalld.service
这下配置客户端的配置文件是同一个文件(/f)
删掉哪些没用的server xxxxxxxxxx iburst
[plain] view plain copy
1.1 # Use public servers from the&p.org project.
2.2 # Please consider joining the pool (/j oin.html).
3.3 server 192.168.1.192 iburst
4.4 # Ignore stratum in source selection.
同样需要重启同步服务,关闭防火墙
[plain] view plain copy
1.[root@recvhost ~]# systemctl restart chronyd.service
2.[root@recvhost ~]# systemctl stop firewalld.service
使用下面的命令就可以查看同步情况
[plain] view plain copy
1.[root@recvhost ~]# chronyc sources -v
2.210 Number of sources = 1
3.
4..-- Source mode '^' = server, '=' = peer, '#' = local clock.
5./ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
6.| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
7.|| .- xxxx [ yyyy ] +/- zzzz
8.|| / xxxx = adjusted offset,
9.|| Log2(Polling interval) -. | yyyy = measured offset,
10.|| \ | zzzz = estimated error.
11.|| | |
12.MS Name/IP address Stratum Poll Reach LastRx Last sample
13.===============================================================================
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论