NTP配置时间同步

    xiaoxiao2021-04-13  28

    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)

    两个节点之间已实现同步

    转载请注明原文地址: https://ju.6miu.com/read-669140.html

    最新回复(0)