ntp客户端安装脚本
# 安装ntp客户端
sudo dnf install chrony
# 配置
pool 2.centos.pool.ntp.org iburst给这一行加注释
sudo sed -i 's/^pool 2.centos.pool.ntp.org iburst/#&/' /etc/chrony.conf
# 添加3个阿里云NTP服务器
# echo -e "server ntp1.aliyun.com iburst\nserver ntp2.aliyun.com iburst\nserver ntp3.aliyun.com iburst" | sudo tee -a /etc/chrony.conf
# 添加ntp服务器
echo -e "server 192.168.10.91 iburst" | sudo tee -a /etc/chrony.conf
# 重启 chronyd 服务以应用更改
sudo systemctl restart chronyd
# 设置开机自启
sudo systemctl enable chronyd
# 检查 NTP 同步状态
# chronyc tracking
其中192.168.10.91是ntp服务器ip
测试
更改错误的时间时间:引号不能忘记
date -s '2022-11-11 11:11:11'
查看时间
输入下面命令
date
刚开始看到的应该是上面设置的时间
过几分钟之后就能看到时间同步成正确的时间了

本文详细介绍了如何在Linux系统中使用脚本安装和配置NTP客户端Chrony,包括添加阿里云NTP服务器、设置开机自启,以及检查时间同步状态的过程。
2万+

被折叠的 条评论
为什么被折叠?



