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默认情况下,系 ...
随机推荐
- https/相对路径,绝对路径
1. htttps HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全 ...
- Hello Spring
初认识Spring 什么是spring:1.Spring是一个轻量级的DI/IoC和AOP容器的开源框架,来源于Rod Johnson 在其著作<Expert one on one J2EE d ...
- MYSQL常见语句
SHOW INDEXES from tablename EXPLAIN tablename EXPLAIN SELECT * FROM tablename
- Mysql(一)
一.Mysql简介 Mysql是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle旗下.特点:其体积小.速度快.开源. 分为社区办和商业版,其社区版性能卓越. 二.Ubun ...
- Window.Open详解
文章来源:http://www.cnblogs.com/stswordman/archive/2006/06/02/415853.html 一.window.open()支持环境:JavaScript ...
- OWIN是什么?
OWIN的英文全称是Open Web Interface for .NET. 如果仅从名称上解析,可以得出这样的信息:OWIN是针对.NET平台的开放Web接口. 那Web接口是谁和谁之间的接口呢?是 ...
- win7 64位 VS2010调试提示“ORA-12154: TNS: 无法解析指定的连接标识符”的解决方法
如果使用工具可以连接Oralce说明与Oralce安装无法. 解决方法: 解决步骤: 1.去网上下载"instantclient-basic-win32-11.2.0.1.0.zip&quo ...
- VR定制 AR定制 就找北京动软VR开发团队(VR案例 AR案例)
我们长期承接丰交互软件.游戏项目外包: VR/AR内容应用定制.VR.AR游戏项目外包(有主流测试硬件设备) VR全景应用.视频外包 请提供贵公司的信息,我们将提供高大上的VR案例欢迎联系我们给您提供 ...
- C#读取文件夹大小
今天需要做一个读取文件夹大小的功能,为了避免遍历文件夹下所有文件并求出总大小,找到如下的好方法: 首先要在项目中引用一个COM组件:Microsoft Scripting Runtime,这个在Ref ...
- DDGSpring2016 Demos
I followed the course http://brickisland.net/DDGSpring2016/, and here is the screenshot of my coding ...