ntp服务配置

芒果2年前技术文章761


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


相关文章

Yarn调度器对比

1)Hadoop调度器重要分为三类:FIFO 、Capacity Scheduler(容量调度器)和Fair Sceduler(公平调度器)。Apache默认的资源调度器是容量调度器;CDH...

python脚本--检查域名证书到期时间

需要的依赖:pip install python-dateutil pip install pytzpython脚本内容:#!/usr/bin/env python3      import s...

MySQL运维实战之备份和恢复(8.1)xtrabackup全量备份

xtrabackup是percona开源的mysql物理备份工具。xtrabackup 8.0支持mysql 8.0版本的备份和恢复。xtrabackup 2.4支持mysql 5.7及以下版本的备份...

Zabbix监控接入

Zabbix监控1、环境实验机器:118.31.158.83(zabbix server)172.17.6.11(zabbix proxy)172.17.6.11(zabbix agent)2、安装z...

apache Kyuubi部署及对接hive

apache Kyuubi部署及对接hive

1、背景客户重度使用spark sql,但是使用spark thriftserver存在各种各样的问题,我们选择使用kyuubi来替代spark thriftserver的使用2、安装包下载下载地址:...

开源大数据集群部署(五)Freeipa客户端部署及配置(kerberos+ldap)

开源大数据集群部署(五)Freeipa客户端部署及配置(kerberos+ldap)

1、安装IPA-Client安装(每个节点均需安装)yum install ipa-client -y2、执行安装命令ipa-client-install3、执行完成后进入交互阶段4、安装完成后查看页...

发表评论    

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