linux 时间同步的2种方法
转载自: http://blog.51yip.com/server/1474.html
由于硬件的原因,机器或多或少的根标准时间对不上,一个月的误差几秒到几分钟不等。对于服务器来说时间不准,会有很多麻烦。例如,支付的时候,无法下单,游戏无法登录等。自己用的PC就无所谓了,手动改一下就行了。
一,用ntpdate从时间服务器更新时间
如果你的linux系统根本没有ntpdate这个命令
- yum install ntp
安装完了之后,你不要做什么配置,也不需要,直接测试一下
vi /etc/ntp.conf
add below:
server 1.cn.pool.ntp.org
server 3.asia.pool.ntp.org
server 2.asia.pool.ntp.org
restart service and sync the time
- [root@localhost ~]# ntpdate time.nist.gov
- 22 Oct 21:11:43 ntpdate[5014]: adjust time server 207.200.81.113 offset -0.018788 sec
如果出去上面的内容说明,同步成功了。然后在crontab里面加上以下内容。
- */10 * * * * ntpdate time.nist.gov #域名或IP
每隔十分钟同步一次。推荐几个时间服务器。
time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org
二,用ntp搭建自己的时间服务器
上面我们是利用别人的时间服务器来同步时间,这些时间服务器都是比较权威的。当我们自己搭建时间服务器就不用crontab来定时去跑。
1,安装时间服务器ntp
- yum install ntp
2,配置ntp
- [root@localhost ~]# cat /etc/ntp.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'
- restrict default ignore //默认不允许修改或者查询ntp,并且不接收特殊封包
- restrict 127.0.0.1 //给于本机所有权限
- restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //给于局域网机的机器有同步时间的权限
- server time.nist.gov prefer //设置时间服务器,加prefer表示优先
- server 0.asia.pool.ntp.org
- server 1.asia.pool.ntp.org
- server 2.asia.pool.ntp.org
- server 127.127.1.0 # local clock
- fudge 127.127.1.0 stratum 10
- driftfile /var/lib/ntp/drift
- keys /etc/ntp/keys
3,启动 ntp
- [root@localhost ~]# /etc/init.d/ntpd start
4,查看并测试
- [root@localhost ~]# netstat -upnl |grep ntpd //查看时程
- [root@localhost ~]# ntpq -pn //查看同步的服务器IP
- remote refid st t when poll reach delay offset jitter
- ==============================================================================
- 50.77.217.185 .INIT. 16 u - 64 0 0.000 0.000 0.000
- 202.90.158.4 .INIT. 16 u - 64 0 0.000 0.000 0.000
- 202.71.100.89 .INIT. 16 u - 64 0 0.000 0.000 0.000
- 202.134.1.10 .INIT. 16 u - 64 0 0.000 0.000 0.000
- *127.127.1.0 .LOCL. 10 l 18 64 377 0.000 0.000 0.001
- [root@localhost ~]# ntpstat //同步的结果
- synchronised to local net at stratum 11
- time correct to within 12 ms
- polling server every 512 s
remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。
refid:参考的上一层NTP主机的地址
st:即stratum阶层
when:几秒前曾做过时间同步更新的操作
poll:下次更新在几秒之后
reach:已经向上层NTP服务器要求更新的次数
delay:网络传输过程钟延迟的时间
offset:时间补偿的结果
jitter:Linux系统时间与BIOS硬件时间的差异时间
推荐第一种方法,虽然搭建个时间服务器,还是比较简单的,但是我觉得没有这个必要。如果用别人的时间服务器,每隔10分钟同步一次,可以精确到毫秒。
linux 时间同步的2种方法的更多相关文章
- linux 时间同步的2种方法(转)
linux 时间同步的2种方法 张映 发表于 2012-10-23 分类目录: 服务器相关 标签:linux, ntp, 同步, 时间服务器 由于硬件的原因,机器或多或少的根标准时间对不上,一个月的误 ...
- RAC时间同步的两种方法
集群时间同步服务在集群中的两个 Oracle RAC 节点上执行以下集群时间同步服务配置.Oracle Clusterware 11g 第 2 版及更高版本要求在部署了 Oracle RAC 的集群的 ...
- linux安装IPython四种方法
IPython是Python的交互式Shell,提供了代码自动补完,自动缩进,高亮显示,执行Shell命令等非常有用的特性.特别是它的代码补完功能,例如:在输入zlib.之后按下Tab键,IPytho ...
- python执行linux命令的两种方法
python执行linux命令有两种方法: 在此以Linux常用的ls命令为例: 方法一:使用os模块 1 2 3 shell# python >> import os >> ...
- 强制重启Linux系统的几种方法
实际生产环境中某些情况下 Linux 服务器系统在出现致命错误需要远程进行重启,通过常规的 reboot.init 6 等方法无法正常重启(例如重启时卡在驱动程序里等情况),这时就需要通过下面介绍的几 ...
- linux 安装软件三种方法
引言 在ubuntu当中,安装应用程序我所知道的有三种方法,分别是apt-get,dpkg安装deb和make install安装源码包三种.下面针对每一种方法各举例来说明. apt-get方法 使用 ...
- linux下时间同步的两种方法分享
方法1:与一个已知的时间服务器同步 复制代码 代码如下: ntpdate time.nist.gov 其中 time.nist.gov 是一个时间服务器. 删除本地时间并设置时区为上海 复制代码 代码 ...
- linux下时间同步的两种方法分享(转)
与一个已知的时间服务器同步 代码如下: ntpdate time.nist.gov 其中 time.nist.gov 是一个时间服务器. 删除本地时间并设置时区为上海 复制代码 代码如下: rm -r ...
- 远程重启linux主机的几种方法
方法一,在终端上利用ssh,不登录远程主机,直接发送重启命令 ssh root@192.168.8.128 'reboot' 方法二,在终端上利用ssh和here document ssh root@ ...
随机推荐
- CALayer的m34 - 三维透视效果
CATransform3D transform = CATransform3DIdentity; // 修改transform的m34达到透视效果 // - 1.0 / (500 ~ 1000 效果最 ...
- Cell右滑 多个编辑选项栏
简单粗暴,一看就能明白 关于右滑cell,能滑出来两个以上的选项栏,可以如下这么做,但是要注意下面的注意事项,就是关于iOS8前后的问题,注释写的很清楚了.可以直接复制到自己的代码里看的会更明白. / ...
- (十四)Maven聚合与继承
1.Maven聚合 我们在平时的开发中,项目往往会被划分为好几个模块,比如common公共模块.system系统模块.log日志模块.reports统计模块.monitor监控模块等等.这时我们肯定会 ...
- audio 基本功能实现(audio停止播放,audio如何静音,audio音量控制等)
audio最简单原始的播放.暂停.停止.静音.音量大小控制的功能,注意某些浏览器会有权限无法自动播放噢(video也会如此) <!doctype html> <html> &l ...
- servlet应用及知识点总结
1. servlet的web.xml中的配置 ------------------------------------------------------------------1. response ...
- Hadoop技巧(03):HostName命名带来的问题
阅读目录 序 HostName 问题 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink ...
- Nginx 访问日志轮询切割
Nginx 访问日志轮询切割脚本 #!/bin/sh Dateformat=`date +%Y%m%d` Basedir="/application/nginx" Nginxlog ...
- QTimer的用法
1.singleShot的用法 代码: QTextEdit *testEdit = new QTextEdit("hello world"); testEdit->setMa ...
- java遍历给定目录,树形结构输出所有文件,包括子目录中的文件
(转自:http://blog.csdn.net/gangwazi0525/article/details/7569701) import java.io.File; public class Rea ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...