Linux中配置ntp服务

NTP:是Network Time Protocol的缩写又 称网络时间协议,是用来使计算机时间同步化的一种协议,用来同步网络中各主机的时 间,在linux系统中早期使用ntp来实现,后来使用chrony来实现。Chrony 应用本身已经有 几年了,是网络时间协议的 (NTP) 的另一种实现。

一、安装ntp服务

1、首先检查系统中是否安装ntp包:rpm -q ntp

2、执行命令在线安装ntp:yum -y install ntp

3、现在设置开机自启动:systemctl enable ntpd

二、配置ntp服务

时间服务器配置: vim /etc/ntp.conf

在文本中添加(/!!!前为要添加的内容)

java 复制代码
# For more information about this file, see the ntp.conf(5) man page.

# Record the frequency of the system clock.
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 noepeer noquery

# Permit association with pool servers.
restrict source nomodify notrap noepeer 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 192.168.29.28 nomodify notrap nopeer noquery //!!!
restrict 127.0.0.1
restrict ::1

# Hosts on local network are less restricted.
restrict 192.168.1.2 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).
# pool 2.openEuler.pool.ntp.org iburst
server 127.127.1.0 //!!!
Fudge 127.127.1.0 stratum 10 //!!!

# Reduce the maximum number of servers used from the pool.
tos maxclock 5

# Enable public key cryptography.
# crypto
1)启动ntp服务

service ntpd start

systemctl restart ntpd.service

2)通过命令timedatectl查看,ntp服务是否生效

(若NTP enabled: no,执行命令timedatectl set-ntp yes)

3)查看ntp服务器有无和上层ntp连通
4)查看ntp服务器与上层ntp的状态
相关推荐
WJ.Polar4 分钟前
Ansible任务控制
linux·运维·网络·python·ansible
计算机安禾18 分钟前
【Linux从入门到精通】第10篇:软件包管理——Linux如何安装与卸载软件
java·linux·运维·服务器·编辑器
zzzyyy53820 分钟前
Linux进程控制(2)
linux·服务器
热爱Liunx的丘丘人20 分钟前
PlayBook常用的模块编写
linux·服务器·ansible
wellc21 分钟前
Nginx作用以及应用场景
运维·nginx
SilentSamsara22 分钟前
etcd 运维:数据一致性、备份恢复与性能调优
运维·服务器·数据库·kubernetes·kubectl·k8s·etcd
lclcooky25 分钟前
Nginx代理到https地址忽略证书验证配置
运维·nginx·https
前端达人28 分钟前
第12课:MCP 与 Hooks——给 Claude Code 装上插件和自动化引擎
运维·自动化
RH23121136 分钟前
2026.4.21Linux 共享内存
linux·服务器·网络
wanhengidc39 分钟前
云主机的核心原理与架构
运维·服务器·科技·游戏·智能手机·架构