文章目录
- 概述
 - 图
 - 步骤
 - 1、修改时区
 - 2、安装chrony
 - 3、选1台机作为时钟服务器
 - 4、其他机器同步时间
 
概述
对于物理机集群,需要使用统一的时间,本文使用时钟同步技术来实现
图
图解
默认的 外部网络的 时钟服务器 在国外,速度较慢
0.centos.pool.ntp.org
1.centos.pool.ntp.org
2.centos.pool.ntp.org
3.centos.pool.ntp.org
 
换成 国内的 时钟服务,速度较快
ntp1.aliyun.com
ntp2.aliyun.com
ntp3.aliyun.com
……
 
步骤
1、修改时区
每台机执行
# 修改时区
timedatectl set-timezone Asia/Shanghai
# 设置硬件时钟为UTC时间
timedatectl set-local-rtc 0
# 启动NTP时间同步(含ntpd服务或chrony服务)
timedatectl set-ntp true
# 最后检查一下
timedatectl
 
2、安装chrony
每台机执行,查看有无安装chrony
rpm -qa | grep chrony
 
每台机执行,安装chrony
yum install -y chrony
 
每台机执行,设置chrony开机自启
systemctl start chronyd
systemctl enable chronyd
systemctl status chronyd
 
3、选1台机作为时钟服务器
以node100作为内网集群的时钟服务器,其它机与本机时间进行同步
 而本机与阿里云时间进行同步,配置chrony
vim /etc/chrony.conf
 
做如下修改
# 注释掉默认的4个ntp服务器,因为慢
#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个快的,是阿里云的ntp服务
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
# 允许所有主机从server端同步时间
# Allow NTP client access from local network.
allow all
# 即使server端无法从互联网同步时间,也同步本机时间至client
# Serve time even if not synchronized to a time source.
local stratum 10
 
改完后,重启chrony服务
systemctl restart chronyd
 
4、其他机器同步时间
vim /etc/chrony.conf
 
注释掉默认的4个ntp服务器
# 注释掉默认的4个ntp服务器
#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 node100 iburst
 
改完后,重启chrony服务
systemctl restart chronyd
 
检验:每台机同时发送date命令,看看时间是否一致
Appendix
| 英 | 🔉 | 中 | 
|---|---|---|
| NTP | Network Time Protocol | 网络时间协议 | 
| chron | krɑːn | comb. 时;时间 | 
| RTC | Real_Time Clock | 实时时钟 | 














![[附源码]SSM计算机毕业设计“云味坊”购物网站JAVA](https://img-blog.csdnimg.cn/6e1d891bbc7f415a95be21b732fff5db.png)





