centos7搭建NTP时间服务器
时间: 2023-11-22 09:49:18 浏览: 101
构建NTP时间服务器
以下是在CentOS 7上搭建NTP时间服务器的步骤:
1.安装NTP软件包
```shell
yum install ntp -y
```
2.配置NTP服务器
编辑`/etc/ntp.conf`文件,添加如下内容:
```shell
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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
# Allow LAN traffic.
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
```
其中,`server`行指定了NTP服务器使用的公共时间服务器,`restrict`行指定了允许访问NTP服务器的IP地址范围。
3.启动NTP服务
```shell
systemctl start ntpd
```
4.设置NTP服务开机自启动
```shell
systemctl enable ntpd
```
5.检查NTP服务状态
```shell
systemctl status ntpd
```
如果NTP服务正在运行,则输出类似以下内容:
```shell
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-08-10 14:20:20 CST; 1h 5min ago
Main PID: 1234 (ntpd)
CGroup: /system.slice/ntpd.service
└─1234 /usr/sbin/ntpd -u ntp:ntp -g
```
6.检查NTP服务器是否正常工作
```shell
ntpq -p
```
如果NTP服务器正常工作,则输出类似以下内容:
```shell
remote refid st t when poll reach delay offset jitter
==============================================================================
*0.centos.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000
+1.centos.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000
+2.centos.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000
+3.centos.pool. .POOL. 16 p - 64 0 0.000 0.000 0.000
```
阅读全文