Centos7搭建ntp服务演示

Centos7搭建ntp服务演示

1 环境描述

服务端node01192.168.245.101
客户端node02192.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服务时间同步成功。

好的,下面是在 CentOS 7 上搭建 NTP 服务器的步骤: 1. 安装 NTP:运行以下命令安装 NTP: ``` sudo yum install ntp ``` 2. 配置 NTP:编辑 `/etc/ntp.conf` 文件,配置服务器地址和允许访问的客户端地址。例如,以下是一个示例配置: ``` server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict <客户端IP地址> mask <子网掩码> nomodify notrap ``` 其中,`server` 指定 NTP 服务器地址,`restrict` 用于限制访问控制。 3. 启动 NTP:运行以下命令启动 NTP 服务并设置为开机自启: ``` sudo systemctl start ntpd sudo systemctl enable ntpd ``` 4. 验证 NTP:使用 `ntpq` 命令验证 NTP 是否正常工作。例如,运行以下命令: ``` ntpq -p ``` 如果 NTP 正常工作,将显示类似以下内容的输出: ``` remote refid st t when poll reach delay offset jitter ============================================================================== *ntp1.example.c .GPS. 1 u 154 256 377 0.862 -30.200 1.835 +ntp2.example.c .PPS. 1 u 173 256 377 0.991 -30.230 1.309 -ntp3.example.c .GPS. 1 u 130 256 377 1.003 -29.990 1.935 ``` 其中,`*` 表示当前服务器为 NTP服务器,`+` 表示当前服务器为 NTP 辅助服务器,`-` 表示当前服务器为 NTP 被动服务器。 以上就是在 CentOS 7 上搭建 NTP 服务器的步骤。希望能对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值