美文网首页LinuxNTP
6-从零开始搭建一台NTP服务器

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

作者: Jerry_1116 | 来源:发表于2022-01-02 18:03 被阅读0次

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

相关文章

网友评论

    本文标题:6-从零开始搭建一台NTP服务器

    本文链接:https://www.haomeiwen.com/subject/uwvzqrtx.html