linux同步两台服务器时间,同步两台linux服务器时间同步方案

[root@node1 ~]clock -w

[root@node1 ~]hwclock –systohc

后两个命令是把设置的时间写到硬件时间中去(也就是CMOS里面的时间)。

第二步,

然后将node1配置成一个time server,修改/etc/ntp.conf,

[root@node1 ~]vi /etc/ntp.conf

其他的配置不怎么需要改,只需要关注restrict的配置:

1. 注释掉下面两行,本身是不响应任何的ntp更新请求,其实也就是禁用了本机的ntp server的功能,所以需要注释掉。

#restrict default kod nomodify notrap nopeer noquery

#restrict -6 default kod nomodify notrap nopeer noquery

2. 加入:restrict 192.168.1.0 mask 255.255.255.0 — 让192.168.1.0/24网段上的机器能和本机做时间同步

如果有多个网段则顺次加入即可.

3. 这样就可以了,记得加入下面的:

server 127.127.1.0 # local clock

fudge 127.127.1.0 stratum 10

这两行需要,这是让本机的ntpd和本地硬件时间同步。

当然,我们也可以添加server xxx.xxx.xxx.xxx,让他和其他的time server时间同步。

4. /etc/init.d/ntpd restart

5. chkconfig ntpd on

6. 修改iptables配置,将tcp和udp 123端口开放,这是ntp需要的端口,在/etc/services中可以查到这个端口。

第三步,

这样node1就成为一台time server了,现在我们配置node2这台机器

关闭ntp服务 service ntpd stop

执行: ntpdate  192.168.1.101 即可手工同步!

    原文作者:小枣君
    原文地址: https://blog.csdn.net/weixin_29734123/article/details/116762523
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞