CentOS 7 多台服务器 时间同步
现有5台服务器
- server-1(192.168.31.2)
- server-2(192.168.31.3)
- server-3(192.168.31.4)
- server-4(192.168.31.5)
- server-5(192.168.31.6)
项目需求以server-1服务器时间为标准,其他服务器时间与其同步对齐
安装软件
上述服务器执行以下命令
# 卸载默认时钟
sudo yum -y remove chrony
# 安装ntp
sudo yum install ntp -y
server-1 配置
打开文件 /etc/ntp.conf
,16行开始修改如下
# Hosts on local network are less restricted.
restrict 192.168.31.2 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.50.0 mask 255.255.255.0 nomodify notrap
配置中分别是本机IP和掩码
并在末尾追加内容
server 127.127.1.0
fudge 127.127.1.0 stratum 10
127.127.1.0 是一个特殊的地址,代表本地时钟设备
stratum 10 是一个相对较低的值,表示这个时间源比默认的系统时钟(通常是 stratum 16)更准确,但10已经够用了
启动服务
sudo systemctl start ntpd
# 开机自启服务
sudo systemctl enable ntpd
server-2、3、4、5 配置
打开文件 /etc/ntp.conf
,16行开始修改如下
# Hosts on local network are less restricted.
# restrict 127.0.0.1 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.31.2
启动服务
sudo systemctl start ntpd
# 开机自启服务
sudo systemctl enable ntpd
设置定时任务——定时对齐时间
# 打开定时器
crontab -e
追加内容
我的配置是每分钟执行一次命令
*/1 * * * * /usr/sbin/ntpdate 192.168.31.2
保存退出(crontab不是立即生效,隔几分钟看效果)
本文来自博客园,作者:勤匠,转载请注明原文链接:https://www.cnblogs.com/JarryShu/articles/18543614
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现