如何在 CentOS/RHEL 7 中配置 NTP 服务器和客户端

下面讨论的示例适用于基本的 NTP 服务器和客户端。
NTP 代表 Network Transport Protocol(网络传输协议),它用于使用共同的可靠来源来保持服务器上的时间彼此同步以获取时间。

NTP 服务器配置

  1. 在服务器上安装所需的ntp包。
# yum install ntp
  1. 确保以下条目在 ntp 配置文件 /etc/ntp.conf 中。
# cat /etc/ntp.conf
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org
restrict 10.10.10.0 mask 255.255.255.0 nomodify notrap
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

根据配置文件,NTP 服务器仅服务于子网 10.10.10.0/24 中的 NTP 客户端。
我们可以从 pool.ntp.org 获取特定于我们所在地区的公共 NTP 服务器。

在 /etc/ntp.conf 文件中,我们必须提及环境中的 NTP 服务器。

  1. 现在可以启动ntpd服务了。

对于 RHEL 5,6 :

# service ntpd start

对于 RHEL 7:

# systemctl start ntpd.service
更多: zhilu jiaocheng

NTP客户端配置

  1. 对于客户端NTP配置,在/etc/ntp.conf文件中添加以下配置。
# cat /etc/ntp.conf
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
server ntp.server.com
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

这里,ntp.server.com 是我们在文章开头显示的示例中配置为 NTP 服务器的服务器。
可以有多个 NTP 服务器用于冗余目的。
在 /etc/ntp.conf 文件中为每个 NTP 服务器添加一个新行。

  1. 在ntp客户端服务器上启动ntpd服务。

对于 RHEL 5,6 :

# service ntpd start

对于 RHEL 7:

# systemctl start ntpd.service
日期:2020-09-17 00:12:13 来源:oir作者:oir