一、服务器配置

1、查看服务器、客户端操作系统版本

[root@hadoop101 ~]# cat /etc/redhat-release
CentOS Linux release 7.6. (Core)

2、查看服务器是否安装ntp,系统默认安装ntpdate;

[root@hadoop101 ~]# rpm -qa | grep ntp
fontpackages-filesystem-1.44-.el7.noarch
ntpdate-4.2.6p5-.el7.centos.x86_64
python-ntplib-0.3.-.el7.noarch
ntp-4.2.6p5-.el7.centos.x86_64

3、安装ntp ntpdate,其中ntpdate默认安装,可以只安装ntp;

yum install ntp ntpdate -y

4、查看是否已安装完成,与第2步对比

[root@hadoop101 mysql-libs]# rpm -qa | grep ntp
fontpackages-filesystem-1.44-.el7.noarch
ntpdate-4.2.6p5-.el7.centos.x86_64
ntp-4.2.6p5-.el7.centos.x86_64
python-ntplib-0.3.-.el7.noarch

5、查看ntp服务器状态,两条命令效果一样

[root@hadoop101 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)

[root@hadoop101 ~]# service ntpd status
Redirecting to /bin/systemctl status ntpd.service
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)

6、修改配置文件,使该NTP服务器在不联网的情况下,使用本服务器的时间作为同步时间

vim /etc/ntp.conf

把如下四行代码注释掉

#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst

在下面再添加两行

server 127.127.1.0
fudge 127.127.1.0 stratum

配置后:

[root@hadoop101 ~]# vim /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(), ntp_acc(), ntp_auth(), ntp_clock(), ntp_misc(), ntp_mon(). 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 :: # Hosts on local network are less restricted.
#restrict 192.168.1.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.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 0
#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 # Specify the key identifier to use with the ntpdc utility.
#requestkey # Specify the key identifier to use with the ntpq utility.
#controlkey # Enable writing of statistics records.

7、启动ntp服务

systemctl start ntpd

service ntpd start

8、再次查看服务器状态是否配置成功

[root@hadoop101 mysql-libs]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: active (running) since Fri -- :: CST; 13s ago
Process: ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=/SUCCESS)
Main PID: (ntpd)
Tasks:
CGroup: /system.slice/ntpd.service
└─ /usr/sbin/ntpd -u ntp:ntp -g Aug :: hadoop101.com ntpd[]: Listen normally on ...
Aug :: hadoop101.com ntpd[]: Listen normally on ...
Aug :: hadoop101.com ntpd[]: Listen normally on ...
Aug :: hadoop101.com ntpd[]: Listen normally on ...
Aug :: hadoop101.com ntpd[]: Listening on routing ...
Aug :: hadoop101.com ntpd[]: 0.0.0.0 c016 restart
Aug :: hadoop101.com ntpd[]: 0.0.0.0 c012 freq_...
Aug :: hadoop101.com ntpd[]: 0.0.0.0 c011 freq_...
Aug :: hadoop101.com systemd[]: Started Network Time ...
Aug :: hadoop101.com ntpd[]: 0.0.0.0 c514 freq_...
Hint: Some lines were ellipsized, use -l to show in full.

[root@hadoop101 ~]# service ntpd status

9、查看是否同步

[root@hadoop101 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL() .LOCL. l 0.000 0.000 0.000

10、设置开机启动

[root@hadoop101 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

11、设置防火墙,打开udp123端口(如果防火墙关了就不用设置了)

[root@hadoop101 ~]# firewall-cmd --permanent --add-port=/udp
success
[root@hadoop101 ~]# firewall-cmd --reload
success

12、查看防火墙已打开端口

iptables -L -n

二、客户端配置(其他节点)

前5步与服务器一致

6、修改配置文件,将刚刚搭建好的NTP服务器作为客户端上游时间服务器

vim /etc/ntp.conf
#注释掉其他上游时间服务器
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#配置上游时间服务器为本地的ntpd Server服务器
server hadoop101.com
fudge hadoop101.com stratum #配置允许上游时间服务器主动修改本机的时间
restrict hadoop101.com nomodify notrap noquery

配置后:

[root@hadoop103 ~]# vi /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(), ntp_acc(), ntp_auth(), ntp_clock(), ntp_misc(), ntp_mon(). 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 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap restrict hadoop101.com nomodify notrap noquery # Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#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 hadoop101.com
fudge hadoop101.com stratum 0
#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 # Specify the key identifier to use with the ntpdc utility.
#requestkey # Specify the key identifier to use with the ntpq utility.

7、与本地ntpd Server同步一下

[root@hadoop102 ~]# ntpdate -u hadoop101.com
Aug :: ntpdate[]: adjust time server 192.168.1.101 offset 0.004621 sec

8、启动ntp服务

systemctl start ntpd

service ntpd start

9、设置开机启动

[root@hadoop102 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

10、查看状态

[root@hadoop103 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
hadoop101.com .LOCL. u 8.148 -2.581 0.000

参考:https://blog.csdn.net/hellboy0621/article/details/81903091

CentOS7搭建NTP服务器及客户端同步时间的更多相关文章

  1. centos7搭建svn服务器及客户端设置

    centos7搭建svn服务器及客户端设置 centos7貌似预装了svn服务(有待确认),因此我们直接启动该服务即可 一.svn服务端配置(服务器IP假设为192.168.100.1) 步骤1:创建 ...

  2. centos6 & centos7搭建ntp服务器

    原理 NTP(Network TimeProtocol,网络时间协议)是用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1 ...

  3. linux篇-CentOS7搭建NTP服务器

    1查看服务器.客户端操作系统版本 2查看服务器是否安装ntp 3如果没有安装 4安装完成后重新查看服务器是否安装ntp 5查看ntp服务器状态 6修改配置文件 注释 #server 0.centos. ...

  4. Centos7安装搭建NTP服务器和NTP客户端同步时间

    NTP简介: NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在计算机的世界里,时间非常地重要 例如:对于火箭发射这种科研活动,对时间的 ...

  5. 时间服务器: NTP 服务器及客户端搭建

    时间服务器: NTP 服务器及客户端搭建 一. NTP 服务器的安装与设定 1. NTP 服务器的安装与设定前言 2. 所需软件与软件结构 3. 主要配置文件 ntp.conf 的处理 4. NTP ...

  6. centos7搭建ntp时间同步服务器chrony服务

    centos7搭建ntp时间同步服务器chrony服务 前言: 在centos6的时候我们基本使用的是ntp服务用来做时间同步,但是在centos7后推荐是chrony作为时间同步器的服务端使用, ...

  7. CentOS 6.5 下搭建NTP服务器

    参考网站: http://www.iyunv.com/thread-64847-1-1.html http://acooly.iteye.com/blog/1993484 1         检查系统 ...

  8. Ubuntu搭建NTP服务器

    NTP简介 NTP是Network Time Protocol的缩写,又称为网络时间协议.是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提 ...

  9. CentOS7 搭建 SVN 服务器

    CentOS7 搭建 SVN 服务器 介绍SVN: SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上 ...

随机推荐

  1. VirtualBox导入VmWare生成的.vmdk格式虚拟机镜像

    VmWare默认的镜像格式是.vmdk格式的,VirtualBox则默认是.vdi格式的.其实这在VirtualBox新建虚拟机的过程中是可选的. 导入.vmdk格式的镜像到VirtualBox只需要 ...

  2. 【NOIP2016提高A组模拟10.15】最大化

    题目 分析 枚举两个纵坐标i.j,接着表示枚举区域的上下边界, 设对于每个横坐标区域的前缀和和为\(s_l\),枚举k, 显然当\(s_k>s_l\)时,以(i,k)为左上角,(j,k)为右下角 ...

  3. “_MSC_VER”的不匹配项

    近些年来vs更新步伐加快,深刻的感受到了技术成长学习的重要性. 另一方面,版本的更换,也带来了许多的问题.今天用2019打开以前2010的工程时就碰到了一个: 检测到“_MSC_VER”的不匹配项: ...

  4. HTTS TTLS 433

    HTTP和HTTPS协议,看一篇就够了 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/x ...

  5. JUnit——运行多个测试方法

    TDD=Test Drive Development   在实际应用中作用特别大,因为我们会定义很多的类和方法,也会存在很多的更新操作,这样如果用main函数进行测试,则会异常麻烦. 而如果用这种多个 ...

  6. mac 的 ping 命令怎么停掉?

    Widnows下的Ping不会只Ping4次,mac 会不停的Ping下去,需要停止,按下键盘上的 control+c 键即可停掉 Ping 过程.

  7. windows下开启远程连接Mysql

    使用“Ctrl + R”组合键快速打开cmd窗口,并输入“cmd”命令,打开cmd窗口.  使用“mysql -uroot -proot”命令可以连接到本地的mysql服务.  使用“use mysq ...

  8. LBS 基于位置的服务

    LBS (Location Based Services)基于位置的服务 基于位置的服务,它是通过电信移动运营商的无线电通讯网络(如GSM网.CDMA网)或外部定位方式(如GPS)获取移动终端用户的位 ...

  9. android日志优先级

    Android 的日志分为如下几个优先级(priority): V —— Verbose(最低,输出得最多) D —— Debug I —— Info W —— Warning E —— Error ...

  10. android sp文件一个键值保存多条信息

    之前碰到过这样的问题,sp文件只能够append,或者清空.其实一个键值,通过,分割,或者替代可以实现多条信息的存储.下面是一个举例: package com.ctbri.weather.utils; ...