一、时区配置与验证
服务器时区设置是时间管理的基础步骤,可通过以下命令完成:
- 查看当前时区:
timedatectl
或date +"%Z"
- 列出可用时区:
timedatectl list-timezones
- 设置新时区(如亚洲上海):
sudo timedatectl set-timezone Asia/Shanghai
修改后建议重启时间相关服务:systemctl restart systemd-timesyncd
以应用变更。
二、NTP服务安装与同步
跨平台NTP服务配置流程如下:
- Debian/Ubuntu系统:
- 安装服务:
sudo apt install ntp
- 编辑配置文件:
/etc/ntp.conf
添加server pool.ntp.org
- 安装服务:
- CentOS/RHEL系统:
- 安装服务:
sudo yum install ntp
- 启动服务:
systemctl enable --now ntpd
- 安装服务:
配置完成后,建议开放防火墙123端口:firewall-cmd --add-service=ntp --permanent
。
三、自动校准与状态检查
实现时间自动同步的关键步骤:
- 启用NTP同步:
timedatectl set-ntp yes
- 验证同步状态:
ntpq -p
查看NTP节点状态timedatectl status
显示时钟源信息
对于需要更高精度的场景,可改用chronyd
服务:sudo apt install chrony
并配置/etc/chrony.conf
。
本文由阿里云优惠网发布。发布者:编辑员。禁止采集与转载行为,违者必究。出处:https://aliyunyh.com/449532.html
其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。