首页 > 系统相关 > Linux系统配置NTP时钟服务器

Linux系统配置NTP时钟服务器

时间:2023-02-10 23:03:34浏览次数:57  
标签:NTP Linux 192.168 rpm ntp home root el7 系统配置

1、需要配置的计算机IP

192.168.0.131 bznode1

192.168.0.134 bznode2

192.168.0.135 b​znode3

192.168.0.136 bznode4

设置IP=192.168.0.131为时钟服务器

IP=192.168.0.134服务器为需要同步机器

IP=192.168.0.135服务器为需要同步机器

IP=192.168.0.136服务器为需要同步机器

2、查看每个机器是否安装了ntp

[root@bznode1 ~]# rpm -qa | grep ntp
ntp-4.2.6p5-25.el7.centos.2.x86_64
ntpdate-4.2.6p5-25.el7.centos.2.x86_64
[root@bznode1 ~]#

这样的输出证明已经安装好了,其中包就是" ntp-4.2.6p5-25.el7.centos.2.x86_64"

如果已经安装则略过此步,如果没有安装则先安装ntp,安装ntp有两种方式

1.使用yum进行安装,并设置系统开机自动启动并启动服务

[root@ bznode1 ~]# yum -y install ntp
[root@ bznode1 ~]# systemctl enable ntpd
[root@ bznode1 ~]# systemctl start ntpd

2.离线安装

首先需要下载ntp的rpm包,把下载好的包放到/home文件夹下面

下载地址​​​​​https://pkgs.org/​​

 Linux系统配置NTP时钟服务器_UDP

安装ntp可能会遇到下面的问题,缺少依赖

[root@ bznode1 home]# rpm -ivh ntp-4.2.6p5-25.el7.centos.2.x86_64
错误:依赖检测失败:

Libopts.so.25()(64bit) 被 ntp-4.2.6p5-22.el7.centos.x86_64 需要
ntpdate = 4.2.6p5-22.el7.centos 被 ntp-4.2.6p5-22.el7.centos.x86_64 需要
[root@ bznode1 home]#

上面给出的截图里面已经下载到了需要的rpm包,下面就依次进行安装即可

[root@bznode1 home]# rpm -ivh autogen-libopts-5.18-5.el7.x86_64.rpm 
警告:autogen-libopts-5.18-5.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:autogen-libopts-5.18-5.el7 ################################# [100%]
[root@bznode1 home]# rpm -ivh ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm
警告:ntpdate-4.2.6p5-25.el7.centos.2.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:ntpdate-4.2.6p5-25.el7.centos.2 ################################# [100%]
[root@bznode1 home]# rpm -ivh ntp-4.2.6p5-25.el7.centos.2.x86_64.rpm
警告:ntp-4.2.6p5-25.el7.centos.2.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:ntp-4.2.6p5-25.el7.centos.2 ################################# [100%]
[root@bznode2 home]#

3、配置ntp.conf文件

配置NTP服务器的关键是需要配置这个文

[root@ bznode1 ~]# vi /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 ::1
# 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
#restrict 192.168.195.0 mask 255.255.0.0 nomodify
server 127.127.1.0
fudge 127.127.1.0 stratum 11
下面的省略了....

这是要改变的地方,server 0-3 注释掉, 加入本地时间服务器,主要是 127.127.1.0,由于是顶层服务,也就是说没有上级时间服务器 了,这里就是使用192.168.0.131的时间为准。接着,重启或者启动ntpd服务:

[root@ceph-node1 ~]# systemctl restart ntpd.service

此时,ntpd服务器已经配置好了。再执行:

[root@ceph-node1 ~]# systemctl enable ntpd.service

使服务在系统启动后就开启。

4、在客户端机器上进行配置 

[root@ bznode2 ~]# vi /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 ::1
# 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 iburst local clock
#fudge 127.127.1.0 stratum 11
#restrict 192.168.195.0 mask 255.255.0.0 nomodify
server 192.168.0.131
fudge 127.127.1.0 stratum 11
下面省略....

主要是添加下面两行:

server 192.168.0.131

fudge 127.127.1.0 stratum 11

#这个是需要11,因为不是顶级的

配置好保存,重启ntp服务并设置跟随系统启动

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

查看ntp服务状态

[root@bznode2 /]# ntpq -p
remote refid st t when poll reach delay offset jitter
=====================================================
*192.168.0.131 LOCAL(0) 6 u 66 64 377 0.094 -6.614 2.241
[root@bznode2 /]#

refid为LOCAL(0)为准确。

其他需要同步的服务器同样按照上面步骤进行操作即可

5、实时同步时间

执行命令 ntpdate 192.168.0.131可能会遇到下面的问

[root@bznode2 home]# ntpdate 192.168.0.131
11 Jan 16:31:32 ntpdate[5723]: the NTP socket is in use, exiting

然后使用lsof –i:123命令

[root@bznode2 home]# lsof -i:123
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ntpd 5670 ntp 16u IPv4 12173 0t0 UDP *:ntp
ntpd 5670 ntp 17u IPv6 12174 0t0 UDP *:ntp
ntpd 5670 ntp 18u IPv4 12179 0t0 UDP localhost:ntp
ntpd 5670 ntp 19u IPv4 12180 0t0 UDP bznode3:ntp
ntpd 5670 ntp 20u IPv6 12181 0t0 UDP bznode3:ntp
ntpd 5670 ntp 21u IPv6 12182 0t0 UDP localhost:ntp
[root@bznode2 home]# kill -9 5670

此后,再使用ntpdate 192.168.0.131就成功了!

[root@bznode2 home]# ntpdate 192.168.0.131
11 Jan 16:32:43 ntpdate[5753]: adjust time server 192.168.0.131 offset 0.150170 sec
[root@bznode2 home]#

如果lsof –i:123命令出现下面问题

[root@bznode2 /]# lsof -i:123
-bash: lsof: 未找到命令
[root@bznode2 /]#

则只需要安装上面截图中的lsof-4.87-4.el7.x86_64 (1).rpm就可以了

[root@bznode2 home]# rpm -ivh lsof-4.87-4.el7.x86_64\ \(1\).rpm 
警告:lsof-4.87-4.el7.x86_64 (1).rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:lsof-4.87-4.el7 ################################# [100%]
[root@bznode2 home]#


标签:NTP,Linux,192.168,rpm,ntp,home,root,el7,系统配置
From: https://blog.51cto.com/u_15935178/6049765

相关文章

  • ARM linux 系统调用实现原理
    https://blog.csdn.net/u013836909/article/details/120962422 LinuxARM系统调用过程分析(一)——Linux编程中的API函数和系统调用的关系LinuxARM系统调用过程分析(二......
  • 嵌入式Linux—文件IO
    文件IO在Linux系统中,一切都是“文件”:普通文件、驱动程序、网络通信等等。所有的操作,都是通过“文件IO”来进行的。所以,很有必要掌握文件操作的常用接口。Linux系......
  • 服役已有6年:Linux Kernel 4.9正式终止支持
    Linux Kernel4.9收到4.9.337更新,并在kernel.org上被标记为EOL,这意味着该版本系统将正式终止支持,不再收到任何维护和安全更新。而这,距离LinuxKernel4.9推出,已经过......
  • linux下查看发行版本和内核版本
    1、查看发行版本cat/etc/*_release如:cat/etc.rocky_release或用lsb_release命令 2、查看内核版本cat/proc/version  或用uname-a ......
  • Linux系统的目录结构
    在Windows下,我们的整个硬盘实际上可以被分为多个磁盘驱动器:而在Linux中,没有C盘D盘这个概念,只有一句经典的话:"在Linux世界里,一切皆文件",而所有的文件都是位于根目录下的,Lin......
  • Linux系列教程(七)——Linux常用命令之帮助和用户管理命令
    上篇博客我们介绍了​​Linux文件搜索命令​​,其中find是用的最多的也是功能最强大的文件或目录搜索命令,和另一个搜索命令locate的区别是,find命令是全盘搜索,刚创建的文......
  • linux基本功之lsof命令实战
    前言......
  • 记一次Arch Linux蓝牙问题
    在一次系统更新后,重启发现蓝牙无法使用,表现为:右上角的Bluetooth图标闪烁,设置选项里的Bluetooth在"BluetoothTurnedOff"和"NoBluetoothFound"之间来回闪烁。......
  • Linux shell system environment variables All In One
    LinuxshellsystemenvironmentvariablesAllInOnebash/zshvscodeterminalenvCommand+Shift+PdemosPS1demo.vscode/settings.json{//自定......
  • Linux Nginx企业级平滑升级完整演示,全网最全最详细!
    平滑升级到底是个什么东西呢?说白了就是在不停止公司业务或者不停止公司网站的前提下对Nginx服务进行版本的升级,而且升级的过程呢正在访问的用户是感觉不到的,他们该怎么访问......