目的:
保证分布式环境所有机器的时间具有一致性
推荐 chrony,原因:chrony相对于ntp的优势,但npt 支持广播协议;小规模集群推荐chrony
大规模集群时间同步参考教程
集群时钟同步必读-NTP和chronyhttps://www.cnblogs.com/subsea/p/17350326.html
一:安装 chrony
1)安装运行:
yum install chrony
2、修改chrony配置文件:/etc/chrony.conf
注释掉原来的时间同步池,再前面添加 # 号
并且在文件最后面:添加3个阿里的同步服务
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp4.aliyun.com iburst
3、启动chronyd
systemctl start chronyd
4、检查运行状态情况
systemctl status chronyd
5、设置开机自启动
systemctl enable chronyd
6、更改时区
timedatectl set-timezone Asia/Shanghai
7、手工强制执行时间同步
chronyc -a makestep
8、检查同步状态
chronyc tracking
#或者执行
chronyc sources –v
二、 安装npt服务,已经过时了(2023-09-05)
1、安装ntp服务
yum install ntp
#开机启动服务
systemctl enable ntpd
#启动服务
systemctl start ntpd
#更改时区
timedatectl set-timezone Asia/Shanghai
2、修改默认配置文件
vim /etc/ntp.conf
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#设置ntp1.aliyun.com可以修改本地系统时间
restrict ntp.aliyun.com nomodify notrap noquery
#设置阿里云NTP服务器
server ntp.aliyun.com
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
server ntp4.aliyun.com
server ntp5.aliyun.com
server ntp6.aliyun.com
server ntp7.aliyun.com
# 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#注释以上默认NTP服务器
3、重启服务
#重启NTP服务
systemctl restart ntpd
4.进行单词时间同步
#单次同步时间
ntpdate ntp.aliyun.com
#启用ntp同步
timedatectl set-ntp yes
5.查看同步状态
ntpq -p #查看NTP服务同步状态,见下面输出代表成功
remote refid st t when poll reach delay offset jitter
==============================================================================
120.25.115.20 10.137.53.7 2 u 9 64 1 47.461 0.578 0.000