ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

linux 局域网时钟同步

2022-06-25 11:32:54  阅读:190  来源: 互联网

标签:1.152 ntp ntpdate 局域网 linux 0.00000 172.20 时钟


Linux时钟同步

一 需求

​ 以172.20.1.152作为时钟服务器,其他服务器根据这台服务器进行时钟同步。

二 时钟服务器172.20.1.152实施

2.1 安装ntp

#检查是否已经安装,出现了红框中的就说明已经安装了
rpm -qa | grep ntp
#安装ntp
yum install ntp

2.2 配置时钟服务器

vi /etc/ntp.conf
#代表允许172.20网段的服务器与此服务器进行时间同步,根据需要进行替换id和子网掩码即可
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
restrict 172.20.1.0 mask 255.255.255.192 nomodify notrap
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

2.3 开启服务

service ntpd start

2.4 设置ntp开机自启动

chkconfig ntpd on

2.5 开发访问端口权限

#之后还需要对ntp的默认端口123进行放行,这个一定要配,除非你关了防火墙,否则会报错,no server suitable for #synchronization found
iptables -I INPUT -p tcp --dport 123 -j ACCEPT
iptables -I INPUT -p udp --dport 123 -j ACCEPT

2.6 本服务器时间可以根据互联网时钟或者数据库手动调整

三 时钟客户端172.20.1.158实施

3.1 安装ntp

#检查是否已经安装,出现了红框中的就说明已经安装了
rpm -qa | grep ntp
#安装ntp
yum install ntp

3.2 配置

vi /etc/ntp.conf

记得把地址替换为你自己的那台时间服务器的地址

server 172.20.1.152
fudge 172.20.1.152 stratum 10

3.3 启动

service ntpd start

3.4 开机启动

chkconfig ntpd on

3.5 手动同步下测试

ntpdate -d 172.20.1.152
#显示以下内容代表成功
[root@host-172-20-1-158 tomcat9-llqt-7003]# ntpdate -d 172.20.1.152
25 Jun 09:58:57 ntpdate[13538]: ntpdate 4.2.6p5@1.2349-o Fri Apr 13 12:52:28 UTC 2018 (1)
Looking for host 172.20.1.152 and service ntp
host found : 172.20.1.152
transmit(172.20.1.152)
receive(172.20.1.152)
transmit(172.20.1.152)
receive(172.20.1.152)
transmit(172.20.1.152)
receive(172.20.1.152)
transmit(172.20.1.152)
receive(172.20.1.152)
server 172.20.1.152, port 123
stratum 11, precision -24, leap 00, trust 000
refid [172.20.1.152], delay 0.02586, dispersion 0.00000
transmitted 4, in filter 4
reference time:    e660efe3.56e033ce  Sat, Jun 25 2022 10:22:27.339
originate timestamp: e660f01a.2e8a535d  Sat, Jun 25 2022 10:23:22.181
transmit timestamp:  e660ea67.47801f45  Sat, Jun 25 2022  9:59:03.279
filter delay:  0.02621  0.02591  0.02586  0.02589 
         0.00000  0.00000  0.00000  0.00000 
filter offset: 1458.902 1458.902 1458.902 1458.902
         0.000000 0.000000 0.000000 0.000000
delay 0.02586, dispersion 0.00000
offset 1458.902283

25 Jun 09:59:03 ntpdate[13538]: step time server 172.20.1.152 offset 1458.902283 sec

3.6 查看同步状态

ntpq -p 
#when代表最近同步时间

3.7 创建定时任务,自动同步

#查看已有定时任务
crontab -l
#添加定时任务
crontab -e
#每天凌晨一点20,自动从172.20.1.152同步一次
20 1 * * * ntpdate 172.20.1.152

标签:1.152,ntp,ntpdate,局域网,linux,0.00000,172.20,时钟
来源: https://www.cnblogs.com/qiaoyizhi/p/16411008.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有