冰恋 发表于 2019-2-16 12:45:51

Centos 7 ntp时间服务器搭建

  1.查看是否已安装ntp
  rpm -qa | grep ntp
  ntp-4.2.6p5-22.el7.centos.2.x86_64
  ntpdate-4.2.6p5-22.el7.centos.2.x86_64
  如果有上述内容输出,测说明ntp服务已安装;否则需要安装ntp服务
  关闭selinux并开放防火墙配置
  sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
  setenforce 0
  firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --in-interface ens160 --destination 224.0.0.18--protocol vrrp -j ACCEPT
  firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 --out-interface ens160 --destination 224.0.0.18--protocol vrrp -j ACCEPT
  firewll-cmd --reload
  firewall-cmd --reload
  2.安装ntp
  yum -y install ntp
  3.配置ntp
  vi/etc/ntp.conf
  # For more information about this file, see the man pages
  # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
  driftfile /var/lib/ntp/drift
  # Permit time synchronization with our time source, but do not
  # permit the source to query or modify the service on this system.
  restrict default nomodify notrap nopeer noquery
  # Permit all access over the loopback interface.This could
  # be tightened as well, but to do so would effect some of
  # the administrative functions.
  restrict 127.0.0.1
  restrict ::1
  # Hosts on local network are less restricted.
  #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
  restrict 10.10.1.0 mask 255.255.255.0 nomodify notrap #允许特定网段能同步时间
  # Use public servers from the pool.ntp.org project.
  # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  #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 1.cn.pool.ntp.org
  server 0.asia.pool.ntp.org
  server 2.asia.pool.ntp.org
  server 127.0.0.1
  fudge 127.127.1.0 stratum 5
  #broadcast 192.168.1.255 autokey      # broadcast server
  #broadcastclient                        # broadcast client
  #broadcast 224.0.1.1 autokey            # multicast server
  #multicastclient 224.0.1.1            # multicast client
  #manycastserver 239.255.254.254         # manycast server
  #manycastclient 239.255.254.254 autokey # manycast client
  restrict 1.cn.pool.ntp.org nomodify notrap noquery
  restrict 0.asia.pool.ntp.org nomodify notrap noquery
  restrict 2.asia.pool.ntp.org nomodify notrap noquery
  # Enable public key cryptography.
  #crypto
  includefile /etc/ntp/crypto/pw
  # Key file containing the keys and key identifiers used when operating
  # with symmetric key cryptography.
  keys /etc/ntp/keys
  # Specify the key identifiers which are trusted.
  #trustedkey 4 8 42
  # Specify the key identifier to use with the ntpdc utility.
  #requestkey 8
  # Specify the key identifier to use with the ntpq utility.
  #controlkey 8
  # Enable writing of statistics records.
  #statistics clockstats cryptostats loopstats peerstats
  # Disable the monitoring facility to prevent amplification attacks using ntpdc
  # monlist command when default restrict does not include the noquery flag. See
  # CVE-2013-5211 for more details.
  # Note: Monitoring will not be disabled with the limited restriction flag.
  disable monitor
  ####restrict参数####
  #kod 使用kod技术防范“kiss of death”***
  #ignore 拒绝任何NTP连接
  #nomodify 用户端不能使用ntpc,ntpq修改时间服务器参数,但是可以进行网络校时
  #noquery 用户端不能使用ntpc,ntpq查询时间服务器参数,不可以进行网络校时
  #notrap 不提供远程日志功能
  #notrust 拒绝没有认证的客户端
  server 127.0.0.1
  fudge 127.127.1.0 stratum 5
  #设置本地时间级别是5,如果上级时间服务器均失效,对外发布本地时间,时间层级是4。
  #这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0
  3.启动ntp服务
  systemctl start ntpd.service
  4.查看ntp运行状态
  systemctl statusntpd.service
  5.查看ntp服务器端同步状态
  ntpq -p   显示参数解析
  *
  响应的NTP服务器和最精确的服务器
  +
  响应这个查询请求的NTP服务器
  blank(空格)
  没有响应的NTP服务器
  标题
  remote
  响应这个请求的NTP服务器的名称
  refid
  NTP服务器使用的更高一级服务器的名称
  st
  正在响应请求的NTP服务器的级别
  when
  上一次成功请求之后到现在的秒数
  poll
  本地和远程服务器多少时间进行一次同步,单位秒,在一开始运行NTP的时候这个poll值会比较小,服务器同步的频率大,可以尽快调整到正确的时间范围,之后poll值会逐渐增大,同步的频率也就会相应减小
  reach
  用来测试能否和服务器连接,是一个八进制值,每成功连接一次它的值就会增加
  delay
  从本地机发送同步要求到ntp服务器的往返时间
  offset
  主机通过NTP时钟同步与所同步时间源的时间偏移量,单位为毫秒,offset越接近于0,主机和ntp服务器的时间越接近
  jitter
  统计了在特定个连续的连接数里offset的分布情况。简单地说这个数值的绝对值越小,主机的时间就越精确
  ntpstat显示如下表示同步成功
  synchronised to NTP server (203.135.184.123) at stratum 2
  time correct to within 189 ms
  polling server every 128 s
  在ntp服务重启后需要一段时间来和上层时间服务器同步,这个过程可能需要5分钟。初始同步时间会较长请耐心等待。。。
  6.客户端同步时间
  ntpdatentp服务器IP



页: [1]
查看完整版本: Centos 7 ntp时间服务器搭建