Centos7笔记之NTP服务器安装设置

一、目标

在centos7上安装设置ntp服务器;

在centos7上设置ntp客户端。

二、架构

NTP架构
ip role os & module
10.1.1.5 ntp server centos 7.6,ntpd
10.1.1.6 ntp client centos 7.6 ,ntpd

三、ntp服务器安装配置

1.安装ntp组件

yum install -y ntp ntpdate -y

2.查询服务器上的ntp组件(可略)

[root@ntpserver ~]# rpm -qa |grep ntp
fontpackages-filesystem-1.44-8.el7.noarch
python-ntplib-0.3.2-1.el7.noarch
ntpdate-4.2.6p5-29.el7.centos.2.x86_64
ntp-4.2.6p5-29.el7.centos.2.x86_64

3.修改ntp服务器配置文件

cp /etc/ntp.conf{,.bak}
vim /etc/ntp.conf

● 注释掉【#restrict default nomodify notrap nopeer noquery】

● 增加一行【restrict 10.1.1.5 nomodify notrap nopeer noquery】

● 增加一行【restrict 10.1.1.0 mask 255.255.255.0 nomodify notrap】

● 注释掉【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】

● 增加一行【server 127.127.1.0】

● 增加一行【Fudge 127.127.1.0 stratum 10】

下面展示出完整配置

driftfile /var/lib/ntp/drift
restrict 10.1.1.5 nomodify notrap nopeer noquery
restrict 10.1.1.0 mask 255.255.255.0 nomodify notrap
restrict 127.0.0.1 
restrict ::1
server 127.127.1.0
Fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

注释:照着上面的设置的话,那如果ntp服务器时间与真实的时间有差异的话,ntp客户端也会跟着ntp服务器一错到底。

感觉如果想让ntp服务器和互联网时间也同步,那就把restrict 127.0.0.1给注释掉,还有把server 127.127.1.0给改成如ntp.aliyun.com

4.重启ntpd服务、并设置开机自启

systemctl restart ntpd
systemctl enable ntpd

5.开放ntp的端口udp123

●方法1:关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

●方法2:开放端口udp123

firewall-cmd --permanent --add-port=123/udp
firewall-cmd --reload
firewall-cmd --list-all

6.检验NTP服务器是否安装成功

[root@ntpserver ~]# netstat -tlunp | grep ntp
udp        0      0 192.168.122.1:123       0.0.0.0:*                           86814/ntpd          
udp        0      0 10.1.1.5:123            0.0.0.0:*                           86814/ntpd          
udp        0      0 127.0.0.1:123           0.0.0.0:*                           86814/ntpd          
udp        0      0 0.0.0.0:123             0.0.0.0:*                           86814/ntpd          
udp6       0      0 fe80::ee7:2e9:62c4::123 :::*                                86814/ntpd          
udp6       0      0 ::1:123                 :::*                                86814/ntpd          
udp6       0      0 :::123                  :::*                                86814/ntpd

四、ntp客户端设置

1.安装ntp组件

yum install -y ntp ntpdate -y

2.修改ntp客户端配置文件

cp /etc/ntp.conf{,.bak}
vim /etc/ntp.conf

● 注释掉【#restrict default nomodify notrap nopeer noquery】

● 增加一行【restrict 10.1.1.5 nomodify notrap nopeer noquery】

● 增加一行【restrict 10.1.1.0 mask 255.255.255.0 nomodify notrap】

● 注释掉【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】

● 增加一行【server 10.1.1.5】

● 增加一行【Fudge 10.1.1.5 stratum 10】

3.重启ntpd服务、并设置开机自启

systemctl restart ntpd
systemctl enable ntpd

五、扩展

1.在客户端手工同步时间

ntpdate 10.1.1.5

2.查看服务器与上级时钟服务器通讯情况

无论ntp服务器还是客户端都可以使用

ntpq -p

-------------------END------------------2020年11月5日18:00:00---------------------------------

猜你喜欢

转载自blog.csdn.net/xoofly/article/details/109510499