服务器之间时间同步(Chrony)

服务器A:192.168.2.203

服务器B:192.168.2.205

让A作为主服务器去外网同步时间,或者直接以A服务器时间为主,让其他服务器去同步

 

第一步:安装chrony

yum -y install chrony

 其对应的文件有:rpm -ql chrony

第二步:配置chrony.conf文件

vi /etc/chrony.conf

A服务器配置:

# 配置时间服务器,以server开头,理论上添加多少时间服务器都可以。
server ntp.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst server ntp.aliyun.com minpoll 4 maxpoll 10 iburst server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst server ntp1.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst server ntp10.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst server ntp11.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst server ntp12.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst server ntp2.aliyun.com minpoll 4 maxpoll 10 iburst server 192.168.2.203 iburst rtcsync #启用内核时间与 RTC 时间同步 (自动写回硬件)。 makestep 1.0 3 #如果系统时钟的偏移量大于1秒,则允许系统时钟在前三次更新中步进。 allow 192.168.2.0/24 #表示允许这个网段的其他主机链接 local stratum 10 #即使未与时间源同步,也提供服务时间

 

 

  

 

B服务器配置:

server 192.168.2.203 iburst
rtcsync
makestep 1.0 3
allow 192.168.2.0/24
local stratum 10

  

假如还有C服务器:(这样即使其中一个挂了,另外两台服务器之间时间也会同步)

server 192.168.2.203 iburst
server 192.168.2.205 iburst
rtcsync
makestep 1.0 3
local stratum 10

  

第三步:启动服务

systemctl start chronyd

systemctl enable chronyd

测试 

在A,B,C服务器上输入

chronyc sources

 

^*  代表连接成功。

^?  代表未连接成功。可以尝试关闭防火墙,然后重启chrony。

^- 代表通过组合算法计算后排除的源

 

 

其他命令:

#重启
systemctl restart chronyd 

# 查看日期时间、时区及NTP状态
timedatectl

# 查看时区列表
timedatectl list-timezones

# 修改时区
timedatectl set-timezone Asia/Shanghai

# 修改日期时间
timedatectl set-time "2015-01-21 11:50:00"

# 设置完时区后,强制同步下系统时钟
chronyc -a makestep

# 硬件时间默认为UTC
 timedatectl set-local-rtc 1

# 启用或关闭NTP时间自动同步
 timedatectl set-ntp yes|flase

  

 

posted @ 2022-05-07 16:16  风子磊  阅读(975)  评论(0编辑  收藏  举报