百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 编程文章 > 正文

CentOS - 时间同步服务ntp 时间同步服务器地址

qiyuwang 2024-11-03 16:31 10 浏览 0 评论

简介

在一些集群服务中,不同的主机时间不一致,会导致服务异常。因此都会使用ntp(Network Time Protocol)进行时间同步。

操作系统

CentOS Linux release 7.6.1810 (Core)

安装

yum -y install ntp 

配置

默认配置会,同步外网的ntp时间服务。

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
#系统时间与BIOS事件的偏差记录
driftfile /var/lib/ntp/drift 
# 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 控制相关权限。
#语法为: restrict IP地址 mask 子网掩码 参数
#其中IP地址也可以是default ,default 就是指所有的IP
#参数有以下几个:
#ignore :关闭所有的 NTP 联机服务
#nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
#notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
#noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器
#notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
#nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
#kod : 访问违规时发送 KoD 包。
#restrict -6 表示IPV6地址的权限设置。
#对本机不做限制,拥有所有的权限
restrict 127.0.0.1 
restrict ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#设置默认策略为允许任何主机进行时间同步
restrict default ignore
#此处表示限制向从192.168.1.1-192.168.1.254这些IP段的服务器提供NTP服务。
#restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap noquery
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#设定NTP主机来源(其中prefer表示优先主机),192.168.1.123是本地的NTP服务器,所以优先指定从该主机同步时间。
server 192.168.1.123 prefer 
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
#broadcast 192.168.1.255 autokey	# broadcast server
#broadcastclient			# broadcast client
#broadcast 224.0.1.1 autokey		# multicast server
#multicastclient 224.0.1.1		# multicast client
#manycastserver 239.255.254.254		# manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

服务启动时,同步的时间服务器

修改/etc/ntp/stpe-tickers文件

server 192.168.1.123 
server 0.centos.pool.ntp.org 
server 1.centos.pool.ntp.org 
server 2.centos.pool.ntp.org 
server 3.centos.pool.ntp.org 

配置硬件时间同步

ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件,在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样,就可以让硬件时间与系统时间一起同步。

#允许BIOS与系统时间同步,也可以通过hwclock -w 命令

SYNC_HWCLOCK=yes

启动服务

systemctl start ntpd 

查看ntp服务器有无和上层ntp连通

ntpstat

synchronised to NTP server (120.25.115.20) at stratum 3

time correct to within 85 ms

polling server every 64 s

查看ntp服务器与上层ntp的状态

ntpq -p

remote refid st t when poll reach delay offset jitter

==============================================================================

*120.25.115.20 10.137.53.7 2 u 39 64 7 34.227 -1.895 5.605

amy.chl.la .INIT. 16 u - 64 0 0.000 0.000 0.000

+xk-6-95-a8.bta. 10.41.14.199 2 u 36 64 7 38.472 1.974 1.703

ntp7.flashdance .INIT. 16 u - 64 0 0.000 0.000 0.000

remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先

refid - 参考上一层ntp主机地址

st - stratum阶层

when - 多少秒前曾经同步过时间

poll - 下次更新在多少秒后

reach - 已经向上层ntp服务器要求更新的次数

delay - 网络延迟

offset - 时间补偿

jitter - 系统时间与bios时间差


总结

时间同步服务,是一个很简单的服务。

相关推荐

windows开启telnet服务,检测远程服务端口是否可以连通

本文介绍windwos开启telnet服务,telnet服务一般可以用于检测远程主机的某个端口服务是否可以连通,在日常的工作中,我们经常会遇到在本地的windows检测远程服务端口是否可以连通。win...

仅在Web登录新华三交换机条件下启用设备Telnet登录方式

概述Web登录新华三交换机可以在“网络-服务”页面中启用设备Telnet服务或SSH服务,也可以在“设备-管理员”设置管理员用户的可用服务,然而,在设备Web页面中,无法设置lineVTY用户线【l...

思科交换机,路由器如何关闭telnet 开启ssh服务

SSH为建立在应用层基础上的安全协议。SSH是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用SSH协议可以有效防止远程管理过程中的信息泄露问题。今天我们就来说说思科交换机,路...

智能化弱电行业常用的DOS命令,掌握了你也能成为...

前言在做智能化弱电项目时,前端摄像头设备安装结束后,我们会对网络摄像头进行调试,调试过程中会遇到前端摄像头没有图像或者图像出来了画面卡顿的现象。我们会采用ping命令来测试网络的连通性和网络承载能力。...

「干货」eNSP模拟器之配置Telnet登录

配置说明:配置Telnet,使R2(模拟PC)通过SW1登录到R1进行管理和配置。操作步骤:system-view##进入系统视图[Huawei]sysnameR1##改名为R1[R1]int...

win11开启telnet服务怎么操作 win11打开telent指令是什么

telnet服务是我们在进行远程连接的时候,必须要打开的一项功能。但是有不少用户们不清楚在windows11系统中怎么开启telnet服务。今天小编就使用详细的图文教程,来给大家说明一下打开telen...

华三(H3C)交换机Telnet的远程登陆

一,配置交换机管理IP[SW1]vlan20//创建管理vlan[SW1]interfacevlan20//进入vlan接口[SW1-Vlanif20]ipaddress192.168....

win10 telnet命令怎么查看端口是否打开

可能大家也会遇到这个问题,win10telnet命令查看端口是否打开的步骤是什么?具体方法如下:1、键盘输入快捷键WIN+R,打开运行窗口。2、输入cmd,点击确定按钮。3、弹出cmd命令行窗...

Windows 7如何打开Telnet功能(win7系统打开telnet)

Windows7默认安装后是没有开启telnet客户端功能的,例如,我们在开始菜单中输入cmd,然后使用telnet命令,会弹出下图提示:‘telnet’不是内部或外部命令,也不是可运行程序或批处理文...

为锐捷路由器交换机开启web和telnet,实现轻松管理

笔者上一篇文章写了关于锐捷二层交换机配置教程,那么接下来讲一下锐捷的路由交换设备配置web、telnet技巧。同样,今天的教程也是基于命令行,比较简单,适合新手小白进行学习。准备工作配置前准备:con...

一文学会telnet命令的用途和使用方法

Telnet是一个古老的远程登录协议,可以让本地计算机获得远程计算机的工作能力。它采用了TCP的可靠连接方式,可以连接任何网络互通的远程计算机。不过由于它采用了明文传输方式,存在安全风险,目前已经很少...

Telnet命令是什么?如何使用?(telnet命令在哪里开启)

telnet命令是一个常用的远程登陆工具,使用它,我们可以快捷地登陆远程服务器进行操作。那么如何使用telnet命令呢?首先,我们需要打开telnet功能,任何电脑默认是关闭此功能的,开启方式如下:打...

win11系统如何开启telnet服务(拷贝版本)

  我们要知道,Telnet协议是Internet远程登陆服务的标准协议,可以使用户在本地计算机上完成远程主机的工作,不过对于一些刚接触win11中文版系统的用户来说,可能还不知道telnet服务在哪...

如何开启telnet客户端(如何开启telnet服务)

Telnet协议是TCP/IP协议家族中的一员,是Internet远程登陆服务的标准协议和主要方式,Telnet是常用的远程控制Web服务器的方法。工作中经常用到telnet客户端,但在windows...

Telnet 是什么,如何启用它?(telnet有什么用)

对于Internet等TCP/IP网络,Telnet是一个终端仿真程序。Telnet软件在您的系统上运行并将您的个人计算机链接到网络服务器。它将所有数据转换为纯文本这一事实被认为是易受...

取消回复欢迎 发表评论: