NTP服务器 服务器

NTP服务器怎么配置和部署

iii
141
2022-12-13 15:25:41
栏目: 云计算

NTP服务器配置和部署的方法:1、使用cp命令备份ntp服务器配置文件;2、使用egrep命令优化配置文件;3、使用vim命令编辑配置文件,包括配置文件文本、允许内网其他机器同步时间、定义使用的上游ntp服务器和定义服务器时间;4、启动NTP服务器;5、测试服务器与客户端时间是否同步。

具体操作如下:

1、备份ntp服务器配置文件

cp /etc/ntp.conf /etc/ntp.conf.bak

ll /etc/ntp.conf*

2、精简优化配置文件

egrep -v "^$|#" /etc/ntp.conf.bak >/etc/ntp.conf

3、编辑配置文件

vim /etc/ntp.conf

配置文件文本

driftfile /var/lib/ntp/drift

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

restrict 127.0.0.1 

restrict -6 ::1

允许内网其他机器同步时间

restrict 172.16.1.0 mask 255.255.255.0 nomodify notr

#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

定义使用的上游 ntp服务器,将原来的注释

server ntp1.aliyun.com

server time1.aliyun.com

允许上层时间服务器主动修改本机时间

restrict time1.aliyun.com nomodify notrap noquery

restrict ntp1.aliyun.com nomodify notrap noquery

外部时间服务器不可用时,以本地时间作为时间服务

server 127.127.1.0 

fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

4、启动NTP服务器

Centos6: /etc/init.d/ntpd start centos7: systemctl start ntpd

ntpq -p 显示节点列表

5、客户端时间同步测试

ntpdate 10.0.0.111(ntp服务器)

0
看了该问题的人还看了