说明
本博文记录,使用chrony完成时间同步,centos7系统默认自带。
分享
- 大数据博客列表
- 开发记录汇总
- 个人java工具库 项目https://gitee.com/wangzonghui/object-tool
- 包含json、string、集合、excel、zip压缩、pdf、bytes、http等多种工具,欢迎使用。
国内公共ntp服务
-
阿里云公共NTP服务器:
- Unix/linux类:ntp.aliyun.com,ntp1-7.aliyun.com
- windows类: time.pool.aliyun.com
-
腾讯公共NTP服务器:time1-5.cloud.tencent.com
-
大学NTP服务器:
- s1a.time.edu.cn 北京邮电大学
- s1b.time.edu.cn 清华大学
- s1c.time.edu.cn 北京大学
-
国家授时中心服务器:210.72.145.44
单机同步
- 查看系统是否安装chrony服务:
rpm -qa |grep chrony
- 未安装则手动安装:
yum -y install chrony
- 未安装则手动安装:
- 启动chrony服务:
systemctl start chronyd.service
- 设置开机启动:
systemctl enable chronyd.service
- 查看chronyd状态:
systemctl status chronyd.service
- 编辑文件:
vi /etc/chrony.conf
设置时间服务器
# 修改server设置国内时间服务器
# 单个方式
server ntp1.aliyun.com iburst
# 多个方式
server 0.ntp1.aliyun.com iburst # 阿里
server 1.time1.cloud.tencent.com #腾讯
- 手动同步时钟:
chronyc -a makestep
- 显示当前chronyd正在访问的时间源的信息:
chronyc sources -v
集群同步
所有节点
- 查看系统是否安装chrony服务:
rpm -qa |grep chrony
- 未安装则手动安装:
yum -y install chrony
- 未安装则手动安装:
配置防火墙
- 防火区放行 NTP使用123/UDP 端口协议
# centos7 配置方式
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload
时间服务器节点
- 时间服务器,编辑文件:
vi /etc/chrony.conf
,内容如下:
# 内网集群
server 集群时间服务器ip iburst
# 允许其他节点连接
allow 0.0.0.0/0
local stratum 10 #不去同步任何人的时间。时间同步服务级别
- 查看时区:
timedatectl
- 设置时区:
timedatectl set-timezone Asia/Shanghai
- 强制同步系统时间:
chronyc -a makestep
- 重启chrony服务:
systemctl restart chronyd.service
- 查看chrony状态:
systemctl status chronyd.service
其他节点
- 其他服务器同步时间服务时间,编辑文件:
vi /etc/chrony.conf
# 配置时间服务器
server 集群时间服务器ip iburst
- 重启chrony服务:
systemctl restart chronyd.service
- 显示当前chronyd正在访问的时间源的信息:
chronyc sources -v
验证
- 修改服务器时间:date -s “2021-9-11 11:11:11”
- 一段时间后查看:date
总结
- 服务器时间同步是很多分布式软件正常运行的基础,非常重要。
- 学海无涯,日日新,加油。