CentOS 7 搭建ntp时钟服务器的步骤详解

发布时间:2022-04-22 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了CentOS 7 搭建ntp时钟服务器的步骤详解脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

前言 

NTP 网络时间协议用来同步网络上不同主机的系统时间。你管理的所有主机都可以和一个指定的被称为 NTP @R_512_2769@的时间服务器同步它们的时间。而另一方面,一个 NTP 服务器会将它的时间和任意公共 NTP 服务器,或者你选定的服务器同步。由 NTP 管理的所有系统时钟都会同步精确到毫秒级。

公司环境中,如果他们不想为 NTP 传输打开火墙,就有必要设置一个内部 NTP 服务器,然后让员工使用内部服务器而不是公共 NTP 服务器。在这篇文章中,我们会介绍在CentOS 7 搭建ntp时钟服务器的步骤,一起来看看吧。

服务器 : 192.168.137.3

客户机:  192.168.137.6

1、 服务器端

centos7下首先确认服务器的防火墙、selinux关闭状态

# cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core)

第一步  为服务器和客户机安装ntp   ntpdate   --默认已安装

# yum install ntp ntpdate -y

第二步 查找时间同步服务器

http://www.pool.ntp.org/zone/asia

第三步  编辑 /etc/ntp.conf

server time.windows.COM
server s2m.time.edu.cn
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org
server 127.127.1.0 iburst  local clock 当外部时间不可用时,使用本地时间。
restrict 192.168.137.1 mask 255.255.255.0 nomodify  允许更新的IP地址段

第四步  启动ntp服务

Systemctl start ntpd
systemctl enable ntpd.service 设置开机启动服务

第五步  验证服务

# ntpq -p

  remote   refid  st t when poll reach delay offset JITter
==============================================================================
 211.138.200.209 .INIT.   16 u - 64 0 0.000 0.000 0.000
 ns.pku.edu.cn .INIT.   16 u - 64 0 0.000 0.000 0.000
 211.138.200.208 .INIT.   16 u - 64 0 0.000 0.000 0.000
 nipPEr.paina.jp .INIT.   16 u - 64 0 0.000 0.000 0.000
 send.mx.cdnetwo .INIT.   16 u - 64 0 0.000 0.000 0.000
*LOCAL(0)  .LOCL.   5 l 52 64 1 0.000 0.000 0.000

# date -R
Fri, 15 Jul 2016 15:28:34 +0800

2、客户端

第六步  远程客户端时间同步测试

# date 
Fri Jul 15 15:31:22 CST 2016
# ntpdate 192.168.137.3
15 Jul 15:33:04 ntpdate[63912]: step time server 192.168.137.3 offset -4.492463 sec

第七步 客户端设置计划任务每天晚上1点同步时间

crontab -e
00 01 * * * root /usr/sbin/ntpdate 192.168.137.3; /sbin/hwclock -w  

格式 00 01 * * *  五个字符表示  分 时 日 月 年

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

脚本宝典总结

以上是脚本宝典为你收集整理的CentOS 7 搭建ntp时钟服务器的步骤详解全部内容,希望文章能够帮你解决CentOS 7 搭建ntp时钟服务器的步骤详解所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:centos7