Centos8 修改时区和配置服务器时间

2,351 阅读1分钟

Centos7以上支持chrony时间同步配置,ntp在Centos8上已经不再支持了 chrony相比ntp时间同步配置更简单,更高效 timedatectl 是 centos7+上的一个时间客户端工具 服务器上没有chrony的可以使用 yum -y install chrony 或 ndf -y install chrony 进行安装

一. 修改chrony.conf配置文件

vim /etc/chrony.conf
# 注释掉 # pool 2.centos.pool.ntp.org iburst
# 添加 server ip iburst ,可以配置多个例如:
server ntp.aliyun.com iburst
# 这里server配置可以是网易云/腾讯云/阿里云等时间服务器
# 下面的那些可以适当修改也可以不用去修改

二. 重启 chronyd 服务

systemctl restart chronyd.service

三. 设置Asia/Shanghai时区

timedatectl set-timezone Asia/Shanghai

或者

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

四. 设置开机自启动

# 开机自启动
systemctl enable chronyd