Linux配置NTP时间服务器

文章
林里克斯

Linux上搭建NTP时间服务器

实验平台:CentOS 6.8



1.NTP简介


NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms

NTP服务器就是利用NTP协议提供时间同步服务的。

ntp官网:

http://www.ntp.org/

2.NTP服务器安装


$ rpm -qa | grep ntp      #查询系统是否安装ntp
$ ntp-4.2.6p5-5.el6.centos.x86_64

如果查询为空则没有就按以下安装

$ yum -y install ntp

3.配置NTP服务


编辑配置文件ntp.conf

$ vim /etc/ntp.conf

# restrict default kod nomodify notrap nopeer noquery
restrict default nomodify
# nomodify客户端可以同步
# 将默认时间同步源注释改用可用源
# 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
server ntp1.aliyun.com    #新加,可是域名 可是ip
server time.nist.gov      #新加,可是域名 可是ip
server 192.168.7.2        #这里是本机地址

4.启动NTP服务器


如果计划任务有时间同步,先注释,两种用法会冲突。

$ crontab -e
#*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
/etc/init.d/ntpd strat  #启动服务
Starting ntpd:                                             [  OK  ]

查看时间服务器的状态

$ ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp1.aliyun.com 10.137.38.86     2 u   22   64    1  525.885  -42.367   0.000
[root@oldboyedu ~]# ntpstat
synchronised to NTP server (110.75.186.247) at stratum 3
   time correct to within 4257 ms
   polling server every 64 s

$ ntpdate 10.0.0.9
 7 Dec 18:43:07 ntpdate[26950]: the NTP socket is in use, exiting

5.客户机时间同步


客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。

$ ntpdate 192.168.7.2

7 Dec 18:40:16 ntpdate[1453]: step time server 10.0.0.9 offset 40.880807 sec

Over~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

686 0 2017-01-21


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-04-26

今日天气
站点统计
  • 文章总数:240篇
  • 分类总数:29个
  • 评论总数:10条
  • 本站总访问量 216039 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!