欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > Linux多台服务器 时间同步

Linux多台服务器 时间同步

2025/2/24 0:37:25 来源:https://blog.csdn.net/qq_35215728/article/details/143737121  浏览:    关键词:Linux多台服务器 时间同步

Linux多台服务器 时间同步

基于 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不是立即生效,隔几分钟看效果)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词