ntp服务配置

芒果3年前技术文章852


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


相关文章

cattle-cluster-agent产生的僵尸进程处理

cattle-cluster-agent产生的僵尸进程处理

现象zabbix告警服务器存在僵尸进程排查步骤1、登陆服务器使用top命令,确认下僵尸进程数量。2、使用ps -aux | grep Z命令,过滤出僵尸进程PID。3、根据查到的PID,借助ps命令,...

谈谈K8S Pod Eviction 机制

Pod Eviction 简介Pod Eviction 是k8s一个特色功能,它在某些场景下应用,如节点NotReady、Node节点资源不足,把pod驱逐至其它Node节点。从发起模块的角度,pod...

REPMGR-PG高可用搭建(三)

REPMGR-PG高可用搭建(三)

2.2.2repmgr安装兼容性3节点均安装repmgr1.安装依赖 # yum install flex 2.下载解压 # wget -c https://repmgr.org/downloa...

Prometheus监控Minio集群

Prometheus监控Minio集群

一、概述Minio支持集成prometheus,用以监控CPU、硬盘、网络等数据。二、修改docker-compose.yaml官方的给docker-compose.yaml,默认是不能访问metri...

Impala 操作命令

Impala 操作命令

Impala的外部shell选项描述-h, --help显示帮助信息-v or --version显示版本信息-i hostname, --impalad=hostname 指定连接运行 impala...

yarn常用命令

1、yarn application 查看任务1.1 列出所有 Application: yarn application -list1.2 根据 Application 状态过滤:yarn appl...

发表评论    

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