CentOS8上集群时间的同步

需求:

我们以前可能接触过时间同步的软件:ntp或者说是ntpdate,但是如果我们在CentOS8上面进行主机之间时间的同步,想要下载ntpdate可能会发现没有这个包:

[root@kvm yum.repos.d]# yum -y install ntp ntpdate
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Last metadata expiration check: 0:07:08 ago on Thu 12 Mar 2020 08:32:10 AM EDT.
No match for argument: ntp
No match for argument: ntpdate
Error: Unable to find a match: ntp ntpdate

原因:

经过查询我们发现CentOS8已经用chrony来替换了ntpdate来完成时间的同步,总体上来说,chrony更为简单,比如,客户端安装好chrony之后,并不需要设定crontab任务来定时同步时间,它是自动的。

安装chrony:

1. 用yum安装chrony

[root@kvm yum.repos.d]# yum -y install chrony
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
CentOS-8 - AppStream                                                                                                                                                                       1.0 MB/s | 6.5 MB     00:06    
CentOS-8 - Extras                                                                                                                                                                          364  B/s | 2.1 kB     00:05    
CentOS-8 - Base - mirrors.aliyun.com                                                                                                                                                       1.5 MB/s | 5.0 MB     00:03    
Package chrony-3.5-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

这里因为我已经完整的安装好了,所以不会显示下载的细节了。

2. 配置chrony

chrony的配置文件是/etc/chrony.conf

[root@kvm etc]# vim  /etc/chrony.conf

只需要在第一行中换成
server 需要同步机器的ip	iburst

3. 保存退出,重启chronyd服务即可

[root@kvm etc]# systemctl restart chronyd
[root@kvm etc]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-03-12 09:04:51 EDT; 14h ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 9146 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 9140 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 9144 (chronyd)
    Tasks: 1 (limit: 9643)
   Memory: 1.8M
   CGroup: /system.slice/chronyd.service
           └─9144 /usr/sbin/chronyd
           .....

4. 在服务器端也要打开chronyd服务才可以(安装之后)

[root@server etc]# systemctl start chronyd

5. 在客户端输入命令进行同步

[root@kvm etc]# chronyc sourcestats -v

6. 查看是否同步成功

[root@kvm etc]# timedatectl

7. 至此我们就完成了集群之间时间的同步,在多机的集群依然是适用的,特别是企业内部无法访问外部网络时间服务器且非常需要时间同步的情况下是非常必要的。

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值