设为首页 收藏本站
查看: 1251|回复: 0

[经验分享] Centos 7 ntp时间服务器搭建

[复制链接]

尚未签到

发表于 2019-2-16 12:45:51 | 显示全部楼层 |阅读模式
  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 status  ntpd.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.客户端同步时间
  ntpdate  ntp服务器IP




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-673175-1-1.html 上篇帖子: centos7搭建ngrok 下篇帖子: 安装ClamAV对centos系统进行病毒查杀
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表