时间服务:chrony

为什么需要时间同步?

如果web服务没有时间同步很有可能会出一些莫名奇妙的的问题,比如我就曾遇到过一则案例,服务器刚刚申请完CA证书,但是在客户端访问时却提示证书过期。

由其在虚拟化的环境当中,虚拟化的系统的CPU是虚拟的,时钟震荡不精确,为什么会不精确呢?因为虚拟化的CPU并不是真正的CPU,就容易产生误差。

什么时候需要时间同步?

为了避免后期维护起来麻烦,我们最好在安装系统的时候就做好时间同步。

常用的时间同步服务有:ntp和chrony,centos7以上都采用chrony,主要是因为其比较精确。无论客户端还是服务器都要安装chrony做为后台进程。

做客户端时

//#默认都配置好了时间服务器,只要启动服务,并且网络通配,chrony就可自行向配置文件里面指向的时间服务器同步时间,默认指向centos的官方时间服务器。
yum
install chrony rpm -qc chrony /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
//默认是侦听udp323端口
[root@tomcat2 ~]# systemctl start chronyd [root@tomcat2 ~]# systemctl enable chronyd [root@tomcat2 ~]# ss -unlp | grep 323 UNCONN 0 0 127.0.0.1:323 *:* users:(("chronyd",pid=8572,fd=5)) UNCONN 0 0 ::1:323 :::* users:(("chronyd",pid=8572,fd=6))

如何确定时间已经正确同步了呢?通过chronyc sources命令可得知,如下所示:

[root@tomcat2 ~]# chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample              
===============================================================================
^? sv1.ggsrv.de                  2   6     1     3    -44ms[  -44ms] +/-  132ms
^* time5.aliyun.com              2   6    77     4   +215us[+1227us] +/-   10ms
^- ntp7.flashdance.cx            2   6    77     3  -2098us[-2098us] +/-  204ms
^- time.cloudflare.com           3   6    77     4    +11ms[  +11ms] +/-  124ms

做时间服务器时

做服务器时,只要将配置文件的allow字段打开即可。

#allow 192.168.0.0/16
原文地址:https://www.cnblogs.com/yizhangheka/p/11610258.html