实现多台主机进行时间同步
NTP时间同步服务NTP是网络时间协议(Network Time Protocol)它是用来同步网络中各个计算机的时间的协议。在机房中各个服务器的时间务必要保持一致同时也要和实际的时间保持一致2、使用的工具Chrony 是一个高效的时间同步服务主要用于在 Linux 系统中通过网络时间协议 (NTP) 进行时间同步轻量高效启动速度快适合间歇性连接到网络的设备。低延迟在不需要长期运行的环境中快速同步时间。适配性强支持虚拟化环境如虚拟机和频繁断网的设备3、安装# 安装yum install chrony-y systemctlstartchronyd systemctl enable chronyd 查看状态: systemctl status chronyd4、修改配置文件/etc/chrony.conf# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #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 # 这里配置 公共时间源 #pool ntp.org.cn iburst #pool ntp.aliyun.com iburst #pool ntp.tencent.com iburst # 这里是配置把当前主机当作时间服务器使用的 其他机器同步本机器的时间 local stratum 10 # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. # 配置那些网段可以访问 可以配置多个 allow 192.168.30.0/24 # Serve time even if not synchronized to a time source. #local stratum 10 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking时间服务器机器配置完后需要重启服务systemctl restart chronyd systemctl status chronyd主机需要关闭防火墙 或者开放对应端口firewall-cmd--add-servicentp--permanent firewall-cmd--reload firewall-cmd--list-all5、其他机器 修改NTP核心配置文件vim/etc/chrony.conf 修改以下内容#注释掉原有的pool 新增一个pool (文件头部)#pool 2.centos.pool.ntp.org iburstpool192.168.88.101 iburst :x 保存退出 然后重启 systemctl restart chronyd systemctl status chronyd 查看是否生效 chronyc sources6、如何两台主机时间差距较大直接强制一步对齐 忽略平滑渐变直接把本机时间跳转到和 Master 一致时差多大都会一次性修正。chronyc -a makestep7、为什么时差大默认不会自动跳变chrony 默认 makestep 1.0 3只有前 3 次启动、时差超过 1 秒才会跳变正常运行时差很大时它怕业务乱序日志、数据库时间戳错乱只会缓慢一点点校准。离线内网环境时差巨大必须手动 makestep。

相关新闻