ntp服务器同步时间详细配置
部署NTP服务器进行时间同步
NTP服务概述
1、原理

2、端口(123)
1 [root@linl_S ~]# vim /etc/services
2 nntp 119/tcp readnews untp # USENET News Transfer Protocol
3 nntp 119/udp readnews untp # USENET News Transfer Protocol
4 ntp 123/tcp
5 ntp 123/udp # Network Time Protocol
1 [root@linl_S ~]# ls /mnt/Packages/ntp*
2 /mnt/Packages/ntp-4.2.6p5-1.el6.x86_64.rpm #NTP服务端软件包
3 /mnt/Packages/ntpdate-4.2.6p5-1.el6.x86_64.rpm #NTP客户端软件包

1 [root@linl_S ~]# yum -y install ntp #NTP两个软件包都会安装上
2 ...
3 Installed:
4 ntp.x86_64 0:4.2.6p5-1.el6
5 Dependency Installed:
6 ntpdate.x86_64 0:4.2.6p5-1.el6
7 Complete!

1 [root@linl_C ~]# rpm -ivh /mnt/Packages/ntpdate-4.2.6p5-1.el6.x86_64.rpm #只安装ntpdate安装包
2 warning: /mnt/Packages/ntpdate-4.2.6p5-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
3 Preparing... ########################################### [100%]
4 package ntpdate-4.2.6p5-1.el6.x86_64 is already installed
1 [root@linl_S ~]# ls /etc/ntp.conf
2 /etc/ntp.conf

1 [root@linl_S ~]# service ntpd start #启动ntp服务
2 Starting ntpd: [ OK ]
3 [root@linl_S ~]# netstat -anptu |grep 123 #查看端口123是否开放
4 udp 0 0 10.0.0.15:123 0.0.0.0:* 5846/ntpd
5 udp 0 0 127.0.0.1:123 0.0.0.0:* 5846/ntpd
6 udp 0 0 0.0.0.0:123 0.0.0.0:* 5846/ntpd
7 udp 0 0 fe80::20c:29ff:fea9:c1ae:123 :::* 5846/ntpd
8 udp 0 0 ::1:123 :::* 5846/ntpd
9 udp 0 0 :::123 :::* 5846/ntpd
10 [root@linl_S ~]# chkconfig ntpd on #开机自启动

实战1:手动同步NTP时间服务器

1 [root@linl_S ~]# vi /etc/ntp.conf
2 # Use public servers from the pool.ntp.org project.
3 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
4 server 0.rhel.pool.ntp.org iburst #找一个可以使用的NTP时间服务器
5 server 1.rhel.pool.ntp.org iburst
6 server 2.rhel.pool.ntp.org iburst
7 server 3.rhel.pool.ntp.org iburst

1 [root@linl_C ~]# ntpdate 0.rhel.pool.ntp.org
2 22 May 22:04:41 ntpdate[5733]: adjust time server 202.118.1.130 offset 0.027428 sec
1 [root@linl_S ~]# ntpdate 0.rhel.pool.ntp.org
2 22 May 22:06:17 ntpdate[2464]: the NTP socket is in use, exiting
1 [root@linl_S ~]# service ntpd stop
2 Shutting down ntpd: [ OK ]
3 [root@linl_S ~]# ntpdate 0.rhel.pool.ntp.org
4 22 May 22:13:27 ntpdate[2495]: adjust time server 202.118.1.130 offset -0.068183 sec
实战2:搭建内网NTP服务器,内网服务器通过此NTP服务器进行时间同步

1 [root@linl_S ~]# vi /etc/ntp.conf
2 # Permit all access over the loopback interface. This could
3 # be tightened as well, but to do so would effect some of
4 # the administrative functions.
5 restrict 127.0.0.1
6 restrict -6 ::1
7 restrict 10.0.0.0 mask 255.255.255.0 #允许10.0.0.0 网段中的服务器访问本ntp服务器进行时间同步
8 restrict 10.0.0.16 #允许单个IP地址访问本ntp服务器
9 # Use public servers from the pool.ntp.org project.
10 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
11 server 210.72.145.44 #指定本ntp服务器的上游ntp服务器为210.72.145.44,并且设置为首先服务器。同步时间为:从上到下,写的越靠上,优先级越高。(此服务器同步不了时间,寻找下一个ntp服务器)。此IP地址是中国国家授时中心ntp服务器。
12 server 133.100.11.8 #当上面服务器同步不了,则寻找第二个。此IP地址是日本福冈大学ntp服务器。
13 server 0.rhel.pool.ntp.org iburst
14 server 1.rhel.pool.ntp.org iburst
15 server 2.rhel.pool.ntp.org iburst
16 server 3.rhel.pool.ntp.org iburst
17 server 127.127.1.0 #local clock 如果上面的服务器都无法同步时间,就和本地系统时间同步。127.127.1.0在这里是一个IP地址,不是网段。
18 fudge 127.127.1.0 stratum 10 #127.127.1.0 为第10层。ntp 和127.127.1.0同步完后,就变成了11层。 ntp是层次阶级的。同步上层服务器的stratum 大小不能超过或等于16。


1 [root@linl_S ~]# /etc/init.d/ntpd start
2 Starting ntpd: [ OK ]
3 [root@linl_S ~]# netstat -ln |grep 123
4 udp 0 0 10.0.0.15:123 0.0.0.0:*
5 udp 0 0 127.0.0.1:123 0.0.0.0:*
6 udp 0 0 0.0.0.0:123 0.0.0.0:*
7 udp 0 0 fe80::20c:29ff:fea9:c1ae:123 :::*
8 udp 0 0 ::1:123 :::*
9 udp 0 0 :::123 :::*


1 [root@linl_S ~]# ntpq -p #列出本NTP服务器与上游服务器的连接状态
2 remote refid st t when poll reach delay offset jitter
3 ==============================================================================
4 210.72.145.44 .INIT. 16 u - 64 0 0.000 0.000 0.000
5 133.100.11.8 .INIT. 16 u - 64 0 0.000 0.000 0.000
6 *dns1.synet.edu. 202.118.1.47 2 u 32 64 3 60.058 7.261 6.860
7 news.neu.edu.cn .INIT. 16 u - 64 0 0.000 0.000 0.000
8 202.118.1.130 .INIT. 16 u - 64 0 0.000 0.000 0.000
9 42.96.167.209 .INIT. 16 u - 64 0 0.000 0.000 0.000
10 LOCAL(0) .LOCL. 10 l 96 64 2 0.000 0.000 0.000
11 [root@linl_S ~]# ntpstat #列出是否与上游服务器连接。需要过5分钟
12 synchronised to NTP server (202.112.29.82) at stratum 3 #可以看到我们当前在3层
13 time correct to within 257 ms #ms 毫秒是一种较为微小的时间单位,是一秒的千分之一。
14 polling server every 64 s

1 [root@linl_C ~]# date -s "2015-5-23 11:30" #先设置一个错误的时间点
2 Sat May 23 11:30:00 CST 2015
3 [root@linl_C ~]# ntpdate lin_S #进行ntp时间同步
4 23 May 11:34:10 ntpdate[6686]: step time server 10.0.0.15 offset 31622622.275270 sec
5 [root@linl_C ~]# date
6 Mon May 23 11:34:16 CST 2016 #时间同步成功
1 [root@linl_C ~]# ntpdate lin_S
2 23 May 11:38:02 ntpdate[6694]: no server suitable for synchronization found
1 [root@linl_S ~]# cat /etc/sysconfig/clock
2 # The time zone of the system is defined by the contents of /etc/localtime.
3 # This file is only for evaluation by system-config-date, do not rely on its
4 # contents elsewhere.
5 ZONE="Asia/Shanghai"

1 [root@linl_C ~]# date -s "2016-5-22 13:50"
2 Sun May 22 13:50:00 CST 2016
3 [root@linl_C ~]# hwclock -r
4 Mon 23 May 2016 01:53:50 PM CST -0.110948 seconds
5 [root@linl_C ~]# hwclock -w
6 [root@linl_C ~]# hwclock -r
7 Sun 22 May 2016 01:50:48 PM CST -0.783098 seconds #已将系统date时间写入到BIOS时间

1 [root@linl_C ~]# ntpdate lin_S
2 23 May 19:50:44 ntpdate[7507]: step time server 10.0.0.15 offset 1.239826 sec
1 [root@linl_C ~]# crontab -e
2 0 12 * * * /usr/sbin/ntpdate lin_S
ntp服务器同步时间详细配置的更多相关文章
- Centos7部署ntp服务器同步时间以及直接将本地时间同步为北京时间
一.查看配置 查看时区列表: timedatectl list-timezones|grep Asia 查看当前时间: date 查看当前设置: [root@localhost ~]# timedat ...
- VMware ESXi 5.5无法与Windows 2012 NTP Server同步时间
这次笔者需要面对的环境对时间的同步有比较高的要求, 而虚拟化的环境中时间是比较容易出问题的, 您可以参考上一篇博文为什么Domain controller上的time synchronization非 ...
- linux 下使rdate命令支持ipv6 ntp server 同步时间
如果使用linux 下,busybox自带的rdate命令 去ipv6 的ntp server 同步时间的话,会提示invalid argument :无效参数. 那么现在下载rdate的源码并对其进 ...
- Centos7安装搭建NTP服务器和NTP客户端同步时间
NTP简介: NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在计算机的世界里,时间非常地重要 例如:对于火箭发射这种科研活动,对时间的 ...
- chronyd时间服务器同步时间配置
chrony是两个用来维持计算机系统时钟准确性的程序,这两个程序命名为chronyd和chronyc. chronyd是一个在系统后台运行的守护进程.他根据网络上其他时间服务器时间来测量本机时间的偏移 ...
- C# 获取NTP远程同步时间
收到一个需要定时同步远程服务器的需求,用C# 实现 网上搜索到解决方案,代码如下: 获取远程时间 参数配置:"NTPServer" 远程时间服务器地址 获取远程服务器时间代码: ...
- Linux服务器同步时间
进行Linux服务器的时间同步是一件需要注意的事情,不然,集群中的服务器时间不同将导致许多奇怪问题发生, 如果没有安装crontab,那么,使用yum install crontabs进行安装和启动, ...
- centos7开启ntp并同步时间到指定时区
前提:近期公司都是使用的直接对外的云服务器,在登上服务器后用date命令查看新服务器的时间,发现并不是标准时间,于是需要做时间同步.我这里讲的是能连接外网的情况下,在服务器不多的情况下是否此方法,大型 ...
- 关于Bootstrap fileinput 上传新文件,移除时触发服务器同步删除的配置
在Bootstrap fileinput中移除预览文件时可以通过配置initialPreviewConfig: [ { url:'deletefile',key:fileid } ] 来同步删除服务器 ...
随机推荐
- 京东2015年应届生招聘笔试题(A)卷答案选择题部分
1.操作系统死锁的必要条件(多选题):() A.相互排斥条件 B.系统资源有限 C.进程调度不合理 D.环路等待条件 答:A,C,D 參考资料:http://blog.sina.com ...
- ORACLE物化视图具体解释
一.物化的一般使用方法物化视图是一种特殊的物理表,"物化"(Materialized)视图是相对普通视图而言的.普通视图是虚拟表.应用的局限性大,不论什么对视图的查询.oracle ...
- Codeforces 223C Partial Sums 数论+组合数学
题意非常easy,求不是那么好求的,k非常大 要操作非常多次,所以不可能直接来的.印象中解决操作比較多无非线段树 循环节 矩阵 组合数等等吧,这道题目 也就仅仅能多画画什么 的了 就以第一个案例为主吧 ...
- scapy windows install
最近有点扫描网络的需求,都说scapy好,但是安装是个事(当然指的是windows安装)有个scapy3k,支持python3,可惜需要powershell,也就是说windows xp是没有戏了. ...
- erlang中通过ip和子网掩码,计算地址范围 【二进制和十进制的转换】
在程序中,难免用的二进制和十进制之间的转换.遇到一个场景,通过ip和子网掩码,计算地址范围. 而地址范围为:网络地址+1—— 广播地址 -1 . 网络地址即ip和子网掩码的与的位运算.广播地址为:网 ...
- XP,32/64位Win7,32/64位Win10系统【电脑城版】
本系统是10月最新完整版本的Windows10 安装版镜像,Win10正式版,更新了重要补丁,提升应用加载速度,微软和百度今天宣布达成合作,百度成为Win10 Edge浏览器中国默认主页和搜索引擎,系 ...
- WPF之DataGrid篇:DataGridComboBoxColumn
准备数据源 1 准备数据源.基类为Student,数据对象为Student3,数据集为StuList3. END 编辑DataGrid显示列 1 若要填充下拉列表,请首先使用下列选项之一设置 ...
- 转载 OSX开发推荐书籍列表
初级 (开发语言, 开发工具)Objective-C Beginner's GuideObjective-C for Absolute Beginners 2nd EditionLearning Co ...
- python推荐系统库
Python推荐系统库——Surprise 在Python中实现你自己的推荐系统 python-recsys:一款实现推荐系统的python库
- 【BZOJ3721】PA2014 Final Bazarek 贪心
[BZOJ3721]PA2014 Final Bazarek Description 有n件商品,选出其中的k个,要求它们的总价为奇数,求最大可能的总价. Input 第一行一个整数n(1<=n ...