centos7安装chronyd服务方式
作者:奈小奈 时间:2022-06-17 15:04:19
centos7安装chronyd服务
一、双节点部署:
ip | 主机名 |
---|---|
192.168.100.10 | controller |
192.168.100.20 | compute |
二、配置时间同步
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
来源:https://blog.csdn.net/weixin_45849657/article/details/109286138
标签:centos7,安装,chronyd服务
0
投稿
猜你喜欢
浅析SpringBoot打包上传到docker并实现多实例部署(IDEA版)
2023-11-03 14:34:58
Windows中合理设置共享文件夹访问权限
2008-12-08 14:51:00
马化腾:腾讯看走眼的很多 不止YouTube
2008-01-13 19:09:00
关键词选择攻略 处理好冷热门及专业关系
2009-02-18 12:21:00
织梦首页调用随机文章定时更新教程
2012-03-06 20:31:23
如何提高网站广告收益之主题篇
2008-04-05 13:44:00
加速WordPress
2010-03-21 13:38:00
Windows服务器组件安全设置策略
2009-10-18 07:41:00
用经验告诉你如何通过百度主题推广
2009-03-02 18:04:00
微软新版Exchange 2010程序开发完工 进度超前
2009-10-12 11:26:00
使用 Apache Superset 可视化 ClickHouse 数据的两种方法
2023-06-21 08:09:45
网站统计给了我们什么?
2007-12-16 19:25:00
百度“有啊”借乡村信息化大赛热卖土特产
2009-10-27 16:10:00
Google AdSense广告优化之“广告位置”
2007-12-06 18:37:00
Win2003IIS6.0+PHP521+Mysql5037+Zend326+phpmyadmin210环境配置图文教程
2007-08-16 09:43:00
foreman ubuntu16 快速安装
2023-08-05 04:07:50
Dedecms与Ecms的战争已入白热化
2007-11-22 23:56:00
消息称谷歌Chrome操作系统本周三正式发布
2009-11-16 08:18:00
搜索引擎优化红火 甄别网站优化行骗手段
2009-02-25 16:09:00
一个草根站长对漂亮女友的期望(搞笑)
2007-08-14 16:39:00