欢迎来到站长天空!

其它服务器

当前位置: 主页 > 服务器 > 其它服务器

Linux下NTP服务器配置详细过程

时间:2025-12-25 00:30:04|栏目:其它服务器|点击:

目录
  • 一、环境配置
    • 1.NTP服务器
    • 2.业务服务器
  • 二、NTP服务器配置
    • 1.查看chrony服务状态
    • 2.启动chrony服务
    • 3.关闭防火墙和selinux
    • 4.配置NTP服务文件
    • 5.重启服务
  • 三、业务服务器配置
    • 1.开启chrony服务
    • 2.配置chrony服务文件
    • 3.重启服务
  • 四、测试业务服务器时间状态
    • 1.查看时间同步状态
    • 2.立即时间同步

一、环境配置

1.NTP服务器

NTP服务器版本:Red Hat Enterprise Linux release 8.0 (Ootpa)
NTP服务器IP:192.168.8.11/24
NTP服务器hostname:node1

2.业务服务器

NTP服务器版本:Red Hat Enterprise Linux release 8.0 (Ootpa)
NTP服务器IP:192.168.8.12/24
NTP服务器hostname:node2

二、NTP服务器配置

1.查看chrony服务状态

[root@node1 ~]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:chronyd(8)
           man:chrony.conf(5)
[root@node1 ~]# 

2.启动chrony服务

[root@node1 ~]# systemctl enable --now chronyd
Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service.

3.关闭防火墙和selinux

[root@node1 ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@node1 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@node1 ~]# setenforce 0
setenforce: SELinux is disabled
[root@node1 ~]# getenforce 
Disabled
[root@node1 ~]# 

4.配置NTP服务文件

[root@node1 ~]# vim /etc/chrony.conf 
[root@node1 ~]# cat /etc/chrony.conf |grep -Ei '(allow|local)'
# Allow the system clock to be stepped in the first three updates
# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 192.168.8.0/24
local stratum 10
[root@node1 ~]# 

5.重启服务

[root@node1 ~]# systemctl restart chronyd
[root@node1 ~]# 

三、业务服务器配置

1.开启chrony服务

[root@node2 ~]# systemctl enable --now chronyd
Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service.
[root@node2 ~]# 

2.配置chrony服务文件

[root@node2 ~]# vim /etc/chrony.conf 
[root@node2 ~]# cat /etc/chrony.conf |grep pool
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 192.168.8.11 iburst
[root@node2 ~]# 

3.重启服务

[root@node2 ~]# systemctl restart chronyd
[root@node2 ~]# 

四、测试业务服务器时间状态

1.查看时间同步状态

[root@node2 ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^? 192.168.8.12                  0   7     0     -     +0ns[   +0ns] +/-    0ns
[root@node2 ~]# 

2.立即时间同步

[root@node2 ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 192.168.8.11                 10   6    17     2   +249ns[ +141us] +/-  100us
[root@node2 ~]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \

MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 192.168.8.11                 10   6    17     8   +249ns[ +141us] +/- 1103us
[root@node2 ~]# 

上一篇:Vmware虚拟机设置固定IP地址的方法( 图文教程)

栏    目:其它服务器

下一篇:利用shadowsocks搭建局域网透明网关

本文标题:Linux下NTP服务器配置详细过程

本文地址:https://zz.feitang.co/server/33269.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2026 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号