IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> linux搭建私网的ntp时间同步服务 -> 正文阅读

[系统运维]linux搭建私网的ntp时间同步服务

目录

一. 安装相关软件

二. 修改配置文件

三. 启动

四. 测试

一. 安装相关软件

1. 没有rpm文件时

需要到与需要安装ntp服务操作系统相同的且有网络的服务器上,下载所需依赖包

yum install ntp ntpdate --downloadonly --downloaddir=/package
#语法释义:
#--downloadonly: 表示仅下载,不安装
#--downloaddir: 表示下载依赖包的路径

如此就可以将安装ntp和ntpdate的所有依赖包下载到/package下面了,然后将/package/下的所有依赖包拷贝到需要安装ntp服务的服务器中

2. 如果有依赖包了就可以直接执行安装,命令如下:

rpm -ivh /package/*.rpm
#/package/*.rpm 指的是依赖包的绝对路径

二. 修改配置文件

安装好依赖之后,就是对配置文件进行修改了,我这里列出自己的安装环境:

主服务:192.168.52.140

客户端节点A:192.168.52.141

客户端节点B:192.168.52.142

说明: 由主服务提供校时服务,客户端节点A,B每5~10分钟向主服务同步一次时间

我将分别列出主服务与客户端节点的配置文件(目录是:/etc/ntp.conf)

1. 主服务

# 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.52.140 nomodify notrap nopeer noquery   #新增该行
server 127.127.1.0 iburst local clock                    #新增该行
restrict 192.168.52.0 mask 255.255.255.0 nomodify        #新增该行
Fudge 127.127.1.0 stratum 10                             #新增该行
#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

2. 客户端A(192.168.52.141)?

# 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.52.141 nomodify notrap nopeer noquery   #新增该行
server 192.168.52.140                                    #新增该行
restrict 192.168.52.0 mask 255.255.255.0 nomodify        #新增该行
Fudge 192.168.52.140 stratum 10                          #新增该行
#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

3. 客户端B(192.168.52.142)?

# 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.52.142 nomodify notrap nopeer noquery   #新增该行
server 192.168.52.140                                    #新增该行
restrict 192.168.52.0 mask 255.255.255.0 nomodify        #新增该行
Fudge 192.168.52.140 stratum 10                          #新增该行
#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

三. 启动

#首先在主服务中先手动校时一次,并同步到硬件上
date -s '20220302 18:44:40' && hwclock -w

#启动服务(在所有服务中都执行)
systemctl start ntpd

#设置开机自启(在所有服务中都执行)
systemctl enable ntpd

#查看服务状态(在所有服务中都执行)
systemctl status ntpd

四. 测试

所有服务都启动之后,等待10分钟左右,就会发现所有的客户端(A,B)的时间已经和主服务同步了

#查看服务器当前时间
date

?如此就算大功告成啦,喜欢的就点个赞和关注吧(* ̄︶ ̄)

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-03-03 16:53:58  更:2022-03-03 16:54:36 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/16 3:44:21-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码