Linux ntp服务配置

基本每个系统都有要求NTP对时,简单记录一下。

  • 安装ntp服务


    yum install -y ntp
    chkconfig ntpd on
  • 配置/etc/ntpd.conf文件。

    #
    vi /etc/ntpd.conf
    #放行局域网来源 :restrict [你的IP] mask [mask_ip] [parameter],nomodify 表明客户端不可以修改服务器的地址
    restrict 192.168.0.0 mask 255.255.0.0 nomodify
    #设置NTP server上层服务器,可以使用默认,如网络不好注释后换下面的
    server time.nist.gov
  • 配置防火墙

    #
    /sbin/iptables -I INPUT -p udp --dport 123 -j ACCEPT
    /etc/rc.d/init.d/iptables save
    service iptables status
  • 重启ntp服务


    ntpd restart
  • 手动更新
    NTP服务启动后大约需要3~5分钟的时间才会进行一次时间同步。可以通过命令ntpstat查看同步情况,


    service ntpd stop
    ntpdate time.nist.gov
    ntpstat

NTP客户端配置

  • 安装ntp服务


    yum install ntp
    chkconfig ntpd on
  • 查询可用NTP服务端

  • 配置/etc/ntpd.conf文件

    #
    vi/etc/ntp.conf
    #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.178.102.249
  • 重启ntp服务


    ntpd restart
  • 检查对时状态


    ntpstat
    ntpq -p
    ntpq -c peers
    ntpq -c assoc

原文:大专栏  Linux ntp服务配置


猜你喜欢

转载自www.cnblogs.com/petewell/p/11601526.html