NTP服务的安装和使用

NTP服务的安装和使用

本文是基于CentOS 7.3系统环境,进行NTP的安装和使用

  • CentOS 7.3

一、NTP简介

(1) NTP

网络时间协议,英文名称:Network Time Protocol(NTP)是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。NTP的目的是在无序的Internet环境中提供精确和健壮的时间服务。

二、NTP的服务端安装和配置

(1) 安装NTP

date # 系统时间
yum -y install net-tools # netstat
yum -y install ntp 

(2) 开放防火墙端口

firewall-cmd --add-port=123/udp --permanent
firewall-cmd --add-port=123/tcp --permanent
firewall-cmd --reload

(3) 启动NTP

systemctl stop chronyd
systemctl disable chronyd
systemctl start ntpd
systemctl enable ntpd

(4) 配置NTP

在这里插入图片描述

# 限制 192.168.0.0~192.168.0.255之间的服务器可以访问
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
# 如果上面的服务器都无法同步,那么就与本地系统时间同步
server 127.127.1.0
fudge 127.127.1.0 stratum 10

(5) 重启NTP

systemctl restart ntpd

(6) 查看NTP状态

ntpstat

(7) 列出上层NTP服务器的连接状态

ntpq -p

(8) 查看硬件BIOS时间

hwclock -r

(9) 将当前系统时间写入BIOS时间

hwclock -w

三、NTP的客户端安装和配置

(1) 安装NTP

yum -y install ntp

(2) 启动NTP

ntp有自我保护机制,如果本机与上源时间相差太大,那么ntpd不会运行,因此在设置同步之前,一定要手动使用ntpdate与上源进行时间同步,然后在启动ntp服务

ntpdate 192.168.0.207

(3) 启动NTP

systemctl stop chronyd
systemctl disable chronyd
systemctl start ntpd
systemctl enable ntpd

(4) 配置NTP

在这里插入图片描述

# 本地局域网内的时间服务器同步
server 192.168.0.207
# 如果上面的服务器都无法同步,那么就与本地系统时间同步
server 127.127.1.0

(5) 重启NTP

systemctl restart ntpd

原创文章 93 获赞 135 访问量 151万+

猜你喜欢

转载自blog.csdn.net/qq_32599479/article/details/105847857