建设银行官网首页网站南山片区,手机网站建设电话,asp网站源代码,国外网站设计师服务器时钟同步 文章目录 服务器时钟同步背景windows时钟同步Linux机器上的时钟同步Centos时钟同步Ubuntu系统时钟同步 查看是否同步的命令 背景
运维#xff0c;XXX服务器慢了2秒#xff0c;导致XXX业务没有正常执行#xff0c;请立即排查为啥会有时钟不同步的问题。 首先…服务器时钟同步 文章目录 服务器时钟同步背景windows时钟同步Linux机器上的时钟同步Centos时钟同步Ubuntu系统时钟同步 查看是否同步的命令 背景
运维XXX服务器慢了2秒导致XXX业务没有正常执行请立即排查为啥会有时钟不同步的问题。 首先说下时间为啥会不准时间不准的原因有很多有以下几种可能
硬件时钟故障BIOS的电池故障时钟同步问题
还有很多问题总而言之就是时间不准确了怎么能将时间尽可能的标准呢来看看我们遇到的问题。
windows时钟同步
首先将自动设置时间要打开 设定要同步的的服务器可以选择官方的也可以选择自己的同步服务器但记得要先telnet一下端口是123 默认同步时间是1天1次本次同步结束后24小时后再同步一次 如果机器对时间的要求比较严格要进行定时同步时间设置定时同步可以这么设置 找到任务计划程序(我不知道哪里进点了win搜索就是了) 创建个目录或者在 \Microsoft\Windows\Time Synchronization 目录下设置时间同步 设置任务的目的主要是执行命令 设置触发器选定你要同步的时间跟Linux里的crontab有点相似这个是界面的更容易理解 主要是操作这些 同步时间的命令
w32tm /resync检查windows中时差的命令是
# 203.107.6.88是阿里云的时钟服务器
cmd /k w32tm /stripchart /computer:203.107.6.88 /samples:2 /dataonly也可以采用微软的服务器自己公司内部的服务器
如果需要看到时间差的情况可以使用钉钉、飞书、邮件等相关软件进行及时通知或者超过某个阈值的时候进行通知这些都是可行的。一般只要时间同步问题就不大。
Linux机器上的时钟同步
Centos时钟同步
采用Centos默认的时钟同步策略在装系统时已经装了查看其命令的
# 查看chronyd的状态
[rootlocalhost log]# systemctl status chronyd
● chronyd.service - NTP client/serverLoaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active: active (running) since Fri 2023-07-21 18:35:48 CST; 2 weeks 0 days agoDocs: man:chronyd(8)man:chrony.conf(5)Process: 1593 ExecStartPost/usr/libexec/chrony-helper update-daemon (codeexited, status0/SUCCESS)Process: 1569 ExecStart/usr/sbin/chronyd $OPTIONS (codeexited, status0/SUCCESS)Main PID: 1585 (chronyd)Tasks: 1CGroup: /system.slice/chronyd.service└─1585 /usr/sbin/chronydJul 21 18:35:48 localhost systemd[1]: Starting NTP client/server...
Jul 21 18:35:48 localhost chronyd[1585]: chronyd version 3.4 starting (CMDMON NTP REFCLOCK RTC PRIVDROP SCFILTER SIGND ASYNCDNS SECH...6 DEBUG)
Jul 21 18:35:48 localhost chronyd[1585]: Frequency 4.080 /- 0.147 ppm read from /var/lib/chrony/drift
Jul 21 18:35:48 localhost systemd[1]: Started NTP client/server.
Jul 21 18:35:58 localhost chronyd[1585]: Selected source 193.182.111.12
Jul 21 18:35:59 localhost chronyd[1585]: Selected source 202.38.64.7
Jul 21 18:36:02 localhost chronyd[1585]: Source 193.182.111.12 replaced with 84.16.73.33
Jul 26 17:50:53 localhost chronyd[1585]: Source 202.112.29.82 replaced with 119.28.206.193
Hint: Some lines were ellipsized, use -l to show in full.
[rootlocalhost log]# 配置文件在
[rootlocalhost etc]# vim /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 所需同步服务器的域名
server 0.centos.pool.ntp.org iburst
……# Record the rate at which the system clock gains/losses time.
# driftfile指定了用于记录系统时钟的漂移量的文件路径。Chrony使用该文件来记录系统时钟的精度和准确度以便在下次启动时进行校准。
driftfile /var/lib/chrony/drift# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
# makestep配置指定了系统时钟在前三次更新时是否允许快速调整stepping当系统时钟的偏差超过1秒时允许进行快速调整。
makestep 1.0 3# Enable kernel synchronization of the real-time clock (RTC).
# rtcsync启用了对硬件RTC实时时钟的内核同步。Chrony将尝试让系统时钟和硬件RTC保持同步。其中要注意同步的服务器要保证和是能通信的
Ubuntu系统时钟同步
(base) testlocalhost:~$ systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time SynchronizationLoaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2023-07-24 18:28:19 CST; 1 week 4 days agoDocs: man:systemd-timesyncd.service(8)Main PID: 838 (systemd-timesyn)Status: Initial synchronization to time server 185.125.190.57:123 (ntp.ubuntu.com).Tasks: 2 (limit: 57665)Memory: 964.0KCPU: 3.313sCGroup: /system.slice/systemd-timesyncd.service└─838 /lib/systemd/systemd-timesyncdWarning: some journal files were not opened due to insufficient permissions.Ubuntu 默认同步的主机是pool.ntp.org 默认同步时间最大是2048秒最小同时间隔是32秒大约每间隔1分钟同步一次
查看是否同步的命令
无论Ubuntu还是Centos查看是否同步的命令都是 乌班图查看
(base) testlocalhost:/etc$ timedatectlLocal time: Fri 2023-08-04 19:30:36 CSTUniversal time: Fri 2023-08-04 11:30:36 UTCRTC time: Fri 2023-08-04 11:30:36Time zone: Asia/Shanghai (CST, 0800)
System clock synchronized: yesNTP service: activeRTC in local TZ: no
(base) testlocalhost:/etc$ Centos查看
[rootlocalhost ~]# timedatectlLocal time: Fri 2023-08-04 19:31:20 CSTUniversal time: Fri 2023-08-04 11:31:20 UTCRTC time: Fri 2023-08-04 11:31:20Time zone: Asia/Shanghai (CST, 0800)NTP enabled: yes
NTP synchronized: yesRTC in local TZ: noDST active: n/a
[rootlocalhost ~]#
计算机不是机械的没有大自然的神奇底层是电压的高低位模拟出来的未免有偏差偏差只要做好同步和监控时间偏差会降到最低防止因为时间偏差带来的麻烦。