centos7搭建ntp服务

148 篇文章 2 订阅

很多应用服务需要时间同步,这时候可以设置一台ntp服务器,其他客户端连接这台服务器就行。

客户端 client A:192.168.1.9   服务端B:192.168.1.7

1、安装ntp服务(操作机器AB)

[root@bvm ~]# yum install ntp -y
[root@node1 ~]# systemctl start ntpd
[root@node1 ~]# systemctl enable ntpd

2、服务端B: 192.168.1.7修改配置文件/etc/ntp.conf

添加

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap #允许内网其他机器同步时间

3、客户端A:192.168.1.9修改配置文件/etc/ntp.conf

注释掉默认的server 0-3

添加

server 192.168.1.7
restrict 192.168.1.7nomodify notrap noquery
fudge 127.127.1.0 stratum 8

#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.1.7
restrict 192.168.1.7 nomodify notrap noquery
fudge 127.127.1.0 stratum 8

查看 ntp 同步情况

[root@bvm ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.1.7     5.103.139.163    2 u   34   64  377    0.194   15.762  17.033

4、客户端同步(操作机器A)

①手动ntpdate同步:ntpdate -u 192.168.1.7 (慎用,ntpdate 会立刻同步时间,对一些服务会造成影响)

然后crontab -e 设置定时即可实现自动同步

[root@bvm ~]# ntpdate -u 192.168.1.7
28 Dec 20:27:06 ntpdate[7170]: adjust time server 192.168.1.7 offset 0.027655 sec

如果使用ntpdate 192.168.1.7会报错,因为客户端也开启了ntpd服务,需要关掉ntpd,systemctl stop ntpd。

[root@bvm ~]# ntpdate  192.168.1.7
28 Dec 20:27:16 ntpdate[7171]: the NTP socket is in use, exiting

②查看 ntp 有无和上层 ntp 同步:ntpstat

[root@bvm ~]# ntpstat
unsynchronised
   polling server every 64 s

显示unsynchronised,需要等待15分钟左右

[root@bvm ~]# ntpstat
synchronised to NTP server (192.168.1.7) at stratum 3
   time correct to within 208 ms
   polling server every 64 s

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值