集群中使用chronyc同步时间

在集群之中,有些服务器之间的时间需要同步,但并不是所有机器可以直接连外网,这时可以用Chrony工具解决。 解决方法是将其中一台设为时间服务器,然后其它服务器和这台时间服务器同步即可。具体步骤如下:

一. 配置时间服务器

Chrony时间服务器上:

 

[root@openstack-controller ~]# systemctl stop firewalld
[root@openstack-controller ~]# systemctl disalbe firewalld
[root@openstack-controller ~]# yum -y install chrony
[root@openstack-controller ~]# vim /etc/chrony.conf
[root@openstack-controller ~]# grep "^server" /etc/chrony.conf 
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
server openstack-controller  iburst    # 添加本机(openstack-controller为本机主机名,需要客户端可解析,也可以使用ip)
[root@openstack-controller ~]# grep -n  "^allow" /etc/chrony.conf   #允许其他节点可以连接
26:allow 192.168.1.0/24 
[root@openstack-controller ~]# timedatectl set-timezone Asia/Shanghai #设置时区
[root@openstack-controller ~]# systemctl enable chronyd.service  #启动 NTP 服务并将其配置为随系统启动 
[root@openstack-controller ~]# systemctl start chronyd.service

 

其它节点:

 

[root@openstack-compute ~]# systemctl stop firewalld
[root@openstack-compute ~]# systemctl disable firewalld
[root@openstack-compute ~]# yum  -y install chrony
[root@openstack-compute ~]# grep -n "^server" /etc/chrony.conf #编辑/etc/chrony.conf 文件并注释所有内容。添加本地Chrony时间服务器
3:server  openstack-controller iburst
[root@openstack-compute ~]# timedatectl set-timezone Asia/Shanghai #设置时区
[root@openstack-compute ~]# systemctl enable chronyd.service #启动 NTP 服务并将其配置为随系统启动 
[root@openstack-compute ~]# systemctl start chronyd.service

 

二、验证操作:

Chrony时间服务器上执行这个命令:

[root@openstack-controller ~]# chronyc sources 
210 Number of sources = 5
MS Name/IP address         Stratum Poll Reach LastRx Last sample       # Name/IP address 列的内容显示NTP服务器的主机名或者IP地址         
===============================================================================
^- 61-216-153-106.HINET-IP.>     3   6    17    13  +1752us[-1466us] +/-   63ms
^- time5.aliyun.com              2   6    17    12   -925us[-4142us] +/-   16ms
^- ntp7.flashdance.cx            2   6    17    11    +15ms[  +15ms] +/-  194ms
^? dns1.synet.edu.cn             0   6     0     -     +0ns[   +0ns] +/-    0ns
^* openstack-controller          3   6    17     7    +14us[-7821ns] +/-   18ms

其他节点执行相同命令:

[root@openstack-compute ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* openstack-controller          4   6    17    23   -744us[-6012us] +/-   33ms

注意:chrony和ntpd类似firewalld和iptables,不能共存,同时只能存在一个服务运行。

其他一些时间同步命令:

查看日期时间及NTP状态:# timedatectl
查看和配置时区:# timedatectl list-timezones;# timedatectl set-timezone Asia/Shanghai
修改日期时间:# timedatectl set-time "2015-01-21 11:50:00"(可以只修改其中一个)
开启NTP:# timedatectl set-ntp true/flase
查看chrony服务所有conf配置文件分布# rpm -ql chrony |grep conf
检查chrony服务配置文件所在# rpm -qc chrony
查看chrony安装情况# rpm -qi chrony
检查ntp安装情况# yum search ntp |grep ^ntp.x86_64或# yum search ntp(列出所有ntp相关包)

 

posted @ 2018-01-30 11:44  百衲本  阅读(17391)  评论(0编辑  收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码