NTP配置时间同步

NTP是用来使计算机时间同步化的一种协议


节点2(客户端)向节点1(服务器端)同步

节点1(服务器端)的配置:

vim /etc/ntp.conf

restrict 127.0.0.1
restrict -6 ::1
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap     -------------允许任何IP的客户机都可以进行时间同步
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
server  127.127.1.0     # local clock        -------------本地时间
fudge   127.127.1.0 stratum 10
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys


启动:/etc/init.d/ntpd start

停止:/etc/init.d/ntpd stop

重启:/etc/init.d/ntpd restart



节点2(客户端)配置:

vim /etc/ntp.conf

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquerya
restrict 127.0.0.1
restrict -6 ::1
server  10.162.67.108 prefer    # local clock      -------------指向这台服务器
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys  



节点2需要关闭NTP服务,否则使用ntpdate连接时会报错如下:
ntpdate[3556]: the NTP socket is in use, exiting


ntpdate 10.162.67.108       -----------向该地址同步

13 Apr 18:32:32 ntpdate[22248]: adjust time server 10.162.67.108 offset 0.017031 sec                  成功


省略不配置   //节点2在/etc/crontab
加这样一句话:
*/2 * * * * root ntpdate 10.162.67.108    ----------表示每隔2分钟在节点2以root身份执行ntpdate 10.162.67.108

重启crond服务:
[root@node2 ~]# /etc/init.d/crond restart
Stopping crond: [  OK  ]
Starting crond: [  OK  ]

观察cron的日志:/var/log

tail -f cron

Apr 13 18:24:01 OSS-4A-20 CROND[20963]: (root) CMD (ntpdate 192.168.3.201)
Apr 13 18:26:01 OSS-4A-20 CROND[21277]: (root) CMD (ntpdate 192.168.3.201)
Apr 13 18:28:01 OSS-4A-20 CROND[21624]: (root) CMD (ntpdate 192.168.3.201)

两个节点之间已实现同步





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值