在所有节点上执行chrony服务安装命令,将主节点设置时间服务器,其他的节点都从主节点同步时间。
# 安装服务
yum -y install chrony
# 查看状态
systemctl status chronyd
# 重启chronyd
systemctl restart chronyd
二、检查设置时区
在所有节点上设置统一的时间区域,本文中将其设置为亚洲时区,用户可自行定义。
# 查看时区
[root@x ~]# timedatectl
Local time: Sun 2022-04-17 11:15:48 CST
Universal time: Sun 2022-04-17 03:15:48 UTC
RTC time: Sun 2022-04-17 11:15:48
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: yes
DST active: n/a
# 筛选式查看在亚洲S开的上海可用时区:
[root@x ~]# timedatectl list-timezones | grep -E "Asia/S.\*"
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
# 设置当前系统为Asia/Shanghai上海时区:
[root@x ~]# timedatectl set-timezone Asia/Shanghai
# 修改日期时间(可选,主节时钟源无法同步,可以先关闭NTP同步)
timedatectl set-ntp false
timedatectl set-time "2022-04-17 15:50:20"
# 开启 NTP
timedatectl set-ntp true
#设置完时区后,强制同步下系统时钟:
[root@x ~]# chronyc -a makestep
200 OK
三、防火墙设置
因NTP使用123/UDP端口协议,所以允许NTP服务即可。但是我一般都会把防火墙和selinux禁止。
# 查看防火墙状态
[root@x ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
# 启动防火墙
[root@x ~]# systemctl start firewalld.service
# 防火墙内放行NTP服务
[root@x ~]# firewall-cmd --add-service=ntp --permanent
success
# reload才能生效
[root@x ~]# firewall-cmd --reload
success
内部访问一般直接关闭防火墙
[root@x ~]# systemctl stop firewalld
[root@x ~]# systemctl disalbe firewalld
四、配置Chrony
1.服务器端配置
将主节点设置为内部NTP Server,编辑“/etc/chrony.conf”文件,如有公网的情况,可以配置阿里云的ntp服务地址作为源 。
ntp1.aliyun.com
授时中心参考
- 210.72.145.44 国家授时中心
- ntp.aliyun.com 阿里云
- s1a.time.edu.cn 北京邮电大学
- s1b.time.edu.cn 清华大学
- s1c.time.edu.cn 北京大学
- s1d.time.edu.cn 东南大学
- s1e.time.edu.cn 清华大学
- s2a.time.edu.cn 清华大学
- s2b.time.edu.cn 清华大学
- s2c.time.edu.cn 北京邮电大学
- s2d.time.edu.cn 西南地区网络中心
- s2e.time.edu.cn 西北地区网络中心
- s2f.time.edu.cn 东北地区网络中心
- s2g.time.edu.cn 华东南地区网络中心
- s2h.time.edu.cn 四川大学网络管理中心
- s2j.time.edu.cn 大连理工大学网络中心
- s2k.time.edu.cn CERNET桂林主节点
- s2m.time.edu.cn 北京大学
- ntp.sjtu.edu.cn 202.120.2.101 上海交通大学
master01作为服务端,当前节点IP地址为172.16.24.65,网段是172.16.24.0/24,配置详情如下