NTP服务器搭建和客户端配置
admin
2023-03-20 02:21:11
0

1 搭建NTP服务器

准备搭建环境
主机IPOS备注
NTP Server192.168.5.180CentOS 6
NTP Client192.168.5.181CentOS 6

1.1 安装NTP服务程序

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

1.2 配置NTP服务程序

红色为添加的配置,其它都是默认配置
  1. [root@node1 ~]# cp /etc/ntp.conf{,.bak} #备份ntp配置文件
  2. [root@node1 ~]# vim /etc/ntp.conf  #编辑ntp配置文件
  3. [root@node1 ~]# grep -Ev '^$|^#' /etc/ntp.conf
  4. driftfile /var/lib/ntp/drift
  5. restrict default kod nomodify notrap nopeer noquery
  6. restrict -6 default kod nomodify notrap nopeer noquery
  7. restrict 127.0.0.1 
  8. restrict -6 ::1
  9. restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap #允许该网段内的主机可以进行校时
  10. restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap
  11. server time.nist.gov prefer #上层NTP服务器地址,prefer表示优先
  12. server 0.centos.pool.ntp.org iburst
  13. server 1.centos.pool.ntp.org iburst
  14. server 2.centos.pool.ntp.org iburst
  15. server 3.centos.pool.ntp.org iburst
  16. includefile /etc/ntp/crypto/pw
  17. keys /etc/ntp/keys

1.3 启动NTP服务程序

# chkconfig ntpd on# /etc/init.d/ntpd start
# /etc/init.d/ntpd stop# /etc/init.d/ntpd restart
查看NTP启动的端口
  1. [root@node1 ~]# netstat -tlunp | grep ntp
  2. udp 0 0 192.168.5.180:123 0.0.0.0:* 28331/ntpd
  3. udp 0 0 127.0.0.1:123 0.0.0.0:* 28331/ntpd
  4. udp 0 0 0.0.0.0:123 0.0.0.0:* 28331/ntpd
  5. udp 0 0 fe80::20c:29ff:fe2b:9990:123 :::* 28331/ntpd
  6. udp 0 0 ::1:123 :::* 28331/ntpd
  7. udp 0 0 :::123 :::* 28331/ntpd

1.4 查看NTP服务状态

   现在ntp服务器已经启动了,不过与上层服务器连接则还需要一些时间,通常启动NTP后在15分钟内才会和上层NTP服务器顺利连接上。如何确定NTP服务器顺利地更新了自己的时间呢?可以使用以下几个命令查看
  1. [root@node1 ~]# ntpstat
  2. synchronised to NTP server (94.237.64.20) at stratum 3 
  3.    time correct to within 362 ms
  4.    polling server every 64 s
   这个命令列出NTP服务器是否已经与上层NTP服务器连接,由上述的输出结果可以知道,时间已经校正约362ms,且每隔64秒会主动去更新
  1. [root@node1 ~]# ntpq -p
  2. remote refid st t when poll reach delay offset jitter
  3. ==============================================================================
  4. time-a.nist.gov .INIT. 16 u - 128 0 0.000 0.000 0.000
  5. *makaki.miuku.ne 218.186.3.36 2 u 16 64 377 269.215 44.744 69.262
  6. +ntp1.ams1.nl.le 130.133.1.10 2 u 21 64 377 271.981 -32.490 66.809
  7. +ntp.wdc1.us.lea 130.133.1.10 2 u 22 64 337 308.368 -6.923 90.300
  8. 61-216--104. 62.161.56.158 3 u 38 64 21 80.450 -33.733 23.397
注意:,
ntpq -p命令可以列出当前我们的NTP服务器与上层NTP服务器的连接状态,以上几个字段的意义如下:
remote: NTP主机的IP或主机名;注意左边的符号:
*:表示正在使用的NTP服务器
+:表示已经连接成功,但是作为备用提供时间更新的NTP服务器;
refid: 上层NTP服务器地址;
st: 就是stratum阶层
when:几秒钟前做过时间同步更新操作;pool:下次更新在几秒钟之后;reach:已经向上层NTP服务器要求更新的次数;delay: 网络传输过程中延迟的时间,单位为10-6offset:时间补偿结果,单位为10-3秒;jitter:系统时间与BIOS硬件时间的差异时间,单位为10-6秒;

2 NTP客户端配置

Client:192.168.5.181
[root@node2 tools]# ntpdate 192.168.5.18015 Jun 14:36:19 ntpdate[24881]: adjust time server 192.168.5.180 offset -0.002062 sec[root@node2 tools]# hwclock -w  #将系统时间写入BIOS硬件时间[root@node2 tools]# hwclock Thu 15 Jun 2017 03:46:26 PM CST  -0.860434 seconds[root@node2 tools]# dateThu Jun 15 15:46:38 CST 2017[root@node2 tools]# crontab -e  #配置计划任务,系统第隔3分钟自动与NTP服务器192.168.5.180进行校时
*/3 * * * * (/usr/sbin/ntpdate 192.168.5.180 && /sbin/hwclock -w) &> /dev/null

相关内容

热门资讯

今日重磅消息“宝马互娱有挂吗?... 有 亲,根据资深记者爆料宝马互娱是可以开挂的,确实有挂(咨询软件无需打开...
我来教教您“欢又聊红包有没有挂... 家人们!今天小编来为大家解答欢又聊红包透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买...
洪都拉斯总统大选胜利者曾说要恢... 澎湃新闻记者 杨文钦 朱郑勇12月25日,外交部发言人林剑主持例行记者会。法新社记者提问,洪都拉斯的...
今日重大发现“红豆大厅开挂器?... 家人们!今天小编来为大家解答红豆大厅透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买很...
【第一财经】“玄龙炸/金/花开... 您好:玄龙炸/金/花这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这...
【今日要闻】“悟空黑桃A究竟有... 您好:悟空黑桃A这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游...
【第一消息】“阿当福建麻将开挂... 您好:阿当福建麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这款...
玩家分享攻略“神皇炸/金/花是... 玩家分享攻略“神皇炸/金/花是不是有挂?”(确实真的有挂)您好,神皇炸/金/花这个游戏其实有挂的,确...
【今日要闻】“微信拼三张有挂吗... 家人们!今天小编来为大家解答微信拼三张透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买...
越秀天悦江湾“领潮级”交付盛启... 从蓝图落地,到实景“说话”,被称作“金水神盘”的越秀·天悦江湾,一批次即将在12月26日盛大交付。这...