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默认情况下,系 ...
随机推荐
- Scala笔记整理
使用类型参数化数组(Array) 创建java.math.BigInteger实例: var big = new java .math.BigInteget("12345678") ...
- java程序员烂大街为何还不便宜?
最近跟一朋友聊天,他是做c#开发的.他答应了老板带领一帮java工程师开发网站.披星戴月终于搞定,现在已经盈利.但是他公司的那帮搞c#的同事不淡定了. 在招聘java程序员的时候2年有开15k的.5年 ...
- MapReduce job.setNumReduceTasks(0)思考
一.概述 在 http://zy19982004.iteye.com/blog/2037549的最后曾经提到过,这里再详细探讨一下. 二.job.setNumReduceTasks(0)唯一影响的是m ...
- LEETCODE —— Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode * ...
- (转) How to Train a GAN? Tips and tricks to make GANs work
How to Train a GAN? Tips and tricks to make GANs work 转自:https://github.com/soumith/ganhacks While r ...
- clientX、pageX、scrollLeft、offsetLeft、clientWidth、screen.width的用法和区别
一.定义和用法 1.event.clientX:事件对象的水平偏移量: event.clientY:事件对象的垂直偏移量: 2.event.pageX:事件对象加上滚动距离后的水平偏移量: event ...
- 如何对web.config进行加密和解密
http://blog.csdn.net/jf_jifei/article/details/6527390 在WEB网站开发过程中,如果我们将数据库连接字符串封装到.DLL文件中,将会给数据库和程序的 ...
- python小知识点
问题:求列表中每个元素的元素次方之和>>> a=[1,2,3,4]>>> k=len(a)第一种解法# s=0# for x in a:# ...
- BRISK: Binary Robust Invariant Scalable Keypoints
注意:本文含有一些数学公式,如果chrome不能看见公式的话请用IE打开网站 1.特征点提取 特征点提取有以下几个步骤: a.尺度空间金字塔结构的构造 和SIFT类似,尺度空间金字塔是由不同的尺度 ...
- vector与list区别
vector为存储的对象分配一块连续的地址空间,因此对vector中的元素随机访问效率很高.在vecotor中插入或者删除某个元素,需要将现有元素进行复制,移动.如果vector中存储的对象很大,或者 ...