ntp服务配置

芒果2年前技术文章770


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


相关文章

Doris审计插件的安装

Doris审计插件的安装

插件下载地址:https://doris.apache.org/download1.安装Doris审计插件(1)解压 Audit Loader 插件步骤1. 复制插件文件cp  /opt/dtstac...

grafana7 监控https证书过期时间

grafana7 监控https证书过期时间

使用 Grafana 7 中new table visualization功能,使用Prometheus监视证书的到期日期,并使用Grafana进行展示。所有证书一目了然:证书到期之前的剩余时间,HT...

MySQL基本配置文件

MySQL基本配置文件

# 5.7  # mkdir /data/mysql57/{data,logs,run} -pv [client] port ...

chengying-4.0登入接口逆向

chengying-4.0登入接口逆向

首先是登入的加密url:http://xxxxx/api/v2/user/login参数1. username:admin@dtstack.com2. password:614bb9438210c69...

企业级大数据安全架构(四)

企业级大数据安全架构(四)

Ranger是支持审计功能的,安装时可以选择审计数据保存的位置,默认支持Solr和HDFS。HDFS的配置比较简单,这里就不赘述了,我们这里使用Ambari默认自带的Solr保存审计日志,下面部署So...

Spark调优方式

(1)资源参数调优num-executors:设置Spark作业总共要用多少个Executor进程来执行executor-memory:设置每个Executor进程的内存executor-cores:...

发表评论    

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