Linux配置时间同步
一、Master节点
1、关闭ntp服务和自启动(必须root用户)
yum install -y ntp
sudo systemctl stop ntpd
sudo systemctl disable ntpd
2、修改ntp配置文件
vi /etc/ntp.conf
修改内容如下:
(1)修改1(授权192.168.67.0-192.168.67.255网段上的所有机器可以从这台机器上查询和同步时间)
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
改为:
restrict 192.168.67.0 mask 255.255.255.0 nomodify notrap
(2)修改2(集群在局域网中,不使用其他互联网上的时间)
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 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
(3)添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
4、修改/etc/sysconfig/ntpd 文件
vi /etc/sysconfig/ntpd
#增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
5、重新启动ntpd服务
systemctl start ntpd
6、设置ntpd服务开机启动
systemctl enable ntpd
7、查看ntpd状态
systemctl status ntpd
二、其他节点,其他机器配置(必须root用户)
1、在其他机器配置10分钟与时间服务器同步一次
crontab -e
#编写定时任务如下:
*/10 * * * * /usr/sbin/ntpdate 192.168.67.1
2、修改任意机器时间
date -s "2020-5-14 12:12:12"
3、十分钟后查看机器是否与时间服务器同步
date
三、Bug说明
1、若时间服务器错误,则:
(1)关闭ntpd服务:
systemctl stop ntpd
(2)查询网络时间:
ntpdate cn.pool.ntp.org
(3)启动ntpd服务:
systemctl start ntpd
2、若其他机器同步时间时发生错误,则:
(1)关闭ntpd服务:
systemctl stop ntpd
(2)关闭ntpd服务自启动:
systemctl disable ntpd
(3)与时间服务器时间同步:
ntpdate 192.168.67.1
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本