栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

局域网内不同linux主机间时间同步

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

局域网内不同linux主机间时间同步

这里写自定义目录标题
  • 使用chrony服务
    • 1、服务端
        • 1.1修改配置文件
            • 1.2 重启chronyd服务
    • 2 客户端
        • 2.1 修改配置文件
            • 2.2 重启chronyd服务
    • 3.客户端定时重启chronyd服务来实现同步

使用chrony服务

摘要:使用其中一台作为服务器主机,其他主机作为客户端,使用crontab定时任务来实现定期自动同步时间为主机时间。

1、服务端
vim  /etc/chrony.conf
1.1修改配置文件
# 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
#主机Ip 当前IP
server 192.168.10.17 iburst
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#表示允许谁去同步我的时间
allow 192.168.10.1/16

# Serve time even if not synchronized to a time source.
#不去同步任何人的时间
local stratum 10

# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys

# Specify directory for log files.
logdir /var/log/chrony
1.2 重启chronyd服务
systemctl restart chronyd
2 客户端
vim  /etc/chrony.conf
2.1 修改配置文件
# 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 193.168.10.17 iburst
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3
2.2 重启chronyd服务
systemctl restart chronyd
3.客户端定时重启chronyd服务来实现同步
crontab -e

客户端每天0点自动同步主机时间

0 0 * * * systemctl restart chronyd
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/599736.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号