NTP配置实践
前言
NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。不管是平时使用的私人计算机还是在工作中搭建的服务器集群。时间的统一性和准确性是十分重要的。
本文以自己公司的NTP配置实践过程为例,过程本身并不复杂,原理部分请參考扩展阅读。
时间同步真的非常重要
更新历史
2015年06月26日 - 初稿
阅读原文 - http://wsgzao.github.io/post/ntp/
扩展阅读
准备工作
检查NTP是否安装
假设缺少NTP服务,请从官方下载适合自己系统的版本号
#检查rpm包
rpm -qa | grep ntp
ntp-4.2.4p8-1.16.1
yast2-ntp-client-2.17.14-1.10.14
手动改动时间
选择正确的时区,控制误差在5分钟以内
#查看当前时间
date
2008年 12月 12日 星期五 14:44:12 CST
Fri Jun 26 14:51:37 CST 2015
#手动改动时间(月/日/年时:分:秒)
date -s "1/1/09 00:01"
2009年 01月 01日 星期四 00:01:00 CST
#手动改动分秒
date -s 21:21
NTP配置
NTP服务端配置
服务端时间来源选择上海交通大学网络中心NTP服务器地址
#NTP服务端系统版本号
cat /etc/SuSE-release
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 2
#编辑ntp配置文件
vi /etc/ntp.conf
server 202.120.2.101 prefer
#server ntp.sjtu.edu.cn
#增加自己主动启动
chkconfig ntp on
#启动ntp服务
service ntp start
service ntp status
service ntp stop
完整的/etc/ntp.conf
配置文件例如以下
################################################################################
## /etc/ntp.conf
##
## Sample NTP configuration file.
## See package 'ntp-doc' for documentation, Mini-HOWTO and FAQ.
## Copyright (c) 1998 S.u.S.E. GmbH Fuerth, Germany.
##
## Author: Michael Andres, <ma@suse.de>
## Michael Skibbe, <mskibbe@suse.de>
##
################################################################################
##
## Radio and modem clocks by convention have addresses in the
## form 127.127.t.u, where t is the clock type and u is a unit
## number in the range 0-3.
##
## Most of these clocks require support in the form of a
## serial port or special bus peripheral. The particular
## device is normally specified by adding a soft link
## /dev/device-u to the particular hardware device involved,
## where u correspond to the unit number above.
##
## Generic DCF77 clock on serial port (Conrad DCF77)
## Address: 127.127.8.u
## Serial Port: /dev/refclock-u
##
## (create soft link /dev/refclock-0 to the particular ttyS?)
##
# server 127.127.8.0 mode 5 prefer
server 202.120.2.101 prefer
##
## Undisciplined Local Clock. This is a fake driver intended for backup
## and when no outside source of synchronized time is available.
##
server 127.127.1.0
# local clock (LCL)
fudge 127.127.1.0 stratum 10
# LCL is unsynchronized
##
## Add external Servers using
## # rcntp addserver <yourserver>
##
##
## Miscellaneous stuff
##
driftfile /var/lib/ntp/drift/ntp.drift
# path for drift file
logfile /var/log/ntp
# alternate log file
# logconfig =syncstatus + sysevents
# logconfig =all
# statsdir /tmp/ # directory for statistics files
# filegen peerstats file peerstats type day enable
# filegen loopstats file loopstats type day enable
# filegen clockstats file clockstats type day enable
#
# Authentication stuff
#
keys /etc/ntp.keys
# path for keys file
trustedkey 1
# define trusted keys
requestkey 1
# key (7) for accessing server variables
# controlkey 15 # key (6) for accessing server variables
NTPclient配置
如无特殊要求,一般使用crontab计划任务同步时间
1.crontab计划任务方式配置
crontab -e
0 0 * * * /usr/sbin/sntp -P no -r 172.16.0.3;hwclock -w
2.以服务进程方式实时同步
#编辑client配置文件
vi /etc/ntp.conf
server 198.16.2.135
#启动服务
chkconfig ntp on
service ntp restart
#假设相差时间较长,请先手动同步
sntp -P no -r 198.16.2.135
ntpdate –d 198.16.2.135
检查NTP同步状态
NTP协议为UDP端口是123,offset时间偏移量以毫秒为单位,注意防火墙的控制策略
#查看服务连接和监听
ntp:~ # netstat -tlunp | grep ntp
udp 0 0 198.17.1.224:123 0.0.0.0:* 28916/ntpd
udp 0 0 198.16.2.224:123 0.0.0.0:* 28916/ntpd
udp 0 0 127.0.0.2:123 0.0.0.0:* 28916/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 28916/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 28916/ntpd
udp 0 0 ::1:123 :::* 28916/ntpd
udp 0 0 fe80::250:56ff:feb9:123 :::* 28916/ntpd
udp 0 0 fe80::250:56ff:feb9:123 :::* 28916/ntpd
udp 0 0 :::123 :::* 28916/ntpd
#查看网络中的NTP服务器。同一时候显示client和每一个服务器的关系
ntp:~ # ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*202.120.2.101 202.118.1.81 3 u 5 1024 377 265.748 -2.819 16.138
LOCAL(0) .LOCL. 10 l 34 64 377 0.000 0.000 0.001
NTP配置实践的更多相关文章
- linux服务器应用NTP配置时间同步
linux服务器应用NTP配置时间同步 • 为什么建议使用ntpd而不是ntpdate? #####原因很简单,ntpd是步进式的逐渐调整时间,而ntpdate是断点更新,比如现在服务器时间是9.18 ...
- 【转】Flume(NG)架构设计要点及配置实践
Flume(NG)架构设计要点及配置实践 Flume NG是一个分布式.可靠.可用的系统,它能够将不同数据源的海量日志数据进行高效收集.聚合.移动,最后存储到一个中心化数据存储系统中.由原来的Fl ...
- [转载] iptables配置实践
原文: http://wsgzao.github.io/post/iptables/ iptables配置实践 By wsgzao 发表于 2015-07-24 文章目录 1. 前言 2. 更新历史 ...
- Zookeeper、Solr和Tomcat安装配置实践
Zookeeper.Solr和Tomcat安装配置实践
- MySql主从配置实践及其优势浅谈
MySql主从配置实践及其优势浅谈 1.增加两个MySQL,我将C:\xampp\mysql下的MYSQL复制了一份,放到D:\Mysql2\Mysql5.1 修改my.ini(linux下应该是my ...
- 原创:路由配置实践 两个局域网主机的互连 VM linux
又开始齐天大圣讲课的时间了 我相信网络是每个运维人员和开发人员必不可少要接触的 今天我们要讲的是在VM虚拟机中 我们三台虚拟机划分两个局域网 实现不同局域网的互联 也就是下面图中的AC通过B主机的 ...
- Celery配置实践笔记
说点什么: 整理下工作中配置celery的一些实践,写在这里,一方面是备忘,另外一方面是整理成文档给其他同事使用. 演示用的项目,同时也发布在Github上: https://github.com/b ...
- 基于openresty的https配置实践
最近机器人项目的子项目,由于和BAT中的一家进行合作,人家要求用HTTPS连接,于是乎,我们要改造我们的nginx的配置,加添HTTPS的支持. 当然了,HTTPS需要的证书,必须是认证机构颁发的,这 ...
- 华三交换机NTP配置
clock protocol ntp ntp-service enable ntp-service unicast-server x.x.x.x clock timezone beijing add ...
随机推荐
- Android自定义控件(四)——让每一个Activity UI都具有弹性
前面我们已经介绍了如何让你的ScrollView,ListView具有弹性, 今天,我们在前面的基础上,做一下适当的修改,让那些既不是ScrollView,也不是ListView的Activity页面 ...
- Error when launching Quest Central for DB2: "QCC10000E - Unable to allocate environment handle fo
标题 Error when launching Quest Central for DB2: "QCC10000E - Unable to allocate environment hand ...
- [CSAPP笔记][第十二章并发编程]
第十二章 并发编程 如果逻辑控制流在时间上是重叠,那么它们就是并发的(concurrent).这种常见的现象称为并发(concurrency). 硬件异常处理程序,进程和Unix信号处理程序都是大家熟 ...
- python - 执行父类中的方法
执行父类中的方法: class C1: def f1(self): print('c1.f1') return 123 class C2(C1): def f1(self): #主动执行父类的f1方法 ...
- JS高级程序设计学习笔记之基本包装类型
概述 基本类型:string.boolean.number 每当读取一个基本类型的值的时候,后台就会创建一个对应的基本包装类型的对象,从而让我们能够调用一些方法来操作这些数据. 使用new操作符创建的 ...
- ie8 hack
1.‘\9’: eg:.test { color/*\**/: blue\9 }.header {width:300px;} /* 所有浏览器*/.header {width/*\**/:330px\ ...
- asp.net中的主题
用了更方便,在.net网站上,右键,选择添加主题,然后命一个名子,如果,有四个主题, 只需要在web.config的page节里加上styleSheetTheme="Red",就会 ...
- 一句SQL实现MYSQL的递归查询
众所周知,目前的mysql版本中并不支持直接的递归查询,但是通过递归到迭代转化的思路,还是可以在一句SQL内实现树的递归查询的.这个得益于Mysql允许在SQL语句内使用@变量.以下是示例代码. 创建 ...
- FCKeditor插件开发实例:uploadify多文件上传插件
FCKeditor是一个专门使用在网页上属于开放源代码的所见即所得文字编辑器.它志于轻量化,不需要太复杂的安装步骤即可使用.它可和PHP.JavaScript.ASP.ASP.NET.ColdFusi ...
- Effective Java 电子书 apk版本下载
下载安装包以后,安装即可阅读该书了,并且实时展示每章节代码哦,并且可以运行哦,赶快下载体验吧. Effective Java中文第二版下载地址:下载 应用截图: