前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >服务器时间自动同步

服务器时间自动同步

原创
作者头像
谭广健
发布2022-07-21 11:56:00
4.6K0
发布2022-07-21 11:56:00
举报
文章被收录于专栏:谭广健的专栏谭广健的专栏

很多时候由于服务器的日期时间不准确,导致程序容易出问题;本来这个上去同步一下就可以,但有时候没发现或留意就会引申出很多问题。本来说在程序中加入一个时间校准功能,不是不可以,只是麻烦。后来经过其他朋友提醒;在windows和linux都有一个时间同步的功能,于是独享不是群享,就发出来留个脚印吧。。

先说linux:

Liunx下有2种方法:rdate和ntpdate。

其中rdate本身是用来获取远程时间服务器上时间用的,带上 -s 参数,就可以将获取到的时间应用到本地系统。

代码语言:javascript
复制
NAME  rdate - get the time via the network
SYNOPSIS  rdate [-p] [-s] [-u] [-l] [-t sec] [host...]
DESCRIPTION
       rdate  connects  to  an  RFC  868 time server over a TCP/IP network, printing the returned time
       and/or setting the system clock.
   OPTIONS
       -p     Print the time returned by the remote machine.

       -s     Set the system time to the returned time.

       -u     Use UDP instead of TCP as the transport.

       -l     Use syslog to output errors (cron.warning) and output (cron.info).

       -t     Set timeout in seconds for every attempt to retreive date.

执行命令:rdate -s time.nist.gov

而ntpdate 本身就是用来同步时间的工具。

代码语言:javascript
复制
NAME    ntpdate - set the date and time via NTP
       Disclaimer:  The functionality of this program is now available in the ntpd program. See the -q com-
       mand line option in the ntpd - Network Time Protocol (NTP) daemon page. After a suitable  period  of
       mourning, the ntpdate program is to be retired from this distribution

SYNOPSIS
       ntpdate [ -46bBdqsuv ] [ -a key ] [ -e authdelay ] [ -k keyfile ] [ -o version ] [ -p samples ] [ -t
       timeout ] [ -U user_name ] server [ ... ]

执行命令:ntpdate ntp.sjtu.edu.cn

腾讯云NTP授时服务器地址

代码语言:javascript
复制
time1.cloud.tencent.com 
time2.cloud.tencent.com 
time3.cloud.tencent.com
time4.cloud.tencent.com
time5.cloud.tencent.com

最后就是记得将命令放到crontab里定时执行。。。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 腾讯云NTP授时服务器地址
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档