Centos7搭建ntp服务演示
1 环境描述
服务端 | node01 | 192.168.245.101 |
---|---|---|
客户端 | node02 | 192.168.245.102 |
2 安装NTP服务
node01 & node02
yum install -y ntp
3 服务端修改配置
[root@node01 ~]# vim /etc/ntp.conf
#restrict default nomodify notrap nopeer noquery #将这条注释,添加如下两行 restrict 192.168.245.101 nomodify notrap nopeer noquery restrict 192.168.245.0 mask 255.255.252.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 #服务端IP #如果网络时间服务器不可用,以本地时间为标准想客户端提供服务 Fudge 127.127.1.0 stratum 10
4 客户端修改配置
[root@node02 ~]# vim /etc/ntp.conf
#restrict default nomodify notrap nopeer noquery #将这条注释,添加如下两行 restrict 192.168.245.102 nomodify notrap nopeer noquery restrict 192.168.245.0 mask 255.255.252.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 192.168.245.101 #服务端IP 192.168.245.101 Fudge 192.168.245.101 stratum 10
5 启动NTP服务
[root@node01 ~]# systemctl restart ntpd
[root@node02 ~]# systemctl restart ntpd
systemctl enable ntpd
查看服务状态:systemctl status ntpd
6 查看时间同步
node01(注意可能需5-10min自动进行同步)
[root@node01 ~]# ntpstat synchronised to local net at stratum 6 time correct to within 11 ms polling server every 64 s [root@node01 ~]# [root@node01 ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *LOCAL(0) .LOCL. 5 l 41 64 377 0.000 0.000 0.000
node02
[root@node02 ~]# ntpstat synchronised to NTP server (192.168.245.101) at stratum 7 time correct to within 17 ms polling server every 64 s [root@node02 ~]# [root@node02 ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *node01 LOCAL(0) 6 u 43 64 377 0.251 0.101 0.025 [root@node02 ~]#
如上ntp服务时间同步成功。