6-从零开始搭建一台NTP服务器

1 环境

  • 操作系统
    CentOS 7.x
  • ntp版本
    ntp-4.2.6p5-29.el7.centos.2.x86_64
    ntpdate-4.2.6p5-29.el7.centos.2.x86_64

2 NTP服务器搭建

  1. 查看ntp是否已经安装
# rpm -qa | grep ntp
  1. 安装ntp
# yum install -y ntp
  1. 启动 ntp服务
  • 启动服务准备工作
    启动服务之前,应该要先进行一次时间同步。可用的公网NTP服务列表,这里使用cn.pool.ntp.org
# ntpdate cn.pool.ntp.org
 2 Jan 16:15:07 ntpdate[7644]: adjust time server 202.118.1.130 offset -0.047276 sec
  • 修改配置文件
    配置文件中各个配置项的含义,参考
# vi /etc/ntp.conf
# # 注释掉其他的时钟server
# # 添加如下几行
# server 0.cn.pool.ntp.org iburst
# # server 127.127.1.0              # local clock,需要强同步的时候,最好也注释掉
# # 配置当前ntp服务所在的层级 fudge {local_IP} stratum 10
# # stratum的值要比上一层ntp服务的stratum值+1
# fudge 127.127.1.0 stratum 10
# # 配置日志文件
# logfile /var/log/ntp.log
  • 启动ntp服务
# service ntpd start
  1. 查看ntpd进程监听的网络端口
# netstat -anp | grep   ntpd
  1. 设置iptables防火墙开放ntpd监听网络端口或清空防火墙所有规则,并保存配置。
  • 使用iptables的用户使用如下方法:
# iptables  -I   INPUT   -p    udp  --dport      123  -j    ACCEPT
# systemctl restart iptables.service
  • 使用firewall的用户使用如下方法:
# firewall-cmd --permanent --add-service=ntp
# firewall-cmd --reload
  1. 查看本地ntpd进程的同步状态
# ntpstat
synchronised to NTP server (139.199.214.202) at stratum 3
   time correct to within 41 ms
   polling server every 128 s
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容