快速学会使用linux上的chrony服务

一、安装与配置

#yum -y install chrony
#systemctl enable chronyd
#systemctl start chronyd
chrony.conf 默认配置#
Chrony的配置文件是/etc/chrony.conf
# 使用 pool.ntp.org 项目中的公共服务器。以server开,理论上想添加多少时间服务器都可以。
# 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

# 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。
# 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

# 指定日志文件的目录。
# Specify directory for log files.
logdir /var/log/chrony

# 选择日志文件要记录的信息。
# Select which information is logged.
#log measurements statistics tracking

二、使用

1.服务端配置#
chrony.conf 修改两处

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server s1a.time.edu.cn iburst
server ntp.aliyun.com iburst

# Allow NTP client access from local network.
allow 192.168.0.0/16
设置开机启动,重启服务

systemctl enable chronyd
systemctl restart chronyd
# 查看时间同步状态
timedatectl status
# 开启网络时间同步
timedatectl set-ntp true
2.客户端配置#
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
设置开机启动,重启服务

systemctl enable chronyd
systemctl restart chronyd
查看时间同步状态

timedatectl status
开启网络时间同步

timedatectl set-ntp true
三、chronyc 命令#
查看 ntp_servers

chronyc sources -v
查看 ntp_servers 状态

1.
chronyc sourcestats -v
1.
查看 ntp_servers 是否在线

1.
chronyc activity -v
1.
查看 ntp 详细信息

1.
chronyc tracking -v
1.
强制同步下系统时钟

chronyc -a makestep
四、timedatectl 命令#
查看日期时间、时区及 NTP 状态

1.
timedatectl
1.
查看时区列表

1.
timedatectl list-timezones
1.
timedatectl list-timezones |  grep  -E "Asia/S.*"
1.
修改时区

1.
timedatectl set-timezone Asia/Shanghai
1.
修改日期时间(可以只修改其中一个)

1.
timedatectl set-time "2021-04-15 15:50:20"
1.
开启 NTP

1.

timedatectl set-ntp true/flase


1.
五、授时中心#
210.72.145.44 国家授时中心
ntp.aliyun.com 阿里云
s1a.time.edu.cn 北京邮电大学
s1b.time.edu.cn 清华大学
s1c.time.edu.cn 北京大学
s1d.time.edu.cn 东南大学
s1e.time.edu.cn 清华大学
s2a.time.edu.cn 清华大学
s2b.time.edu.cn 清华大学
s2c.time.edu.cn 北京邮电大学
s2d.time.edu.cn 西南地区网络中心
s2e.time.edu.cn 西北地区网络中心
s2f.time.edu.cn 东北地区网络中心
s2g.time.edu.cn 华东南地区网络中心
s2h.time.edu.cn 四川大学网络管理中心
s2j.time.edu.cn 大连理工大学网络中心
s2k.time.edu.cn CERNET桂林主节点
s2m.time.edu.cn 北京大学
ntp.sjtu.edu.cn 202.120.2.101 上海交通大学
六、系统时钟与硬件时钟之间同步#

```powershell
设置硬件时钟
-w,--systohc

1.
hwclock -w
1.
设置系统时钟
-s, --hctosys

1.
hwclock -s
1.
修改配置文件方式
vim /etc/sysconfig/ntpd
将系统时间写入BIOS,与 hwclock -w 效果相同

1.at 配置在5小时后,将 “This is a at task” 写入 root家目录中的at_test文件中

[root@Myliunx ~]# at now + 5 hours
warning: commands will be executed using /bin/sh
at> echo "This is a at task" > /root/at_test
at> <EOT>
job 1 at Sun Jul 24 03:22:00 2022

2.crontab配置,每周六,周日 9点半,14点 提醒我上RHCE课 写入root家目录中的cron_test文件中

[root@Myliunx ~]# crontab -e
crontab: installing new crontab
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值