第一步:

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. HTTP node静态资源请求加载demo

    MIME type的缩写为(Multipurpose Internet Mail Extensions)代表互联网媒体类型(Internet media type),MIME使用一个简单的字符串组成, ...

  2. Linux系统安装完的调整和安全

    精简开机系统自启动 •五个企业环境中开机自启动的服务; sshd:远程连接linux服务器必须开启 rsyslog:日志相关软件 network:网络服务 crond:系统和用户配置的计划任务周期性进 ...

  3. android调用第三方库——第一篇 (转载)

    转自:http://blog.csdn.net/jiuyueguang/article/details/9447245 版权声明:本文为博主原创文章,未经博主允许不得转载. 0:前言: 这两天一直在研 ...

  4. hdoj3790 【最短路】

    这一题啊,其实还是很简单的~(A掉了就很简单啊~) 思路: 松弛,然后在里面维护一个小最短路~: A掉这一题,感觉松弛的理解又上了一个台阶,以及spfa的原理,最短路用到的原理就是松弛,先把图构造到最 ...

  5. Fiddler 学习

    Little Skill Fiddler 官网: https://www.telerik.com/fiddler 来自 https://www.cnblogs.com/zhaoyanjun/p/706 ...

  6. jQuery笔记之工具方法

    jQuery 工具方法 $.type()判断数据类型 $.isArray() $.isFunction() $.isWindow()... $.trim()消除空格 $.proxy()改变this指向 ...

  7. 二分搜索 2015百度之星初赛1 HDOJ 5248 序列变换

    题目传送门 /* 二分搜索:在0-1e6的范围找到最小的max (ai - bi),也就是使得p + 1 <= a[i] + c or a[i] - c 比赛时以为是贪心,榨干智商也想不出来:( ...

  8. 494 Target Sum 目标和

    给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S.现在你有两个符号 + 和 -.对于数组中的任意一个整数,你都可以从 + 或 -中选择一个符号添加在前面.返回可以使最终数组和为 ...

  9. [转]Linq 如何实现 in 与 not in

    本文转自:http://blog.csdn.net/zhangyumei/article/details/5620363 接触 LINQ 也有很长的一段时间了,有些在 SQL 语句中用的很顺手的东西在 ...

  10. let块级引起的闭包思考

    因为es6在node中用的比较频繁,最近在按计划根据阮一峰的es6教程从头开始学习一遍, 第一步遇到的就是“看似非常熟悉”的let小伙伴,核心character如下: 即:let变量的作用域只在块内. ...