Linux离线安装NTP服务,内网环境下配置本地时间同步
参考文章:Linux离线安装NTP服务,无外网环境下配置本地时间同步 | 航行学园
1、常用命令
rpm -qa | grep ntp #查询已安装的ntp版本信息等
rpm -e --nodeps ntp-4.2.6p5-29.el7.centos.2.x86_64 #卸载
systemctl status ntpd #查询ntp服务状态
systemctl start ntpd #启动
systemctl stop ntpd #停止
systemctl restart ntpd #重启
ntpq -p #查看ntp服务器与上层ntp的状态
ntpstat #查看时间同步状态(查看ntp服务器有无和上层ntp连通),这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。
2、下载ntp的安装包:
链接:https://pan.baidu.com/s/15yJV9A9zn2KBvy08A080Kw
提取码:cdjz
ntp:可以为其配置ntp.conf将其设置为自动同步某服务器时钟。
3、安装命令:
rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm
安装说明:
直接安装ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm如果不提示缺少依赖就不用再安装另外两个了。
如果提示缺少安装相应的rpm包,也是rpm -ivh …
关于rpm安装安装包是出现的error: Failed dependencies:。。。
解决办法如下:
rpm -ivh 包名 --nodeps --force
加上面后两个参数的意义是安装时不再分析包之间的依赖关系而直接安装。
4、配置:
三台虚拟机:
IP | 节点 |
---|---|
192.168.79.100 | master |
192.168.79.101 | worker1 |
192.168.79.102 | worker2 |
首先设置ntp服务器(master)
编辑配置文件(vim /etc/ntp.conf),注释默认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).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 192.168.79.2 mask 255.255.255.0 nomodify notrap #集群所在网段的网关(Gateway),子网掩码(Genmask)# 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.0.0.1
fudge 127.0.0.1 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.
#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 monitor
修改完成后保存退出,并重启ntp(systemctl restart ntpd)。
设置ntp客户端(以worker1为例,其余相同,略)
编辑配置文件(vim /etc/ntp.conf),注释掉默认ntp服务,使用我们自己配置的ntp服务器(即 192.168.79.100),具体修改部分突出显示,如下:
【特别说明】这里需要注意的是,在使用ntp服务器时,如果有防火墙,则需要开启ntp服务器的udp协议123端口,否则其他虚拟机不能成功同步时间。
# 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
#不同地方
restrict 192.168.79.100 nomodify notrap noquery# 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 192.168.79.100
Fudge 192.168.79.100 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.
#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 monitor
修改完成后保存退出并重启ntp(systemctl restart ntpd)。
5、查看状态:
1)启动ntp服务
systemctl start ntpd
2)查看ntp服务器有无和上层ntp连通
ntpstat
3)查看ntp服务器与上层ntp的状态
ntpq -p
6、设置开机自启动:
systemctl enable ntpd.service
7.手动同步时间尝试(建议使用修改配置永久生效的方法
ntpdate -d 192.168.10.193
出现这个表示手动同步成功
8.修改配置永久生效
vim /etc/ntp.conf
添加自己服务器的server,加上prefer,表示优先执行,其余server可以自行注释
restrict 127.0.0.1 //给于本机所有权限
server 192.168.10.193 prefer //设置时间服务器,加prefer表示优先
9.重启并且查看同步效果
重启systemctl restart ntpd
查看同步效果
ntpq -p
remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。
refid:参考的上一层NTP主机的地址
st:即stratum阶层
when:几秒前曾做过时间同步更新的操作
poll:下次更新在几秒之后
reach:已经向上层NTP服务器要求更新的次数
delay:网络传输过程钟延迟的时间
offset:时间补偿的结果
jitter:Linux系统时间与BIOS硬件时间的差异时间
参考文章:
https://blog.csdn.net/qq_29171935/article/details/87916664
https://blog.csdn.net/qq_38591756/article/details/85243965
https://blog.51cto.com/13670314/2409692
Linux离线安装NTP服务,内网环境下配置本地时间同步相关推荐
- 内网环境下docker安装PMM 并监控 PG与MySQL
0.前言 虽然PMM官网上安装指南上安装PMM有三种方式,但目前主流安装 还是以docker 的方式安装. PMM分两个版本:PMM1和PMM2,PMM1控制力度比较好一些,PMM2界面比较丰富友好一 ...
- 离线/内网环境下搭建vue开发环境
系列文章目录 第一讲 离线/内网环境下搭建vue开发环境 第二讲 内网环境运行maven项目 目录 外网环境搭建 一.安装nodeJS 二.安装vue依赖包 内网环境正式开始 准备工作: 一.安装no ...
- 内网环境下预览ArcGIS地图服务
内网环境下预览ArcGIS地图服务 文章目录 内网环境下预览ArcGIS地图服务 1.背景 2.解决方案 2.1下载ArcGIS API for JavaScript 2.2本地部署ArcGIS AP ...
- 内网环境下使用rpm包制作yum数据源及使用
内网环境下使用rpm包制作yum数据源及使用 在实际生产环境中,绝大多数服务器处于内网环境.基于最小化安装.光盘镜像挂载不方便(缺少)等原因,无法使用yum服务,本实验基于生产环境中出现的上述现象进行 ...
- 内网渗透-内网环境下的横向移动总结
内网环境下的横向移动总结 文章目录 内网环境下的横向移动总结 前言 横向移动威胁 威胁密码安全 威胁主机安全 威胁信息安全 横向移动威胁的特点 利用psexec 利用psexec.exe工具 msf中 ...
- 22. 案例:在 proxy 内网环境下使用 percona 监控 mysql
文章目录 22. 案例:在 proxy 内网环境下使用 percona 监控 mysql 22.1 安装 mysql 22.2 安装 percona 22.3 安装 agent 22.4 配置 age ...
- 内网环境下CentOs离线安装程序
目录 零.情景介绍 一.下载 RPM 包 1.安装包的选择 2.rpm包的命名规则 二.传输rpm包到CentOs主机上 三.安装rpm包的工具 1.安装 2.查询 3.卸载 四.安装rpm 五.相关 ...
- 内网环境下手动部署kubernetes(v1.26.3)高可用集群
这篇博客主要是记录了手动部署一个高可用的Kubernetes集群的过程.旨在帮助自己及初学者学习kubernetes,并记录下具体的操作过程和总结的知识点.文中可能存在一些问题或不足之处,仅供参考. ...
- 内网环境下的横向移动总结
前言 在内网渗透中,当攻击者获取到内网某台机器的控制权后,会以被攻陷的主机为跳板,通过收集域内凭证等各种方法,访问域内其他机器,进一步扩大资产范围.通过此类手段,攻击者最终可能获得域控制器的访问权限, ...
最新文章
- C语言求3x3数组对角线元素之和
- 忘了root口令解决方法
- python pygame模块按键延迟_如何在python/pygame中延迟一件事情而不延迟其他事情?...
- 可视化---寻找路径与算法
- 代码添加ProgressBar 进度条
- delphi 生成 超大量xml_用OpenCV4实现图像的超分别率
- 工作经验--他人经验
- Http协议对格式、请求头、方法
- 计算机组成原理知识点总结白中英,计算机组成原理知识点总结.pdf
- Linux从入门到指令详解
- 新版中日交流标准日本语多媒体版(全25CD)下载
- python画图-python绘图入门(完整版)
- 使用node批量压缩图片
- UVALive - 3713 - Astronauts(图论——2-SAT)
- 世界最大暗物质探测器成功运行!首个结果出炉,研究团队达250人,实验室在地下1.5公里...
- 让老主板也支持nvme固态硬盘做系统启动盘,使用mmtool给主板添加nvme协议
- ai人工智能书籍_您应该阅读的有关AI的精彩书籍
- 视音频编解码技术零基础学习方法(向雷神致敬)
- 100句记住7000单词
- 8.10 12.1-12.5