centos7 多台服务器同步ntp
时间: 2023-07-11 09:06:12 浏览: 57
要实现多台 CentOS 7 服务器同步 NTP,需要按照以下步骤进行操作:
1. 确认每台服务器上的 NTP 服务都已经安装并启动。如果没有安装,可以使用以下命令进行安装:
```
yum install ntp
```
2. 在其中一台服务器上设置为 NTP 服务器,其他服务器将向该服务器同步时间。在该服务器上修改 /etc/ntp.conf 文件,配置 NTP 服务器信息以及允许其他服务器同步时间。例如:
```
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
```
其中,server 后面的 IP 地址为 NTP 服务器地址,restrict 用于控制哪些 IP 地址可以同步时间。
3. 在其他服务器上修改 /etc/ntp.conf 文件,将其中的 server 行改为指向 NTP 服务器的 IP 地址,例如:
```
server 192.168.1.100 iburst
```
4. 重启 NTP 服务,在所有服务器上执行以下命令:
```
systemctl restart ntpd
```
现在,所有服务器都应该已经同步了 NTP 服务器的时间。你可以使用以下命令检查服务器时间是否已经同步:
```
timedatectl
```
如果服务器的时间与 NTP 服务器时间相同,则说明同步成功。