打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
CentOS7 的时间同步方法
centos7 时间同步和时区设置
首先centos7的时间同步是使用chrony这个工具(
[plain] view plain copy
[root@localhost ~]# systemctl status chrony
● chrony.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
1.安装chrony
[plain] view plain copy
[root@localhost ~]# yum -y install chrony
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
2.启动chrony
[plain] view plain copy
[root@localhost ~]# systemctl start chronyd
[root@localhost ~]# systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2016-10-24 17:52:52 CST; 3h 35min ago
Main PID: 807 (chronyd)
CGroup: /system.slice/chronyd.service
└─807 /usr/sbin/chronyd
Oct 24 17:52:44 localhost.localdomain systemd[1]: Starting NTP client/server...
Oct 24 17:52:44 localhost.localdomain chronyd[807]: chronyd version 2.1.1 sta...
Oct 24 17:52:45 localhost.localdomain chronyd[807]: Frequency -10.892 +/- 15....
Oct 24 17:52:52 localhost.localdomain systemd[1]: Started NTP client/server.
Oct 24 17:53:49 localhost.localdomain chronyd[807]: Forward time jump detected!
Oct 24 17:53:55 localhost.localdomain chronyd[807]: Selected source 202.118.1.81
Oct 24 17:53:55 localhost.localdomain chronyd[807]: System clock wrong by -45...
Oct 24 17:53:09 localhost.localdomain chronyd[807]: System clock was stepped ...
Oct 24 21:27:55 localhost.localdomain systemd[1]: Started NTP client/server.
Hint: Some lines were ellipsized, use -l to show in full.
3。用本机电脑同步另一台主机。做为服务器端需要配置 /etc/chrony.conf
等等。。先看一下本机的时间(localhost)
[plain] view plain copy
[root@localhost ~]# timedatectl
Local time: Mon 2016-10-24 21:30:33 CST
Universal time: Mon 2016-10-24 13:30:33 UTC
RTC time: Mon 2016-10-24 13:30:32
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
在设置一下另一台主机的时间(recehost)(错误的时间)
[plain] view plain copy
[root@recvhost ~]# timedatectl set-time "2018-11-11 11:11:11"
[root@recvhost ~]# timedatectl
Local time: Sun 2018-11-11 11:11:17 CST
Universal time: Sun 2018-11-11 03:11:17 UTC
RTC time: Sun 2018-11-11 11:11:18
Timezone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
好了,开始配置文件了(注意:现在是服务器端的修改)
[plain] view plain copy
22 allow 192.168.1.0/24
23
24 # Listen for commands only on localhost.
25 bindcmdaddress 127.0.0.1
26 bindcmdaddress ::1
27
28 # Serve time even if not synchronized to any NTP server.
29 local stratum 10
第22行设置为本网段
第29行的注释取消
重启时间同步服务,再关闭防火墙
[plain] view plain copy
[root@localhost ~]# vim /etc/chrony.conf
[root@localhost ~]# systemctl restart chronyd.service
[root@localhost ~]# systemctl stop firewalld.service
这下配置客户端的配置文件是同一个文件(/etc/chrony.conf)
删掉哪些没用的server   xxxxxxxxxx   iburst
[plain] view plain copy
1 # Use public servers from the pool.ntp.org project.
2 # Please consider joining the pool (http://www.pool.ntp.org/j    oin.html).
3 server  192.168.1.192      iburst
4 # Ignore stratum in source selection.
同样需要重启同步服务,关闭防火墙
[plain] view plain copy
[root@recvhost ~]# systemctl restart chronyd.service
[root@recvhost ~]# systemctl stop firewalld.service
使用下面的命令就可以查看同步情况
[plain] view plain copy
[root@recvhost ~]# 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
===============================================================================
^* 192.168.1.192                 3   6    37    29  -1430ns[+7000ns] +/-   15ms
下来再看时间
[plain] view plain copy
[root@recvhost ~]# timedatectl
Local time: Mon 2016-10-24 21:47:23 CST
Universal time: Mon 2016-10-24 13:47:23 UTC
RTC time: Mon 2016-10-24 21:47:24
Timezone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: yes
DST active: n/a
timedatectl      status   显示当前时间信息
set-time  设定当前时间
set-timezone 设定当前时区
set-local-rtc  设定bios时间
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
网络时间服务和chrony
Chronyd同步时间(Server/Client)配置
Centos8设置时间与阿里云NTP服务器同步_centos查看ntp同步
Windows下使用VNC连接CentOS7远程桌面
虚拟机安装CentOS及初始化
CentOS8.2部署NTP服务器与客户端配置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服