linux 时间同步
[转自
qing_gee的专栏 :http://blog.csdn.net/qing_gee/article/details/42234997
]
前言:在我们的项目中,需要同步Linux服务器的时间,于是用到了ntpdate命令,就在crontab中进行了配置,设置为每个小时的整时分钟进行同步,完了后就一直没有关注,因为这很简单,经验主义告诉我,既然手动使用ntpdate命令就可以同步时间成功,放在cron进程(是Linux的一个守护进程,如果启动后,会每隔一分钟去检查对应的crontab文件,root用户的在/var/spool/cron)中就更没有问题了,然而,今天看Linux服务器的时间后,发现和Windows时间差上了好几分钟,我们的Linux服务承载着期货交易平台的定时服务,比如说,9点半开盘等等,这就意味着时间不准确啊,于是就调查解决问题,有了下面的记录
1.使用crontab -l命令查看定时服务
[root@MyCloudServer xxx]# crontab -l
0,10,20,30,40,50 * * * * ntpdate time.windows.com &>/xxx/ntpdate.log
2.看起来好像没有问题啊,vim /var/spool/mail/root(定时服务日志会存放在该文件中)查看定时服务日志,发现有如下信息
/bin/sh: ntpdate: command not found
说明定时服务在/bin/sh目录中去找ntpdate命令,并且没有找到
3.使用whereis ntpdate命令看看该命令在什么目录下
[root@MyCloudServer cron]# whereis ntpdate
ntpdate: /usr/sbin/ntpdate /usr/share/man/man8/ntpdate.8.gz
问题找到了,在定时服务中,ntpdate命令要使用全路径
4.使用crontab -e命令修改一下,加上ntpdate命令的目录
0,10,20,30,40,50 * * * * /usr/sbin/ntpdate time.windows.com &>/xxx/ntpdate.log
然而保存后,等到整数分钟后,在日志中没有发现该命令执行,为什么呢,猜想如下
a.以上命令格式错误,时间格式错误
b.cron自动服务没有执行
通过网上查找时间的命令格式,发现
0,10,20,30,40,50 * * * *
并没有错误,而手动执行
/usr/sbin/ntpdate time.windows.com &>/xxx/ntpdate.log
也成功执行,那么就看看b是否存在问题
5.执行ps -ef | grep cron,查看时间服务进程是否存在
[root@MyCloudServer xxx]# ps -ef | grep cron
root 26157 22992 0 10:04 pts/3 00:00:00 grep cron
发现没有cron执行进程
6.执行service crond status查看服务状态
[root@MyCloudServer xxx]# service crond status
crond is stopped
竟然服务没有启动,好吧
7.启动进程,并且查看状态
[root@MyCloudServer xxx]# service crond start
Starting crond: [ OK ]
[root@MyCloudServer xxx]# service crond status
crond (pid 26291) is running...
[root@MyCloudServer xxx]# ps -ef | grep cron
root 26291 1 0 10:06 ? 00:00:00 crond
root 26302 22992 0 10:06 pts/3 00:00:00 grep cron
8.服务启动了,通过vim /etc/rc.d/rc.local命令添加以下语句设置为开机启动
/sbin/service crond start
注意也加上了/sbin目录
9.最后再看看ntpdate.log中有没有执行日志
[root@MyCloudServer xxx]# cat ntpdate.log
29 Dec 11:10:16 ntpdate[29960]: no server suitable for synchronization found
发现服务器没有找到对应的服务同步,那么猜想应该是time.windows.com服务器在本台服务器上没有获取成功,由于我们用的是香港的云服务器,那么换一个香港认可的地址试试
0,10,20,30,40,50 * * * * /usr/sbin/ntpdate stdtime.gov.hk &>/xxx/ntpdate.log
然后等到整时分钟的时候再次查看一下
[root@MyCloudServer xxx]# cat ntpdate.log
29 Dec 11:20:01 ntpdate[30580]: adjust time server 118.143.17.82 offset 0.015206 sec
可以看到执行成功了
总结:通过以上问题调查,发现无论什么时候经验主义并不可靠,小小的一个问题都可能引发很多原因。
linux 时间同步的更多相关文章
- Linux时间同步方式记录
Linux时间同步 部署Hadoop集群,遇到各个linux服务器的时间不同步的问题,于是研究了一下linux的时间同步方式,特将同步方式,总结如下: A. 前提条件 a) 网络是连通 ...
- linux时间同步,ntpd、ntpdate
linux时间同步,ntpd.ntpdate 在Windwos中,系统时间的设置很简单,界面操作,通俗易懂.而且设置后,重启,关机都没关系.系统时间会自动保存在Bios的时钟里面,启动计算机的时候,系 ...
- linux 时间同步的2种方法(转)
linux 时间同步的2种方法 张映 发表于 2012-10-23 分类目录: 服务器相关 标签:linux, ntp, 同步, 时间服务器 由于硬件的原因,机器或多或少的根标准时间对不上,一个月的误 ...
- Linux 时间同步 01 简介
Linux 时间同步 01 简介 目录 Linux 时间同步 01 简介 时间同步 公共NTP服务器地址及IP 系统时间相关文件 时间同步 大数据产生与处理系统是各种计算设备集群的,计算设备将统一.同 ...
- Linux 时间同步 03 ntpdate时间同步
Linux 时间同步 03 ntpdate时间同步 目录 Linux 时间同步 03 ntpdate时间同步 安装ntpdate 修改/etc/sysconfig/ntpdate 使用ntpdate手 ...
- Linux 时间同步 04 ntp时间同步
Linux 时间同步 04 ntp时间同步 目录 Linux 时间同步 04 ntp时间同步 安装ntp 配置与外部时间服务器进行时间同步的客户端主机 配置其他客户端与以上客户端主机时间同步 验证查看 ...
- Linux 时间同步 02 ntpd、ntpdate的区别
Linux 时间同步 02 ntpd.ntpdate的区别 目录 Linux 时间同步 02 ntpd.ntpdate的区别 [一]这样做不安全. [二]这样做不精确. [三]这样做不够优雅. ntp ...
- Linux 时间同步 05 chrony时间同步
Linux 时间同步 05 chrony时间同步 目录 Linux 时间同步 05 chrony时间同步 chrony 的优势: chrony包介绍 安装chrony 配置与外部时间服务器进行时间同步 ...
- linux 时间同步的2种方法
转载自: http://blog.51yip.com/server/1474.html 由于硬件的原因,机器或多或少的根标准时间对不上,一个月的误差几秒到几分钟不等.对于服务器来说时间不准,会有很多麻 ...
- Linux时间同步,ntpdate命令、ntpd服务详解
声明:以下内容来自网友整理(http://blog.sina.com.cn/s/blog_636a55070101u1mg.html),为便于以后学习暂时收录,请不要随意转载 Linux默认情况下,系 ...
随机推荐
- MIT JOS学习笔记01:环境配置、Boot Loader(2016.10.22)
未经许可谢绝以任何形式对本文内容进行转载! 一.环境配置 关于MIT课程中使用的JOS的配置教程网上已经有很多了,在这里就不做介绍,个人使用的是Ubuntu 16.04 + qemu.另注,本文章中贴 ...
- golang 文件操作
package main import ( "bytes" "fmt" "io" "os" ...
- 如何用java写出无副作用的代码
搞java的同学们可能对无副作用这个概念比较陌生,这是函数式编程中的一个概念,无副作用的意思就是: 一个函数(java里是方法)的多次调用中,只要输入参数的值相同,输出结果的值也必然相同,并且在这个函 ...
- 【耐克】【Air Max90 气垫跑鞋】
[max90 36-44] [加毛冬款 36-44] [黑白百搭款 36-44] [air max90 高帮 冬款 耐看百搭 36-44] [air max90 高帮 40-44] [Air Max9 ...
- oracle数据库备份和还原
ip导出方式:exp demo/demo@127.0.0.1:1521/orcl file=f:\f.dmp full=y 备份:exp demo/demo@orcl file=f:\f.dmp f ...
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:5.安装Oracle RAC FAQ-RAC安装DB软件runInstaller看不到节点
集群安装正常: [root@kmdbrac1 ~]# crs_stat -t -v Name Type R/RA F/FT Target State Host -------------------- ...
- Building good docker images
The docker registry is bursting at the seams. At the time of this writing, a search for "node&q ...
- OS X Yosemite Beta体验
自从看到Yosemite泄露图的那天起,就暗暗下决心,一定要坚守Mavericks阵营,坚决不升级,觉得新版系统界面简直其丑无比,结果过了没多久,就按耐不住了,在Windows下的虚拟机里面看了看,发 ...
- MSSTDFMT.DLL无法注册的解决
今天在使用Windows8的时候,发现了一个问题,当我想执行某个xxx.exe文件的时候,报的问题是MSSTDFMT.DLL无法注册. 但是我的系统又是64位的,那么可以这样操作: 从网上下载一个ms ...
- R语言-基本数据管理
类型转换函数 判断 is.numeric() is.character() is.vector() is.matrix() is.data.frame() is.factor() is.logical ...