当前位置:   首页安装配置CentOS 7搭建ntp时钟主机的步骤详解

CentOS 7搭建ntp时钟主机的步骤详解

发布日期:2022-04-04 13:17 | 文章来源:CSDN

前言

NTP 网络时间协议用来同步网络上不同主机的系统时间。你管理的所有主机都可以和一个指定的被称为 NTP 主机的时间主机同步它们的时间。而另一方面,一个 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 * * * 五个字符表示 分 时 日 月 年

总结

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

联系我们
关于使用场景和技术架构的更多咨询,请联系我们的销售和技术支持团队。
Yingsoo Host

在线
客服

在线客服:7*24小时在线

客服
热线

400-630-3752
7*24小时客服服务热线

关注
微信

关注官方微信
顶部