2021-09-26 NTP时间服务

本文介绍了NTP服务在Linux系统中的应用,重点讲解了chronyd时间同步服务器的安装、配置及管理。内容包括chrony.conf配置文件的编辑,如设置时间源、网络策略,以及如何通过chronyc命令查看时间同步状态。同时,也讨论了ntp服务的配置,如限制访问策略、设置日志和driftfile。最后,提到了ntpdate命令用于手动同步时间,并阐述了系统时间与硬件时间之间的关系和管理。
摘要由CSDN通过智能技术生成

NTP服务解析:
chronyd 开源时间同步服务器:
安装包:
chrony
1、定义:
chrony 是网络时间协议(NTP)的通用软件,使用 UDP 323 端口通信,根据 chrony.conf 文件的不同配置分成服务端和客户端。

2、配置:

vi /etc/chrony.conf
server 1.1.1.1 iburst

allow 192.168.0.0/16

local stratum 10

重启服务:
systemctl restart chronyd
查看时间同步:
chronyc sources -v

客户端设置:
vi /etc/chrony.conf
server 192.168.200.3 iburst

其他查看命令:
chronyc sources ;
chronyc tracking ;
chronyc sources -v ;
查看时间源状态:
chronyc sourcestats -v
查看时间源是否在线:
chronyc activity -v ;
3、网络策略:
chrony 使用323 udp 端口 , 需要防火墙提前开通;

chronyc -a makestep 手动同步时钟

时间命令:
timedatectl 命令;

ntp时间服务同步:

yum install -y ntp 服务端,客户端;
使用端口 udp 123
ntp 平滑同步;
ntpdate 立即同步;

服务端配置, /etc/ntp.conf

记录和上级时间服务器的时间差异

driftfile /var/lib/ntp/drift

ntp 日志

logfile /var/log/ntp.log

日志级别 all event info

logconfig all

设置默认策略,允许同步时间,不允许修改

restrict default nomodify notrap nopeer noquery

允许本机地址的一切操作,-6 为 IPV6

restrict 127.0.0.1
restrict -6 ::1

允许网段内客户端连接此服务器同步时间,但是拒绝让他们修改服务器上的时间

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

https://www.ntppool.org/zone/cn

利用 server 设定上层 NTP 服务器,可设置多个。prefer 表示优先

server s1b.time.edu.cn prefer

在 /ntp.conf 中定义的 server 都不可用时,将使用 local 时间作为 ntp 服务提供给 ntp 客户端。建议配置,否则 ntp 服务器无法与公网 ntp 服务器同步时,其客户端也会无法同步

server 127.127.1.0
fudge 127.127.1.0 stratum 10

主要配置:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server 1.1.1.1

3、重启ntp服务:
systemctl restart ntp

4、常用命令:
上层 ntp 的状态
ntpq -p

ntp 同步状态

ntpstat

向 NTP 服务器同步时间,需关闭 ntpd 服务,-u 指定使用无特权的端口发送数据包 -d 调试

ntpdate -u s1a.time.edu.cn
ntpdate -d 1.1.1.1

系统时间与硬件时间:
hwclock -w 设置硬件时间,系统时间写入硬件时间;
hwclock -s 设置系统时间,硬件时间写入系统时间。

增加定时任务,单次同步时间:
0 12 * * * ntpdate 1.1.1.1 && hwclock -w

时钟的跃变,可能对程序造成严重问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值