Linux学习之NTP服务器

一、NTP服务器(IP:192.168.1.101)

  1. 安装:yum install -y ntp

  2. 防火墙允许:iptables -A INPUT -i $EXTIF -p udp -s 192.168.1.0/24 --dport 123 -j ACCEPT

  3. 配置:vim /etc/ntp.conf

       restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

       server前#去掉

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

        chkconfig ntpd on

  5. 观察:ntpq -p或ntpstat


二、NTP客户端

  1. 安装:yum install -y ntpdate

  2. 先手动同步:ntpdate 192.168.1.101(排错:ntpdate -d 192.168.1.101)

  3. 配置:vim /etc/ntp.conf

        server 192.168.1.101

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

        chkconfig ntpd on

  5. 写入crontab -e

    增加一行,在每天的 6 点 10 分与时间同步服务器进行同步

    10 06 * * * /usr/sbin/ntpdate ntp-server 的 ip >>/usr/local/logs/crontab/ntpdate.log


注意:

  1. 自建NTP time与外部server time不能差太多

  2. 防火墙要允许UDP port 123

  3. 需要等几分钟生效

  4. server与client间时间误差不能大于1000s

原文地址:https://www.cnblogs.com/enginex/p/6802648.html