linux实现时间服务器视频,linux实现时间同步有哪几种方法
发布日期:2021-06-24 12:27:23 浏览次数:2 分类:技术文章

本文共 2210 字,大约阅读时间需要 7 分钟。

原标题:linux实现时间同步有哪几种方法

方法一:用ntpdate从时间服务器更新时间

如果linux系统没有ntpdate这个命令,可以输入以下代码进行安装

yum install ntp

安装完了之后,你不要做什么配置,也不需要,直接测试一下

vi /etc/ntp.conf

add below:

server 1.cn.pool.ntp.org

server 3.asia.pool.ntp.org

server 2.asia.pool.ntp.org

restart service and sync the time

[root@localhost ~]# ntpdate time.nist.gov

22 Oct 21:11:43 ntpdate[5014]: adjust time server 207.200.81.113 offset -0.018788 sec

如果显示上面的内容说明同步成功了,然后在crontab里面加上以下内容。

*/10 * * * * ntpdate time.nist.gov #域名或IP

每隔十分钟同步一次。推荐几个时间服务器。

time.nist.gov

time.nuri.net

0.asia.pool.ntp.org

1.asia.pool.ntp.org

2.asia.pool.ntp.org

3.asia.pool.ntp.org

方法二、用ntp搭建自己的时间服务器

上面是利用别人的时间服务器来同步时间,这些时间服务器都是比较权威的。当我们自己搭建时间服务器就不用crontab来定时去跑。

1、安装时间服务器ntp

yum install ntp

2、配置ntp

[root@localhost ~]# cat /etc/ntp.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'

restrict default ignore //默认不允许修改或者查询ntp,并且不接收特殊封包

restrict 127.0.0.1 //给于本机所有权限

restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //给于局域网机的机器有同步时间的权限

server time.nist.gov prefer //设置时间服务器,加prefer表示优先

server 0.asia.pool.ntp.org

server 1.asia.pool.ntp.org

server 2.asia.pool.ntp.org

server 127.127.1.0 # local clock

fudge 127.127.1.0 stratum 10

driftfile /var/lib/ntp/drift

keys /etc/ntp/keys

3、启动 ntp

[root@localhost ~]# /etc/init.d/ntpd start

4、查看并测试

[root@localhost ~]# netstat -upnl |grep ntpd //查看时程

[root@localhost ~]# ntpq -pn //查看同步的服务器IP

remote refid st t when poll reach delay offset jitter

==============================================================================

50.77.217.185 .INIT. 16 u - 64 0 0.000 0.000 0.000

202.90.158.4 .INIT. 16 u - 64 0 0.000 0.000 0.000

202.71.100.89 .INIT. 16 u - 64 0 0.000 0.000 0.000

202.134.1.10 .INIT. 16 u - 64 0 0.000 0.000 0.000

*127.127.1.0 .LOCL. 10 l 18 64 377 0.000 0.000 0.001

[root@localhost ~]# ntpstat //同步的结果

synchronised to local net at stratum 11

time correct to within 12 ms

polling server every 512 s

remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。

refid:参考的上一层NTP主机的地址

st:即stratum阶层

when:几秒前曾做过时间同步更新的操作

poll:下次更新在几秒之后

reach:已经向上层NTP服务器要求更新的次数

delay:网络传输过程钟延迟的时间

offset:时间补偿的结果

jitter:Linux系统时间与BIOS硬件时间的差异时间

推荐第一种方法,虽然搭建个时间服务器,比较简单的,但是我觉得没有这个必要。如果用别人的时间服务器,每隔10分钟同步一次,可以精确到毫秒。返回搜狐,查看更多

责任编辑:

转载地址:https://blog.csdn.net/weixin_32697149/article/details/116637060 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:linux hadoop etc目录,题目Linux平台下Hadoop的安装配置
下一篇:linux内核用什么调试,什么是开发/调试Linux内核最有效和最优雅的方式

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月22日 05时16分09秒