Linux软件安装[003]:Chrony服务
环境描述
- 共使用三台虚拟机进行测试:一台Mester 两台Salve
- 主要修改文件:/etc/chrony.conf
- 监听端口为:123和323
- 基础环境配置:
- 关闭firewalld。
- 关闭SElinux。
服务介绍
-
Chrony是redhat开发的,它是网络时间协议的 (NTP) 的另一种实现。
-
centos7/rhel7默认的时间同步工具。Chrony可以同时做为ntp服务的客户端和服务端。
-
默认安装完后有两个程序chronyd和chronyc 。
- chronyd是一个在系统后台运行的守护进程。
- chronyc是用来监控chronyd性能和配置其参数程序。
一、安装准备工作(所有主机都需要执行)
1、关闭firewalld,关闭开机自启。
#关闭firewalld
systemctl stop firewalld
#关闭开机自启
systemctl disable firewalld
#查看firewalld状态
firewall-cmd --state
2、关闭SElinux
#关闭selinux
sed -i 's/(^SELINUX)=(.*)/\1=disabled/p' /etc/selinux/config
#查看selinux状态
getenforce
二、安装
1、安装chrony服务(所有需要同步时间的主机)
yum -y install chrony
2、修改server端配置文件
1)注释掉以下内容。
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
2)在上述注释内容之后本地时钟服务器(本机)。
#作为chrony的服务端可以将自己的IP或主机名 添加到此处,注意:添加主机名,需要client可以解析。
server 10.0.0.31 iburst
3)添加允许同步到本服务器的网段。
#在此注释下添加
# Allow NTP client access from local network.
allow 10.0.0.0/24
4)在外部时钟服务器无法使用时,将本机的时间同步给其他的服务器。
#取消此行注释
local stratum 10
3、修改client端配置文件
1)注释掉以下内容。
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
2)在上述注释内容之后添加局域网内时钟服务器。
#配置好的server端的IP地址
server 10.0.0.31 iburst
4、启动并开机自启chrony服务
systemctl enable --now chronyd
三、验证时钟同步
1)方法1
#局域网情况下:server和client显示的IPaddress应该向同
chronyc sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
=============================================================================
^* 10.0.0.31 10 6 37 4 -24ns[-2954ns] +/- 5511ns
MS:显示为*说明同步成功;显示为?说明没有同步。
2)方法2
timedatectl
Local time: Mon 2021-08-02 14:58:45 CST
Universal time: Mon 2021-08-02 06:58:45 UTC
RTC time: Mon 2021-08-02 06:58:45
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
此选项状态为:NTP synchronized: yes 说明同步成功。
3)查看默认端口是监听状态
netstat -nupl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:123 0.0.0.0:* 1308/chronyd
udp 0 0 127.0.0.1:323 0.0.0.0:* 1308/chronyd

浙公网安备 33010602011771号