ntp服务器不起作用

2020-10-26 18:44发布

服务器挂起以后,过段时间重新运行,时间还是挂起时的时间,ntp服务器没有同步网络时间,每次都需要重启ntp服务器才可以,怎么解决

服务器挂起以后,过段时间重新运行,时间还是挂起时的时间,ntp服务器没有同步网络时间,每次都需要重启ntp服务器才可以,怎么解决

3条回答
何大侠
2楼 · 2020-10-26 20:12

NTP全称是Network Time Protocol,也就是互联网时间协议,说到时间,就谈谈时间的一些概念吧;

  • 时区

  • 按照常识来说,一天被划分24小时,近似球体的地球是360度,所以使用经纬度为坐标,将全球划分为24个时区,每个时区是15度;

  • 东八区

  • 格林尼治时间为世界标准时间,又因为,东半球(格林尼治以东)的时间比较早,中国的经度在120E,是位于第八个时区,这里的中国表示北京或者上海,因为横跨的时区不止一个;

  • UTC

  • Coordinated Universal Time表示协调通用时间,根据原子振荡周期所计算的物理时钟,这种计算方式对于时间的计算误差时很小的;

  • GMT

  • Greenwich Mean Time表示的是格林尼治时间,是根据地球的自转周期计算的标准时间,由于各种不稳定因素的影响,计时不是很理想;

  • 软件时钟

  • 表示的是LInux[这里指提Linux]操作系统从1970/01/01开始计算的秒数;

  • 硬件时钟

  • 主机硬件上面的时钟,主要是BIOS内部时间的记录了;

  • 时间校对的几个步骤

    • 1.server端启动daemon;

    • 2.Clientserver发送校对时间的报文;

    • 3.NTP server返回当前的标准时间给Client;

    • 4.Client根据返回的时间校对自己当前的系统时间;

  • 关于NTP服务相关的配置文件


无需指教
3楼 · 2020-10-27 08:12

NTP全称是Network Time Protocol,也就是互联网时间协议,说到时间,就谈谈时间的一些概念吧;

  • 时区

  • 按照常识来说,一天被划分24小时,近似球体的地球是360度,所以使用经纬度为坐标,将全球划分为24个时区,每个时区是15度;

  • 东八区

  • 格林尼治时间为世界标准时间,又因为,东半球(格林尼治以东)的时间比较早,中国的经度在120E,是位于第八个时区,这里的中国表示北京或者上海,因为横跨的时区不止一个;

  • UTC

  • Coordinated Universal Time表示协调通用时间,根据原子振荡周期所计算的物理时钟,这种计算方式对于时间的计算误差时很小的;

  • GMT

  • Greenwich Mean Time表示的是格林尼治时间,是根据地球的自转周期计算的标准时间,由于各种不稳定因素的影响,计时不是很理想;

  • 软件时钟

  • 表示的是LInux[这里指提Linux]操作系统从1970/01/01开始计算的秒数;

  • 硬件时钟

  • 主机硬件上面的时钟,主要是BIOS内部时间的记录了;

  • 时间校对的几个步骤

    • 1.server端启动daemon;

    • 2.Clientserver发送校对时间的报文;

    • 3.NTP server返回当前的标准时间给Client;

    • 4.Client根据返回的时间校对自己当前的系统时间;

  • 关于NTP服务相关的配置文件

/etc/ntp.conf //表示NTP服务的主要配置文件,也是为一个的配置文件/usr/share/zoneinfo/ //表示对应的各个时区的文件/etc/sysconfig/clock 
 //表示用于设置时钟和是否使用UTC的配置文件/etc/localtime //用于复制/usr/share/zoneinfo/里面对应的,/etc/sysconfig/clock里面设定的时区文件,作为当前系统使用的本地时间配置文件;12345678
  • 关于时间的几个命令

/bin/date 
    //Linux软件时钟的修改和查看/sbin/hwclock //用于硬件时钟的修改和显示,如果修改了软件时钟需要使用这个方式同步到硬件时钟上面;/usr/sbin/ntpd //NTP服务的主要程序,配置文件为/etc/ntp.conf/usr/sbin/ntpdate 
 //用于实现Client时间的校正12345678
  • 关于/etc/ntp.conf配置文件

利用restrict来实现权限控制
restrict [IP] [mask] [netmask_IP] [patameter]patameter支持的参数:
    igonre:拒绝所有类型的`NTP`连接
    nomodify:Client不能够使用命令ntpc以及ntpdq来修改修改服务器的时间参数,但是可以进行网络校时;
    noquery:表示不提供NTP网络校时;
    notrap:表示不提供远程事件登陆的功能;
    notrust:表示不接受没有认证的Clent;
    如果没有任何参数,表示不接受任何的限制;
server [IP or hostname] [prefer]
    用于设置上层提供NTP服务的服务器;
    prefer:表示优先使用
driftfile [可以被ntpd写入的进程或者文件]
    NTP Server计算时间是通过本机的时钟振荡来记录的,这个时间和上层Time Server的时钟振荡频率不一定是一致的,需要将这个振荡差异记录下来;1234567891011121314
  • NTP服务的规划

    rhel7.2作为提供时间同步服务的主机172.25.23.250
    rhel6.5作为某个集群中的节点,进行时间同步,这里选择server21.com

  • 需要注意的几点:

    • 1.自己配置的NTP是需要设置上层服务器来进行时间同步的,172.25.23.250主机通过另一块网卡可以上网,使用的上层主机是cn.ntp.org.cn ;

    • 2.NTP服务器和上层NTP服务的时间不能够相差太多;

    • 3.对于防火墙的设置,一定需要允许123/UDP端口;

    • 4.防火墙还需要放行时间同步请求的网段;

  • 首先安装ntp服务的软件包,这里使用Yum配置安装

[root@my Desktop]# yum install ntp -y [root@my Desktop]# rpm -q ntpntp-4.2.6p5-22.el7.x86_64123
  • 然后根据上面的提示修改配置文件/etc/ntp.conf

# 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).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 127.0.0.1 restrict ::1restrict  cn.ntp.org.cn# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notraprestrict 172.25.23.0 mask 255.255.255.0 nomodify notrap 

# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).#server 0.rhel.pool.ntp.org iburst#server 1.rhel.pool.ntp.org iburst#server 2.rhel.pool.ntp.org iburst#server 3.rhel.pool.ntp.org iburst#server cn.ntp.org.cn prefer#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.#cryptoincludefile /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 monitor1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  • 然后启动或者重新启动服务

[root@my Desktop]# !systemcsystemctl start ntpd12
  • 确保端口已经启动
    这里写图片描述

  • 使用命令ntpstat查看NTP服务器的状态

[root@my Desktop]# ntpstat synchronised to NTP server (202.108.6.95) at stratum 3 
   time correct to within 106 ms
   polling server every 64 s1234
  • 或者使用ntpq -p来查看NTP服务器时间同步的过程

[root@my Desktop]# ntpq -p     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================*xk-6-95-a8.bta. 10.69.2.34       2 u   35   64  377   28.381  -30.163  17.4391234
  • 解释上述几个子段的作用

    • *:表示目前正在作用当中的上层NTP服务器;

    • +:表示已经连接成功,并且可以作为下一个提供时间更新的候选者;

    • remote :表示NTP主机的IP或者是主机名,最左边的

    • refid:表示参考的上一层NTP主机的地址;

    • st:表示的含义是startnum,一般范围是从0-->15;

    • when:表示几秒前做过时间同步化更新操作;

    • poll:表示下一次更新在几秒钟之后;

    • reach:表示已经向上一层服务器要求更新的次数;

    • delay: 表示数据在传输过程中延迟的时间;

    • offset:表示时间补偿的结果;

    • jitter:Linux系统时间和BIOS硬件时间的差异;

  • Client仅仅需要使用简单的命令就可以完成时间和NTP的同步操作

[root@server20 ~]# ntpdate 172.25.23.25010 Mar 15:49:08 ntpdate[13911]: adjust time server 172.25.23.250 offset -0.049370 sec12

这里写图片描述

  • 关于NTP服务器配置过程中出现额的几个错误,以及解决额的办法

  • 和上层NTP服务器不能够正常通信;

[root@server21 ~]# ntpstat -punsynchronised
  time server re-starting
   polling server every 8 s1234
  • 上面这个错误出现的原因是没有设置上层服务器,导致和上述NTP服务器的同步没有办法完成,或者是因为上层服务器设置错误;

  • 解决,这里使用的上层服务器是cn.ntp.org.cn, 可以使用联网主机测试和上层时间同步服务器的连接是否正常

[root@my Desktop]# ntpdate cn.ntp.org.cn 10 Mar 15:55:08 ntpdate[8952]: adjust time server 202.112.29.82 offset -0.003693 sec12
  • 出现的错误

[root@server20 ~]# ntpdate 172.25.23.250
 9 Mar 10:46:17 ntpdate[1129]: no server suitable for synchronization found12
  • 对于上述出现的错误,使用-d选项来查看相信的出错信息

[root@server20 ~]# ntpdate -d 172.25.23.2110 Mar 15:56:52 ntpdate[13913]: ntpdate 4.2.6p5@1.2349-o Mon Jul 15 09:22:50 UTC 2013 (1)
Looking for host 172.25.23.21 and service ntp
host found : server21.com
transmit(172.25.23.21)
transmit(172.25.23.21)
transmit(172.25.23.21)
transmit(172.25.23.21)
transmit(172.25.23.21)172.25.23.21: Server dropped: no data
server 172.25.23.21, port 123stratum 0, precision 0, leap 00, trust 000refid [172.25.23.21], delay 0.00000, dispersion 64.00000transmitted 4, in filter 4reference time:    00000000.00000000  Mon, Jan  1 1900  8:05:57.000originate timestamp: 00000000.00000000  Mon, Jan  1 1900  8:05:57.000transmit timestamp:  de4e0e47.784f2a34  Sat, Mar 10 2018 15:56:55.469filter delay:  0.00000  0.00000  0.00000  0.00000 
         0.00000  0.00000  0.00000  0.00000 filter offset: 0.000000 0.000000 0.000000 0.000000
         0.000000 0.000000 0.000000 0.000000delay 0.00000, dispersion 64.00000offset 0.00000010 Mar 15:56:56 ntpdate[13913]: no server suitable for synchronization found12345678910111213141516171819202122232425
  • 上面出现的原因是server droped,也就是说服务器丢弃了数据,可能存在的原因

    • 上面存在的原因可能有两个:1.selinux设置不正常,使用命令setence 0;

    • 还有可能是因为iptables没有添加防火墙例外,也就是对于123/UDP的请求被拒绝;

    • 1.NTP服务器启动不正常,也就是NTP服务器启动过程中存在错误,使用tail -f /var/log/messages查看并且确定错误的详细信息;

  • 对于上面的错误还有可能遇到一种情况

[root@server20 ~]# ntpdate -d 172.25.23.2110 Mar 15:56:52 ntpdate[13913]: ntpdate 4.2.6p5@1.2349-o Mon Jul 15 09:22:50 UTC 2013 (1)
Looking for host 172.25.23.21 and service ntp
host found : server21.com
transmit(172.25.23.21)
transmit(172.25.23.21)
transmit(172.25.23.21)
transmit(172.25.23.21)
transmit(172.25.23.21)172.25.23.21: Server dropped: start toohigh
server 172.25.23.21, port 123stratum 16, precision 0, leap 00, trust 000refid [172.25.23.21], delay 0.00000, dispersion 64.00000transmitted 4, in filter 4reference time:    00000000.00000000  Mon, Jan  1 1900  8:05:57.000originate timestamp: 00000000.00000000  Mon, Jan  1 1900  8:05:57.000transmit timestamp:  de4e0e47.784f2a34  Sat, Mar 10 2018 15:56:55.469filter delay:  0.00000  0.00000  0.00000  0.00000 
         0.00000  0.00000  0.00000  0.00000 filter offset: 0.000000 0.000000 0.000000 0.000000
         0.000000 0.000000 0.000000 0.000000delay 0.00000, dispersion 64.00000offset 0.00000010 Mar 15:56:56 ntpdate[13913]: no server suitable for synchronization found12345678910111213141516171819202122232425
  • 对于上面正常的startnum的范围是[0--->15],出现上面情况的原因是因为NTP服务器无法和上层NTP服务器通信,导致Client的连接不正常;

  • 可以参考第一种错误类型进行配置;

  • 这个是正常时间同步过程中的调式信息

[root@server21 ~]# ntpdate -d 172.25.23.25010 Mar 16:13:18 ntpdate[1508]: ntpdate 4.2.6p5@1.2349-o Mon Jul 15 09:22:50 UTC 2013 (1)
Looking for host 172.25.23.250 and service ntp
host found : 172.25.23.250transmit(172.25.23.250)receive(172.25.23.250)transmit(172.25.23.250)receive(172.25.23.250)transmit(172.25.23.250)receive(172.25.23.250)transmit(172.25.23.250)receive(172.25.23.250)server 172.25.23.250, port 123stratum 4, precision -24, leap 00, trust 000refid [172.25.23.250], delay 0.02571, dispersion 0.00000transmitted 4, in filter 4reference time:    de4e1219.b90d7820  Sat, Mar 10 2018 16:13:13.722originate timestamp: de4e121e.fa8ae002  Sat, Mar 10 2018 16:13:18.978transmit timestamp:  de4e121e.ea321e17  Sat, Mar 10 2018 16:13:18.914filter delay:  0.02580  0.02571  0.02571  0.02571 
         0.00000  0.00000  0.00000  0.00000 filter offset: 0.063770 0.063791 0.063784 0.063784
         0.000000 0.000000 0.000000 0.000000delay 0.02571, dispersion 0.00000offset 0.06379110 Mar 16:13:18 ntpdate[1508]: adjust time server 172.25.23.250 offset 0.063791 sec123456789101112131415161718192021222324252627
  • 补充关于date命令的使用

[root@server21 ~]# date MMDDHHMMYYYYMM:表示月DD:表示天HH:表示小时MM:表示分钟YYYY:表示年123456
  • 上面这个命令主要用来查看(不使用任何选项)和修改时间;

  • hwclock 关于硬件时间

-r :表示用于读取硬件时间-w:表示将软件时间写入为硬件时间12

这里写图片描述


猫的想法不敢猜
4楼 · 2021-12-03 13:51

ntp网络时间服务器(网络时钟同步)客户端与服务器端设置方法说明

更多资料参考——安徽京准——ahjzsz.COM

为了让文件上的时间戳保持一致,我们需要对服务器进行ntp时间同步。

ntp服务器分服务器端以及客户端(C-S)


操作步骤

1 准备工作

两个节点都需要执行

首先安装ntp


yum install ntp

安装完毕之后,启动服务


systemctl start ntpd.service

设置开机自启动


systemctl enable ntpd.service

服务器端设置:

ntp服务端设置

第一台服务器192.168.0.104,作为ntpserver,将他设置为同步外网时间(ntpd服务开启默认就同步了)。

但是得设置允许内网网段可以连接它,将它作为内网的时间同步服务器,所以需要一个简单配置。

修改/etc/ntp.conf文件,添加如下信息,表示允许210网段来同步此服务器


vim /etc/ntp.conf

restrict 192.168.0.0 mask 255.255.255.0 #添加此行


设置后,重启ntpd服务,用ntpstat来检查效果【大概几秒钟就可以看到效果】


systemctl restart ntpd

ntpstat

ntp客户端设置

192.168.0.107 作为ntpclient,将他设置为同步上面的ntpserver,同样需要一个简单配置,分别在两个节点上做如下配置!

修改/etc/ntp.conf文件,注释掉外网时间服务器,添加本地服务器即可


vim /etc/ntp.conf

server 192.168.0.104 #添加此行


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

设置后,重启ntpd服务,用ntpstat来检查效果【大概需要等十五分钟,看到效果】


systemctl restart ntpd

ntpstat

————————————————

版权声明:本文为CSDN博主「安徽京准」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/weixin_44990608/article/details/103783708

来源于网络,仅供参考

相关问题推荐

  • 回答 10

    创建test文件夹hadoop fs -mkdir /test

  • 回答 7

    Hadoop的三大核心组件分别是:1、HDFS(Hadoop Distribute File System):hadoop的数据存储工具。2、YARN(Yet Another Resource Negotiator,另一种资源协调者):Hadoop 的资源管理器。3、Hadoop MapReduce:分布式计算框架。HDFS是一个高度容错性的系统,适合部...

  • 回答 18

    hbase依靠HDFS来存储底层数据。Hadoop分布式文件系统(HDFS)为HBase提供了高可靠性的底层存储支持,HBase中的所有数据文件都存储在Hadoop HDFS文件系统上。

  • 回答 24

    HBase分布式数据库具有如下的显著特点:容量大:HBase分布式数据库中的表可以存储成千上万的行和列组成的数据。面向列:HBase是面向列的存储和权限控制,并支持独立检索。列存储,其数据在表中是按照某列存储的,根据数据动态的增加列,并且可以单独对列进行...

  • 回答 19

    解决问题的层面不一样首先,Hadoop和Apache Spark两者都是大数据框架,但是各自存在的目的不尽相同。Hadoop实质上更多是一个分布式数据基础设施: 它将巨大的数据集分派到一个由普通计算机组成的集群中的多个节点进行存储,意味着您不需要购买和维护昂贵的服务...

  • 回答 14

    1、HBase写快读慢,HBase的读取时长通常是几毫秒,而Redis的读取时长通常是几十微秒。性能相差非常大。2、HBase和Redis都支持KV类型。但是Redis支持List、Set等更丰富的类型。3、Redis支持的数据量通常受内存限制,而HBase没有这个限制,可以存储远超内存大小...

  • 回答 15

    列式存储格式是指以列为单位存储数据的数据存储格式,相比于传统的行式存储格式,它具有压缩比高、读I/O少(此处指可避免无意义的读I/O)等优点,目前被广泛应用于各种存储引擎中。对于HBase而言,它并不是一个列式存储引擎,而是列簇式存储引擎,即同一列簇中...

  • 回答 14

    一、简单理解Hadoop是一个大象:一个hadoop集群主要包含三个主要的模块:Mapreduce,hdfs,yarn。mapreduce是一个分离在合并的计算框架,注意他不是一个集群,而是一个编程框架。hdfs是一个分布式文件系统,是一个分布式集群,用于存放数据。yarn集群是负责集群...

  • 回答 12

    01 网络公开数据集02 数据报采集03 网络爬虫04 日志收集05 社会调查06 业务数据集07 埋点采集08 传感器采集09 数据交易平台10 个人数据收集

  • 回答 9

    1 Hadoop 各个目录的解释bin:Hadoop管理脚本和使用脚本所在目录, sbin目录下的脚本都是使用此目录下的脚本实现的。etc:Hadoop的所有配置文件所在的目录,所有hadoop的配置在etc/hadoop目录下include:对外提供的库的头文件lib :对外提供的动态编程库和静态...

  • 回答 4

    HDFS存储机制,包括HDFS的写入过程和读取过程两个部分: 1、写入过程:  1)客户端向namenode请求上传文件,namenode检查目标文件是否已存在,父目录是否存在。2)namenode返回是否可以上传。3)客户端请求第一个 block上传到哪几个datanode服务器上。4)nam...

  • Shuffle 发生在哪里?2021-04-28 20:11
    回答 4

    adoop核心:MapReduce原理。 MR的核心是shuffle,被称为奇迹发生的地方。 shuffle,弄乱,洗牌的意思。partition 分区,sort 排序,spill溢出,disk 磁盘下面是官方对shuffle的配图: phase 阶段,fetch 最终,merge 合并...

  • 回答 2

    Shuffle阶段分为两部分:Map端和Reduce端。一 map端shuffle过程;1-内存预排序:默认每个map有100M内存进行预排序(为了效率),超过阈值,会把内容写到磁盘;    此过程使用快速排序算法;2-根据key和reducer的数量进行分区和排序;首先根据数据所属的Parti...

  • 回答 3

    大数据时代需要1存储大量数据2快速的处理大量数据3从大量数据中进行分析 

  • Hadoop有哪几种模式?2021-04-27 20:20
    回答 3

    hadoop的四种模式。1、本地模式:本地模式就是解压源码包,不需要做任何的配置。通常用于开发调试,或者感受hadoop。2、伪分布模式:在学习当中一般都是使用这种模式,伪分布模式就是在一台机器的多个进程运行多个模块。虽然每一个模块都有相应的进程,但是却...

  • 回答 1

    进入和退出安全模式 [root@localhost bin]# ./hdfs dfsadmin -safemode enter15/08/03 07:26:24 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where ......

没有解决我的问题,去提问