第一步:

1. 安装NTP服务程序:

[root@host ~]# rpm -qa | grep ntp #查询是否安装ntp服务程序
[root@host ~]# yum install -y ntp #安装ntp服务程序 

2. 配置NTP服务程序:

以下红色是新增的配置,黑色是默认配置

[root@host ~]# cp /etc/ntp.conf{,.bak} #备份ntp配置文件
[root@host ~]# vim /etc/ntp.conf #使用vim编辑ntp配置文件 见vim使用方法
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap #允许该网段内的主机可以进行校时
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap
restrict default #default指所有的IP
server 210.72.145.39 prefer #上层NTP服务器地址,prefer表示优先
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

3. 设置NTP服务器控制操作:

# chkconfig ntpd on  #设置为开机启动
# /etc/init.d/ntpd start #启动NTP服务器
# /etc/init.d/ntpd stop #关闭NTP服务器
# /etc/init.d/ntpd restart #重启NTP服务器

 查看NTP端口

[root@host ~]# netstat -tlunp | grep ntp
udp 0 0 192.168.5.180:123 0.0.0.0:* 28331/ntpd #这里的ip地址是本地IP,如果开放公共NTP的话是NTP服务器的IP
udp 0 0 127.0.0.1:123 0.0.0.0:* 28331/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 28331/ntpd
udp 0 0 fe80::20c:29ff:fe2b:9990:123 :::* 28331/ntpd
udp 0 0 ::1:123 :::* 28331/ntpd
udp 0 0 :::123 :::* 28331/ntpd

  

4.

现在ntp服务器已经启动了,不过与上层服务器连接则还需要一些时间,通常启动NTP后在15分钟内才会和上层NTP服务器顺利连接上。

如何确定NTP服务器顺利地更新了自己的时间呢?可以使用以下几个命令查看

[root@host ~]# ntpstat
synchronised to NTP server (72.5.72.15) at stratum 3
time correct to within 80 ms
polling server every 128 s  
这个命令列出NTP服务器是否已经与上层NTP服务器连接,由上述的输出结果可以知道,时间已经校正约80ms,且每隔128秒会主动去更新============================================================================================================================================

ntpq -p命令可以列出当前我们的NTP服务器与上层NTP服务器的连接状态:

[root@host ~]# ntpd -p
remote refid st t when poll reach delay offset jitter
==============================================================================
210.72.145.39 .INIT. u - 0.000 0.000 0.000
*mirror1.sjc02.s 162.213.2.253 u 10.196 0.945 2.653
+clocka.ntpjs.or 142.66.101.13 u 32.037 0.300 3.040
+----s 172.16.23.153 u 77.364 3.457 3.268
-tesla.selinc.co 74.117.214.3 u 40.243 7.171 5.293

以上几个字段的意义如下:

remote: NTP主机的IP或主机名;

注意左边的符号: *:表示正在使用的NTP服务器

+:表示已经连接成功,但是作为备用提供时间更新的NTP服务器;

refid: 上层NTP服务器地址;

st: 就是stratum阶层;

when:几秒钟前做过时间同步更新操作;

pool:下次更新在几秒钟之后;

reach:已经向上层NTP服务器要求更新的次数;

delay: 网络传输过程中延迟的时间,单位为10-6秒;

offset:时间补偿结果,单位为10-3秒;

jitter:系统时间与BIOS硬件时间的差异时间,单位为10-6秒;

 

PS:

国家授时中心服务器网址: http://www.time.ac.cn/stime.asp

          IP: 210.72.145.39

配置NTP时可以同步硬件时钟指令如下:

同步硬件时钟 SYNC_HWCLOCK=yes

CentOS6 自己动手搭建开放NTP服务器的更多相关文章

  1. centos6.7搭建局域网ntp服务器

    修改/etc/ntp.conf文件 restrict xxx nomodify notrap nopeer noquery             #xxx 此处配置本地IP地址restrict 12 ...

  2. 时间服务器: NTP 服务器及客户端搭建

    时间服务器: NTP 服务器及客户端搭建 一. NTP 服务器的安装与设定 1. NTP 服务器的安装与设定前言 2. 所需软件与软件结构 3. 主要配置文件 ntp.conf 的处理 4. NTP ...

  3. CentOS7配置时间和CentOS6搭建局域网NTP

    NTP 2015年8月20日 星期四 17:34 CentOS 7配置本地时区和TIME ZONE #用tzselect配置时区和time zone [root@localhost Asia]# /u ...

  4. NTP服务器的配置

    安装cloudera Manager的时候,必须要求集群的主机之间时间同步,搭建一个NTP服务器的思路是,首先通过一台主机master与外网进行时间同步,然后其他的slaver主机与主机master进 ...

  5. centos6 & centos7搭建ntp服务器

    原理 NTP(Network TimeProtocol,网络时间协议)是用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1 ...

  6. 搭建ntp服务器

    1.同步网络时间 先关闭掉ntp服务,使用ntpd同步网络时间. /etc/init.d/ntpd stop ntpdate 2.hk.pool.ntp.org 网络时间可以从http://www.p ...

  7. Centos6一键搭建L2TP VPN服务器

    用VPS在墙上打洞还有一种叫L2TP,也是常见的一种方式.本脚本结合了L2TP(Layer Tunneling Protocol)和IPSec(Internet Protocol Security), ...

  8. NTP服务器搭建

    NTP服务器搭建 :http://www.jbxue.com/LINUXjishu/22352.html 客户端配置: vim /etc/ntp.conf #server 0.centos.pool. ...

  9. Centos7安装搭建NTP服务器和NTP客户端同步时间

    NTP简介: NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在计算机的世界里,时间非常地重要 例如:对于火箭发射这种科研活动,对时间的 ...

随机推荐

  1. vs 2015 community Blend和devenv启动的区别

    使用Blend启动会有部分功能无法显示 如:SVN管理插件,工具栏 使用devenv启动会全部显示

  2. Entity Framework 实体间的外键关系

    EF 默认是开户级联删除的,这此规则将会删除非空外键和多对多的关系,如果 在数据库上下文中的实体模型类 存在着 级联引用和多重删除路径,那么EF就抛出 级联引用和多重删除路径的异常. Introduc ...

  3. (水题)洛谷 - P1603 - 斯诺登的密码

    https://www.luogu.org/problemnew/show/P1603 有毒,大小写不检测,句号也不管. #include<bits/stdc++.h> using nam ...

  4. Cg profiles,如何使用CGC编译Cg语言(转)

    抄“GPU Programming And Cg Language Primer 1rd Edition” 中文名“GPU编程与CG语言之阳春白雪下里巴人” 计算机只能理解和执行由0.1序列(电压序列 ...

  5. python __builtins__ complex类 (13)

    13.'complex', 函数用于创建一个值为 real + imag * j 的复数或者转化一个字符串或数为复数.如果第一个参数为字符串,则不需要指定第二个参数. class complex(ob ...

  6. 【POJ - 2376】Cleaning Shifts(贪心)

    Cleaning Shifts Descriptions: 原文是English,我这就直接上Chinese了,想看原文的点一下链接哦 大表哥分配 N (1 <= N <= 25,000) ...

  7. SequoiaDB、SequoiaSQL、Cloudera Manager4.8.0、Cloudera CDH4.5 详细安装教程

    1安装SequoaiDB集群 1.1配置信任关系 以root用户执行下面的操作 1 执行命令 ssh-keygen 然后一直回车确定即可 2 每台机器都打开id_rsa.pub文件 vi ~/.ssh ...

  8. 一起学Android之Activity

    概述 本文以一个简单的小例子,简述Android开发中Activity的相关知识,仅供学习分享使用. 什么是Activity? Activity是一个应用程序组件,通常显示为一个页面,用户可以通过Ac ...

  9. Python文件将日志文件中每天的日志拿出来

    file_log.txt文件内容如下: with open('file_log.txt', 'r', encoding='utf-8') as f: for i in f: s = i.split() ...

  10. AtCoder Grand Contest 015 E - Mr.Aoki Incubator

    题目传送门:https://agc015.contest.atcoder.jp/tasks/agc015_e 题目大意: 数轴上有\(N\)个点,每个点初始时在位置\(X_i\),以\(V_i\)的速 ...