CSE lesson2 chrony服务器
CSE lesson2 chrony服务器
timedatectl命令
NTP(network time protocal)网络时间协议,时钟服务器同步时间的时候会使用到该协议进行时间同步。
#关闭/开启时间同步服务
[root@localhost ~]# timedatectl set-ntp 0/1
#设置时间(必须关闭时间同步服务才能设置时间))
[root@localhost ~]#timedate set-time "2011-11-11 11:56:5"
#开启/关闭硬件时间同步
[root@localhost ~]# timedatectl set-local-rtc 1/0
#查看命令chrony产生了那些文件 当下我们只关心其中的配置文件和服务程序文件
[root@localhost ~]# rpm -ql chrony
/etc/chrony.conf #chronyd服务程序的配置文件
...
/usr/lib/systemd/system/chronyd.service #chronyd服务程序
...
#关闭了chronyd服务程序 NTP service立刻变为inactive状态
[root@localhost ~]#systemctl stop chronyd.service
/etc/chrony.conf配置文件
# 表示时间同步的服务地址(可以是ip地址,也可以是ur1地址)
# poo1 表示是时间服务集群
# poo1 可以修改为 server 表示从急群中挑选一台作为时钟同步服务器
# iburst 表示chrony如果重启会立即同步时间
pool 2.rhel.pool.ntp.org iburst
实验1从远程服务器同时间
# 修改配置文件
[root@localhost ~]# timedatectl set-ntp 0
[root@localhost ~]# timedatectl set-time "2011-11-11 11:11:11"
[root@localhost ~]# vim /etc/chrony.conf
------
server ntp.aliyun.com iburst
------
# 重启chronyd服务
[root@localhost ~]# systemctl restart chronyd.service
[root@localhost ~]# timedatectl
Local time: 五 2025-03-28 20:04:31 CST
Universal time: 五 2025-03-28 12:04:31 UTC
RTC time: 五 2011-11-11 03:17:38
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
[root@localhost ~]#
chronyc
# 查看客户端与服务器的同步状态
[root@client ~]# chronyc sources -v
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| / 'x' = may be in error, '~' = too variable, '?' = unusable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* server.shared 10 6 377 38 -9967ns[ -15us] +/- 250us
# MS:同步状态 *表示同步成功 ?失败
# Name/IP address:时钟服务器的域名或ip地址
# Stratum:时钟源的层级
# Poll: 两次同步之间时间间隔如果是6表示 没2**6秒同步一次时间
# Reach: 最近八次的同步状态如果是 377=>11 111 111 即八次同步都是成功的
# LastRx: 最近一次同步是多少秒前