温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

时间服务和chrony

发布时间:2020-07-20 08:46:07 来源:网络 阅读:252 作者:90001丶冷眸 栏目:系统运维

时间服务和chrony

多主机协作工作是,各个主机的时间同步很总要,时间不一致会造成很多重要应用的故障,如:加密协议,日志,集群等,利用NTP协议使网络中的各个计算机时间达到同步。目前NTP协议属于运维基础架构中必备的基本服务之一。

时间同步实现:ntp,chrony

ntp

ntp将系统时间和世界协调时UTC同步,精度在局域网内可达到0.1ms,在互联网上绝大多数的地方精度可以达到1-50ms。目前CentOS6上所使用的就是ntp服务。

实验

ntp的部署

实验说明

主机A从互联网上的主机同步时间并作为局域网内的时间服务器使用,主机B自动去向主机A同步时间

实验准备

准备A、B两台主机
时间服务和chrony

将主机B时间调慢
[root@HostB ~]# date -s "-10 days"
Sun Apr  7 10:50:51 CST 2019
[root@HostB ~]# date
Sun Apr  7 10:50:58 CST 2019
查看下主机A时间
[root@HostA ~]# date
Wed Apr 17 10:53:35 CST 2019

一、将主机A设置为时间服务器

1.修改/etc/ntp

[root@HostA ~]# vim /etc/ntp.conf 
...
#restrict default kod nomodify notrap nopeer noquery        #将文件中的此行注释,或者修改为下面行
restrict default kod nomodify                               
...
#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 172.22.0.1 iburst                                    #将时间服务器指向外部的时间服务器。
...

2.将主机A与外网的时间服务器同步

[root@HostA ~]# ntpdate 172.22.0.1
18 Apr 10:27:53 ntpdate[3825]: adjust time server 172.22.0.1 offset 0.004437 sec

3.启动ntp服务,将ntp服务设置为开机启动

[root@HostA ~]# service ntpd start
Starting ntpd:                                             [  OK  ]
[root@HostA ~]# chkconfig ntpd on

二、修改主机B配置文件修改为自动和主机A同步时间

1.修改配置文件,将时间服务器指向主机A

#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 192.168.73.140 iburst                                #添加此行

2.启动服务

[root@HostB ~]# service ntpd start
Starting ntpd:                                             [  OK  ]
[root@HostB ~]# date                                        #由于ntp服务同步速度较慢,需要很长一段时间才能同步使劲按
Mon Apr  8 10:34:43 CST 2019
[root@HostB ~]# service ntpd restart
Shutting down ntpd:                                        [  OK  ]
Starting ntpd:                                             [  OK  ]
[root@HostB ~]# date                                        #再次重启服务,此时时间已经自动同步。
Thu Apr 18 10:34:54 CST 2019

CentOS7 chrony

实验

chrony部署

实验说明:

此处以刚才配置的主机A为互联网中的时间服务器,主机7A从主机A同步时间并作为局域网内的时间服务器使用,主机7B自动去向主机7A同步时间

实验准备

7A、7B两台主机
时间服务和chrony

一、配置时间服务器

1.修改主机7A配置文件修改/etc/chrony.conf

[root@7a ~]# vim /etc/chrony.conf
...
server 192.168.73.140 iburst    #添加此行指向网络中的时间服务器
...
allow 192.168.73.0/24           #添加当自己为时间服务器时允许访问的网段
...
local stratum 10                #此行前的注释去掉

2.启动chronyd服务,并设置为开机启动

[root@7a ~]# systemctl start chronyd.service
[root@7a ~]# systemctl enable chronyd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.

二、配置局域网中的服务器,将时间服务器指向为7A

1.修改配置文件

[root@7b ~]# vim /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 192.168.73.150 iburst                #添加此行

2.启动chrony服务,并设置为开机自动启动

[root@7b ~]# systemctl start chronyd
[root@7b ~]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.

3.查看时间同步情况

[root@7b ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 192.168.73.150                5   6   177    31    +50us[  +77us] +/-  218ms
[root@7b ~]# 
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI