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默认情况下,系 ...
随机推荐
- mysql order排序
使用order by 可以对结果进行排序, 默认情况下,order by 以升序进行排序,因此ASC 子句是可选的. DESC 是降序排列. 升序 select * from emp where d ...
- Linear Algebra lecture1 note
Professor: Gilbert Strang Text: Introduction to Linear Algebra http://web.mit.edu/18.06 Lecture 1 ...
- cookie的详细解释
突然看到网页上中英文切换的效果,不明白怎么弄得查了查 查到了cookie 并且附有详细解释 就copy留作 以后温习 http://blog.csdn.net/xidor/article/detail ...
- 作业三:WC项目
WC一个简单的文件检测系统 用c语言实现 不多说 上代码 #include<stdio.h> #include<stdlib.h> #include <io.h> ...
- Mac 使用 SSH 免密连接服务器
1.生成 SSH 秘钥 ssh-keygen -t rsa 生成的密钥对 id_rsa 和 id_rsa.pub,默认存储在 ~/.ssh 目录,其中没有后缀的是私有,有后缀 .pub 的为公钥.生 ...
- Http中 Post和 Get的区别
1.表面上的区别 1.GET在浏览器回退时,是无害的,而Post会再次提交请求 2.Get产生的Url地址会被Bookmark,而Post不会 3.Get请求会被浏览器主动Cache,而Post不会, ...
- OpenGL角轴
概述 轴旋转 角轴 概述 OpenGL旋转矩阵 旋转角度直接影响OpenGL GL_MODELVIEW矩阵的前三列,准确地说是向左.向上与向前三轴元素.例如,如果一沿X轴的单位向量(1,0,0)与任一 ...
- Arcgis Server 10.2默认服务端口号修改方法
本人安装Arcgis Server 10.2之后发布了一个地图服务,该服务默认使用的端口号是6080,本人使用的是教育网,使用教育网均能正常使用该服务,但是使用电信或者移动网络均不能正常访问该网站. ...
- LeetCode----Array
Remove Duplicates from Sorted Array 思路:两个指针,头指针在0,尾指针从1开始寻找,找到第一个不等于头指针值的数,覆盖掉头指针后面那个数,然后尾指针往后移. pub ...
- [zhuan] linux 下 wxWidgets 安装,编译
http://blog.csdn.net/yuzhenxiong0823/article/details/7727133 wxWidgets在Linux下有wxGTK和wxX11供使用,各需要GT ...