centos7安装chronyd服务方式

 更新时间:2023年06月02日 09:45:17   作者:奈小奈  
这篇文章主要介绍了centos7安装chronyd服务方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

centos7安装chronyd服务

一、双节点部署:

ip主机名
192.168.100.10controller
192.168.100.20compute

二、配置时间同步

1、双节点安装chrony服务(这里是使用本地的软件包进行yum安装)

[root@controller ~]# yum install -y chrony
[root@compute ~]# yum install -y chrony

2、controller修改chrony服务配置文件(在/etc/chrony.conf目录下)

[root@controller ~]# vi /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          //添加#号
server controller iburst                      //添加这一行
# 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 all                              //去掉#号
# 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

3、compute 修改chrony配置文件

[root@compute ~]# vi /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
server 192.168.100.10 iburst                   //添加这一行
# 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.0.0/16
# 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

4、双节点重启服务,并设置开机自启

[root@controller ~]# systemctl restart chronyd && systemctl enable chronyd
[root@compute ~]# systemctl restart chronyd && systemctl enable chronyd

5、controller开启ntp同步

[root@controller ~]# timedatectl set-ntp true

6、双节点执行chronyc sources命令,结果中存在以^*开头的行,则同步成功

[root@controller ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* controller                   10   6   377    27   +186ns[-8404ns] +/-   17us
[root@compute ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* controller                   10   6    17    34  -4280ns[  -13us] +/-  328us

Centos7使用chronyd进行时钟同步

最近要做阿里云迁移 IDC 机房,整理下 Linux 运维基线,简单记录,以备后用~

安装

# 默认已经安装
$ yum install -y chrony

配置文件

$ cat /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.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
# 阿里
server ntp.aliyun.com
# 腾讯
server time1.cloud.tencent.com
server time2.cloud.tencent.com
server time3.cloud.tencent.com
server time4.cloud.tencent.com
server time5.cloud.tencent.com
# 苹果
server time.asia.apple.com
# 微软
server time.windows.com
# 其他
server cn.ntp.org.cn
# 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.0.0/16
# 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 start chronyd
# 开机启动
$ systemctl enable chronyd
# 查看当前状态
$ systemctl status chronyd
# 查看亚洲时区
$ timedatectl list-timezones | grep Asia
# 设置时区
$ timedatectl set-timezone Asia/Shanghai

验证服务

# 查看现有的时间服务器
$ chronyc sources -v
# 查看时间服务器状态
$ chronyc sourcestats -v
# 显示时钟同步相关参数
$ chronyc tracking
# 查看当前时区及时间
$ timedatectl 

手动同步时间

# 使用 ntpdate 同步时间
$ ntpdate ntp.aliyun.com
# chronyd 未启动时,如下命令同步时间
$ chronyd -q 'server pool.ntp.org iburst'
# chronyd 启动时,使用如下命令同步时间
$ chronyc -a 'burst 4/4' && sleep 10 && chronyc -a makestep

手动设置时间

# date 设置时间
$ date -s '2021-06-03 19:00:00'
# 关闭 ntp 同步后,才可以使用 timedatectl 进行时间设置
$ timedatectl set-ntp false
# 设置日期和时间
$ timedatectl set-time '2021-06-03 19:00:00'
# 设置日期
$ timedatectl set-time '2021-06-03'
# 设置时间
$ timedatectl set-time '19:00:00'
# 设置完成后,再开启
$ timedatectl set-ntp true

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • Linux下如何永久修改主机名的方法步骤

    Linux下如何永久修改主机名的方法步骤

    这篇文章主要介绍了Linux下如何永久修改主机名的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-01-01
  • linux服务器CPU飙高排查分析

    linux服务器CPU飙高排查分析

    系统cpu飙高,尤其对于后端人员来说,其实应该学会排查,这样也算是综合能力的体现;那么当出现了cpu严重飙高的时候怎么排查呢?感兴趣的朋友跟随小编一起看看吧
    2023-01-01
  • centos7 esxi6.7模板实际应用详解

    centos7 esxi6.7模板实际应用详解

    这篇文章主要介绍了centos7 esxi6.7模板实际应用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-01-01
  • Apache使用.htaccess 屏蔽恶意 User Agent(防蜘蛛)

    Apache使用.htaccess 屏蔽恶意 User Agent(防蜘蛛)

    这篇文章主要介绍了Apache使用.htaccess 屏蔽恶意 User Agent(防蜘蛛),需要的朋友可以参考下
    2016-07-07
  • htaccess Rewrite中文编码问题解决方法

    htaccess Rewrite中文编码问题解决方法

    Seo方面对于中文地址或则文件名,在Google好像比重要大一些,今天正好看到andy的文章.转下,以后也许会用.
    2008-10-10
  • LNMP下防跨站、跨目录的安全设置,仅支持PHP5.3.3以上版本

    LNMP下防跨站、跨目录的安全设置,仅支持PHP5.3.3以上版本

    LNMP一键安装包下存在跨站和跨目录的问题,跨站和跨目录影响同服务器/VPS上的其他网站,最近看PHP 5.3,在5.3.3以上已经增加了HOST配置,可以起到防跨站、跨目录的问题
    2012-10-10
  • Linux中nohup与&的用法和区别详解

    Linux中nohup与&的用法和区别详解

    这篇文章主要给大家介绍了关于Linux中nohup与&的用法和区别的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者使用Linux具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-10-10
  • linux查看用过的命令方法总结

    linux查看用过的命令方法总结

    在本篇文章里小编给大家分享了关于linux怎么查看用过的命令的具体方法和步骤,需要的朋友们参考下。
    2019-06-06
  • Centos7之如何设置定时任务

    Centos7之如何设置定时任务

    这篇文章主要介绍了Centos7之如何设置定时任务问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-06-06
  • Linux中一对多配置日志服务器的详细步骤

    Linux中一对多配置日志服务器的详细步骤

    这篇文章主要介绍了Linux中一对多配置日志服务器步骤教程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-07-07

最新评论