linux 服务器时钟同步设置

您所在的位置:网站首页 二元一次方程组加减消元法计算题及过程答案 linux 服务器时钟同步设置

linux 服务器时钟同步设置

2024-07-06 12:25:58| 来源: 网络整理| 查看: 265

linux 服务器时钟同步设置 1 背景2 简介3 环境4 安装及配置5 配置使用5.1 服务端配置5.1.1 修改配置5.1.2 开启同步5.1.3 防火墙策略配置 5.2 客户端配置5.2.1 修改配置5.2.2 开启同步 5.3 chronyc命令

1 背景

多台服务器集中化部署完毕后服务器时间的快慢,久而久之肆意变换,有几台服务器就产生几个时间,对业务系统的数据的时效产生了一定的影响。 我们都知道时钟同步可以使用外网服务器,但是在内网内不能连接外网的时候也需要时钟同步,那怎么进行呢? 很多项目中会使用内网时间服务器作为时钟源,然后让其他机器都来同步这台机器即可。 针对linux系统下ntp服务和chrony服务都是作为服务器时钟同步服务,他们之间都可以互相进行同步。但是NTP与chrony不能同时存在,只能用其中一个。因为在日常工作中主要操作的系统环境为RHEL7,RHEL7中默认使用chrony作为时间服务器,也支持NTP,需要额外安装。所以本文就以chrony为重点进行展开介绍。

2 简介

Chrony是一个开源的自由软件,是网络时间协议 NTP 的客户端和服务器软件。它能让计算机保持系统时钟与时钟服务器(NTP)同步,因此让你的计算机时间保持精确,Chrony也可以作为服务端软件为其他计算机提供时间同步服务。Chrony由两个程序组成,分别是chronyd和chronyc。chronyd是一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算机增减时间的比率,并对此进行补偿。chronyc提供了一个用户界面,用于监控性能并进行多样化的配置。它可以在chronyd实例控制的计算机上工作,也可以在一台不同的远程计算机上工作。

NTP 是网络时间协议(Network Time Protocol)的简称,通过 udp 123 端口进行网络时钟同步。

3 环境 项目版本说明CentOS7.6.1810操作系统版本 4 安装及配置

使用管理员账号操作

yum -y install chrony systemctl start chronyd systemctl enable chronyd

chrony.conf 默认配置

vi /etc/chrony.conf

# 使用 pool.ntp.org 项目中的公共服务器。 # 以server开,理论上想添加多少时间服务器都可以。 #pool pool.ntp.org iburst server ntp.ntsc.ac.cn iburst server ntp1.aliyun.com iburst #server cn.pool.ntp.org iburst # 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。 # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # 如果系统时钟的偏移量大于1秒,则允许系统时钟在前三次更新中步进。 # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # 启用实时时钟(RTC)的内核同步。 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # 通过使用 hwtimestamp 指令启用硬件时间戳 # 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 # 指定 NTP 客户端地址,以允许或拒绝连接到扮演时钟服务器的机器 # 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 # 指定包含 NTP 身份验证密钥的文件。 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Get TAI-UTC offset and leap seconds from the system tz database. #leapsectz right/UTC # 指定日志文件的目录。 # Specify directory for log files. logdir /var/log/chrony # 选择日志文件要记录的信息。 # Select which information is logged. #log measurements statistics tracking 5 配置使用 5.1 服务端配置 5.1.1 修改配置

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 s2c.time.edu.cn iburst server ntp.aliyun.com iburst # Allow NTP client access from local network. allow 192.168.8.0/16 5.1.2 开启同步 systemctl enable chronyd systemctl restart chronyd # 查看时间同步状态 timedatectl status # 开启网络时间同步 timedatectl set-ntp true

在这里插入图片描述

5.1.3 防火墙策略配置

网络时间协议通过 udp 123 端口进行网络时钟同步

# 开启防火墙 firewall-cmd --zone=public --add-port=123/udp --permanent #或者 firewall-cmd --zone=public --add-service=ntp --permanent firewall-cmd --reload 5.2 客户端配置 5.2.1 修改配置

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 192.168.8.5 iburst # Allow NTP client access from local network. allow 192.168.8.5 5.2.2 开启同步 systemctl enable chronyd systemctl restart chronyd # 查看时间同步状态 timedatectl status # 开启网络时间同步 timedatectl set-ntp true

至此,时钟同步配置已经完成,可以针对客户端设置一些其他时间,对配置的时间同步进行验证。 后续介绍一些chrony命令信息。

5.3 chronyc命令 # 查看 ntp_servers chronyc sources -v

在这里插入图片描述

# 查看 ntp_servers 状态 chronyc sourcestats -v

在这里插入图片描述

# 查看 ntp_servers 是否在线 chronyc activity -v

在这里插入图片描述

# 查看 ntp 详细信息 chronyc tracking -v

在这里插入图片描述 修改时区

# 查看日期时间、时区及 NTP 状态 timedatectl # 查看时区列表 timedatectl list-timezones timedatectl list-timezones | grep -E "Asia/Shanghai" # 修改时区 timedatectl set-timezone Asia/Shanghai # 修改日期时间(可以只修改其中一个) timedatectl set-time "2022-07-14 16:59:20" # 开启 NTP timedatectl set-ntp true/flase

系统时钟与硬件时钟同步

# 设置硬件时钟 # -w,--systohc hwclock -w # 设置系统时钟 # -s, --hctosys hwclock -s # 修改配置文件方式 vim /etc/sysconfig/ntpd # 将系统时间写入BIOS,与 hwclock -w 效果相同 SYNC_HWCLOCK=yes

https://chrony.tuxfamily.org/



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭