ntp服务配置

芒果2年前技术文章619


安装:
yum -y install ntp
服务命令
systemctl enable ntpd 开机启动
systemctl start ntpd 启动服务
systemctl stop ntpd 停止服务
systemctl status ntpd 查看服务状态
服务端口
cat /etc/services | grep ntp


8F727142-063A-4C2E-A8EA-3BF3DBBA6937.png

服务启动后的端口监听

netstat -anptu | grep 123

D1BF956A-5FD0-481E-9CFE-F9E0153A5E9A.png

配置文件:/etc/ntp.conf
server
配置的多个ntp服务器
本机从哪里同步时间?上游时间服务器
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 配置为时间服务器
server 172.16.121.136

#如果联不通外网,则把下面5行注释,
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
#然后添加下面两行,意思是设置成时间服务器是自己
server 127.127.1.0 fudge
127.127.1.0 stratum 8
restrict
谁可以访问?谁可以修改我的时间?
上级时间服务器能访问我,并且能修改我的时间
当我作为局域网内的时间服务器,需要给局域网内的其他机器同步时间,此时就要设置这个网段的机器能访问我,但不能修改我的时间
# 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 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 172.16.121.136        # 172.16.121.136 允许上级时间服务器访问,并修改我的时间

restrict 127.0.0.1            # 自己可以访问自己(ipv4)
restrict ::1                # 自己可以访问自己(ipv6)
restrict  172.16.121.0 mask 255.255.255.0 nomodify # 允许局域网机器访问,但不能修改我的时间
restrict  172.16.120.0 mask 255.255.255.0 nomodify # 允许局域网机器访问,但不能修改我的时间
检查同步结果
配置完重启服务:systemctl restart ntpd
执行ntpstat,检查是否与上有服务器链接时间是否自动同步(每64s 同步一次)
PS:ntpstat需要ntp服务重启后几分钟执行

2F7849B6-0F47-4F85-AA3D-9233314D65F3.png2F7849B6-0F47-4F85-AA3D-9233314D65F3.png

执行 ntpq -p,查看和上游时间服务器的连接状态
列出了所有作为时钟源校正过本地NTP服务器时钟上层NTP服务器的列表。

8CEE37B5-B9C4-4A93-8448-E7C5C67BF970.png

remote:响应这个请求的NTP服务器的名称。*表示当前选择的主服务器,+表示辅助服务器,-表示不合格的服务器,x表示服务器不可用。
refid:NTP服务器使用的上一级ntp服务器的IP地址
st:远程NTP服务器的级别。
t:本地NTP服务器与远程NTP服务器的通信方式。u:单播;b:广播;I:本地
when:上次成功请求后到现在的秒数
poll:本地NTP服务器与远程NTP服务器同步的时间间隔。
reach:这是一个八进制的值,用来测试衡量前八次查询是否成功和服务器连接。377表示都成功,0表示不成功
delay:网络延时,单位为微秒(μs)
offset:本地NTP服务器与远程NTP服务器的时间偏移,单位为毫秒(ms)。offset越接近于0,主机与NTP服务器的时间越接近
jitter:查询偏差的分布值,用于表示远程NTP的网络延时是否稳定,单位为微秒(μs)。
等待一段时间后客户端时间自动同步,这里用手动同步验证下
ntpdate -u 172.16.121.136

3DE0D254-D13A-49DF-8567-24AF66D32297.png

如果觉得自动同步时间间隔比较久,可以设定个定时任务,使用ntpdate命令来同步服务端时间
这里以每分钟同步为例
crontab -e
* * * * * /usr/sbin/ntpdate -u 172.16.121.136 &> /dev/null
debug模式,查询与服务器的时差,状态。ip是指时间服务器的ip地址
ntpdate –d ip 


相关文章

tomcat目录和配置文件介绍

一、tomcat目录说明tomcat主目录bin:命令,存放不同平台上启动或关闭的脚本BUILDING.txt&RUNNING.txt:使用文档,告诉用户如何搭建conf:各种全局配置文件,最...

开启cgroup

开启cgroup

Control groups 是 Linux 内核提供的一种可以限制、记录、隔离进程组所使用的的物理资源的机制。Cgroup 子系统:blkio、CPU、cpuacct、cpuset、devices、...

数据湖技术之iceberg(十一)Flink与Iceberg整合-DataStream API

数据湖技术之iceberg(十一)Flink与Iceberg整合-DataStream API

1.实时写入Iceberg表DataStream Api方式操作Iceberg方式目前仅支持Java Api。使用DataStream API 实时写入Iceberg表具体操作如下:2、编写代码使用D...

Ingress-Nginx 简介

Ingress-Nginx 简介

Ingress-Nginx github 地址:https://github.com/kubernetes/ingress-nginxIngress-Nginx 官方网站:https://kubern...

Redis 运维规范_运维管理规范

三、运维管理规范1、密码认证 云上 Redis 的权限控制:账号管理+白名单设置+阿里云子账号权限。对于线下 Redis 可以通过设置密码和 bind 参数文件控制访问。2、合理设置备份策略 Redi...

nginx配置反向代理某个url

nginx配置反向代理某个url

本文讲的这个漏洞 主要是为了解决漏洞扫描的问题我先介绍下这个漏洞主要是因为访问https://172.16.120.17:18090/ws/v1/cluster/info这个 yarn rest的一个...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。