ntp和chronyd
admin
2023-03-10 18:22:15
0

ntp和chronyd

立即同步时间的坏处,影响某些计划任务执行

一、立即同步时间

方法一:

ntpdate ntp.aliyun.com

方法二:重启ntp服务

方法三:重启chrony服务

二、查看ntp和chrony状态

[root@textbox ~]# 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
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* localhost                     3   6    17     2    +62us[ +661us] +/-   88ms
[root@textbox ~]# 
[root@textbox ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*localhost       119.28.206.193   3 u   41   64  177    0.784    1.195 3656236

三、ntp做服务端的设置

#注释原来的ntp服务器,原来的ntp服务器都是centos.org美国的
[root@textbox ~]# sed   '/^server/s/^/#/' /etc/ntp.conf -i
#添加两个aliyun的
[root@textbox ~]# sed '1a server ntp.aliyun.com iburst'  /etc/ntp.conf -i
[root@textbox ~]# sed '1a server ntp1.aliyun.com iburst'  /etc/ntp.conf -i
#重启服务
[root@textbox ~]# systemctl restart ntpd
#ntp就这么简单,就可以当服务器使用了
[root@textbox ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+120.25.115.20   10.137.53.7      2 u    4   64   17   42.560   -8.795   6.944
*203.107.6.88    100.107.25.114   2 u    4   64   17   15.542   -7.021   6.460
#123端口,udp
[root@textbox ~]# ss -lutnp | grep ntp
udp    UNCONN     0      0      192.168.38.140:123                   *:*                   users:(("ntpd",pid=61668,fd=19))
udp    UNCONN     0      0      127.0.0.1:123                   *:*                   users:(("ntpd",pid=61668,fd=18))
udp    UNCONN     0      0         *:123                   *:*                   users:(("ntpd",pid=61668,fd=16))
udp    UNCONN     0      0      fe80::69d0:5288:fda9:93ae%ens33:123                  :::*                   users:(("ntpd",pid=61668,fd=21))
udp    UNCONN     0      0       ::1:123                  :::*                   users:(("ntpd",pid=61668,fd=20))
udp    UNCONN     0      0        :::123                  :::*                   users:(("ntpd",pid=61668,fd=17))
#用另一台服务器测试
[root@linux5 ~]# ntpdate 192.168.38.140
 5 Sep 09:17:25 ntpdate[28423]: adjust time server 192.168.38.140 offset -0.007790 sec

四、chrony服务端配置

设置项比ntp多

[root@imooc-nginx ~]# sed '/^server/s/^/#/' /etc/chrony.conf -i
[root@imooc-nginx ~]# sed '1a server ntp.aliyun.com iburst' /etc/chrony.conf -i
[root@imooc-nginx ~]# sed '1a server 0.cn.pool.ntp.org iburst' /etc/chrony.conf -i
[root@imooc-nginx ~]# sed '1a server ntp1.aliyun.com iburst' /etc/chrony.conf -i
#即使当前时服务器未与指定ntp完成时间同步,照样提供服务
[root@imooc-nginx ~]# sed '1a local stratum 10' /etc/chrony.conf -i
#允许哪些服务器同步
[root@imooc-nginx ~]# sed '1a allow 192.168.0.0/16' /etc/chrony.conf -i
[root@imooc-nginx ~]# systemctl restart chronyd
[root@imooc-nginx ~]# systemctl enable chronyd
#查看chronyd状态
[root@imooc-nginx ~]# chronyc sources -v
210 Number of sources = 3

  .-- 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
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^+ 120.25.115.20                 2   6    17     4   +766us[ +591us] +/-   21ms
^- 111.230.189.174               2   6    17     4    +98us[  +98us] +/-   49ms
^* 203.107.6.88                  2   6    17     4   -187us[ -361us] +/-   16ms
#测试
[root@textbox ~]# ntpdate 192.168.38.154
 5 Sep 09:33:25 ntpdate[61810]: adjust time server 192.168.38.154 offset -0.010546 sec

五、自动同步时间两种方式

1、ntpdate ntp.aliyun.com写入计划任务,每小时同步一次

2、所有服务器chrony都开启,其中一台做时间服务器,其他服务器的server都指向它

六、设置时区

[root@textbox ~]# timedatectl set-timezone Asia/Shanghai

相关内容

热门资讯

浙江人形与杰克科技签约2000... 来源:上海证券报·中国证券网 上证报中国证券网讯(记者 王子霖)据浙江人形机器人创新中心有限公司(以...
原创 三... 不出意外的话,今年苹果,高通、三星,联发科,这4家确定会推出2nm的手机芯片。 并且高通、联发科、苹...
Kimi、阶跃再获百亿融资,D... 图片由AI生成 出品 | 搜狐科技 作者 | 梁昌均 编辑 | 杨锦 中国大模型创业公司再次迎来融资...
“我妈有俩老公”?OPPO活该... 5月8日,OPPO官方微博发布了一条关于母亲节的宣发文案,内容因表述问题,引起热议。 相关话题“...
他,扛起又一个任正非时刻! 奔赴一场新的长征。 文 | 华商韬略 张静波 黄仁勋,急了。 2026年4月15日,在一场长达90分...
全球开源创新大会在巴黎举行 聚... 全球开源创新大会活动现场(5月6日摄)。新华社发(主办方供图) 新华社巴黎5月8日电 全球开源创新...
罕见!韩媒:韩国总统、国会议长... 据韩国《朝鲜日报》等韩媒报道,5月8日,韩国政坛出现罕见一幕:韩国总统李在明、韩国国会议长禹元植以及...
4000辆奇瑞商用车散件启运非... 河南日报讯(全媒体记者 龚砚庆 马青竹)5月8日上午,开封综合保税区内的汽车及零部件外贸基地一片繁忙...
“河南材料”中丨南阳新材料“追... 柔性功能薄膜隔热效率比传统产品高30%、紫外线与红外线阻隔率高达99%,产品在汽车玻璃、建筑玻璃和航...
河南超有品 第十个“中国品牌日... 从西安到灵宝寺河山,往返数百公里,仅半年,杨女士便跑了4趟。5月7日,她再次叩开果农司红娥家的大门,...