ntp服务配置

芒果2年前技术文章766


安装:
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 


相关文章

scylladb集群如何添加新数据中心

1、信息收集· 收集现有集群信息cat /etc/scylla/scylla.yaml | grep cluster_namecat /etc/scylla/scylla.yaml | grep se...

MySQL 二进制安装

MySQL 二进制安装

一、前言● 介绍:业务环境安装 MySQL 一般都会通过二进制来安装,今天就记录一下业务环境二进制安装 MySQL 过程。● 环境:CentOS 7 安装:MySQL 5.7+二、安装 MySQL1....

Hue跑shell脚本报没权限问题

Hue跑shell脚本报没权限问题

1、客户反应运行脚本如下:经过排查服务器上没有workflow用户,尝试用root、admin测试正常 2、调用脚本运行失败1、给予脚本执行权限 chmod +x data-test.sh 2、/u...

聊一聊什么是分布式系统

聊一聊什么是分布式系统

分布式系统原理1 概念1.1 模型节点在具体的工程项目中,一个节点往往是一个操作系统上的进程。在本文的模型中,认为节点是一个完整的、不可分的整体,如果某个程序进程实际上由若干相对独立部分构成,则在模型...

ranger对接hbase

ranger对接hbase

前提:本文是基于集群中已经部署了ranger组件和hbase组件的情况下,增加ranger对hbase组件的对接。安装部署1、ranger-hbase插件安装使用ranger2.3版本对接插件。将插件...

数据湖技术之iceberg(七)Spark管理iceberg表

数据湖技术之iceberg(七)Spark管理iceberg表

1.SparkSQL设置catalog配置以下操作主要是SparkSQL操作Iceberg,同样Spark中支持两种Catalog的设置:hive和hadoop,Hive Catalog就是icebe...

发表评论    

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