InfrawireInfrawire 标志文档

将时区配置为巴黎

本指南将教您如何将 VPS 服务器的时区配置为巴黎时区(Europe/Paris),以便系统时间正确同步。

📋 先决条件

  • 具有 root 或 sudo 访问权限的 VPS 服务器
  • 活动的 SSH 连接
  • Ubuntu/Debian(命令适用于这些发行版)

🔍 检查当前时区

在更改时区之前,检查当前配置的是哪个时区:

Bash
1# 显示当前时区 2timedatectl 3 4# 或简单地 5date 6 7# 仅显示时区 8timedatectl | grep "Time zone"

🌍 方法 1:使用 timedatectl(推荐)

列出可用时区

Bash
1# 列出所有可用时区 2timedatectl list-timezones 3 4# 过滤以查找欧洲时区 5timedatectl list-timezones | grep Europe 6 7# 专门搜索巴黎 8timedatectl list-timezones | grep Paris

配置巴黎时区

Bash
1# 将时区设置为 Europe/Paris 2sudo timedatectl set-timezone Europe/Paris 3 4# 验证更改已应用 5timedatectl

您应该看到类似的内容:

               Local time: Mon 2026-01-11 14:30:00 CET
           Universal time: Mon 2026-01-11 13:30:00 UTC
                 RTC time: Mon 2026-01-11 13:30:00
                Time zone: Europe/Paris (CET, +0100)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

🔧 方法 2:使用符号链接(传统方法)

如果 timedatectl 不可用,您可以使用传统方法:

步骤 1:识别时区

Bash
1# 列出可用时区 2ls /usr/share/zoneinfo/Europe/ 3 4# 验证 Europe/Paris 存在 5ls -la /usr/share/zoneinfo/Europe/Paris

步骤 2:创建符号链接

Bash
1# 备份旧时区(可选) 2sudo mv /etc/localtime /etc/localtime.backup 3 4# 创建指向巴黎时区的符号链接 5sudo ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime 6 7# 验证更改 8date

步骤 3:更新 /etc/timezone 文件(Debian/Ubuntu)

Bash
1# 编辑时区文件 2echo "Europe/Paris" | sudo tee /etc/timezone 3 4# 验证内容 5cat /etc/timezone

✅ 验证

检查当前时间

Bash
1# 显示带时区的日期和时间 2date 3 4# 显示所有时间信息 5timedatectl 6 7# 显示 UTC 时间 8date -u

验证时区正确

Bash
1# 验证符号链接 2ls -la /etc/localtime 3 4# 应显示类似内容: 5# /etc/localtime -> /usr/share/zoneinfo/Europe/Paris

🕐 夏令时(DST)管理

Europe/Paris 时区自动处理夏令时(CET/CEST):

  • CET(中欧时间) : UTC+1(冬季)
  • CEST(中欧夏令时) : UTC+2(夏季)

系统每年自动调整两次时间。

验证夏令时

Bash
1# 显示详细信息 2timedatectl 3 4# 验证更改日期 5zdump -v Europe/Paris | grep 2024

🔄 NTP 同步

为了保持时间准确,确保启用 NTP 同步:

检查 NTP 状态

Bash
1# 检查 NTP 是否活动 2timedatectl status 3 4# 如果 NTP 不活动,启用它 5sudo timedatectl set-ntp true

安装和配置 NTP(如需要)

Bash
1# 安装 NTP 2sudo apt update 3sudo apt install ntp -y 4 5# 检查状态 6systemctl status ntp 7 8# 在启动时启用 NTP 9sudo systemctl enable ntp 10sudo systemctl start ntp

🎯 其他法国时区

如果您需要另一个法国时区:

Bash
1# 本土(巴黎) 2sudo timedatectl set-timezone Europe/Paris 3 4# 安的列斯(瓜德罗普、马提尼克) 5sudo timedatectl set-timezone America/Martinique 6 7# 法属圭亚那 8sudo timedatectl set-timezone America/Cayenne 9 10# 留尼汪 11sudo timedatectl set-timezone Indian/Reunion 12 13# 新喀里多尼亚 14sudo timedatectl set-timezone Pacific/Noumea 15 16# 法属波利尼西亚 17sudo timedatectl set-timezone Pacific/Tahiti

📝 有用命令

在不同时区显示时间

Bash
1# 本地时间(巴黎) 2date 3 4# UTC 时间 5date -u 6 7# 特定时区的时间 8TZ='America/New_York' date 9TZ='Asia/Tokyo' date

手动修改时间(不推荐)

Warning: 如果 NTP 处于活动状态,不建议手动修改时间,因为 NTP 会自动将其重置为正确时间。

Bash
1# 修改时间(格式:YYYY-MM-DD HH:MM:SS) 2sudo timedatectl set-time "2026-01-11 14:30:00" 3 4# 仅修改日期 5sudo timedatectl set-time "2026-01-11" 6 7# 仅修改时间 8sudo timedatectl set-time "14:30:00"

🔍 故障排除

问题:时间不同步

Bash
1# 检查 NTP 状态 2timedatectl status 3 4# 如果禁用,启用 NTP 5sudo timedatectl set-ntp true 6 7# 检查与 NTP 服务器的连接 8sudo ntpq -p

问题:时区不更改

Bash
1# 验证 timedatectl 工作 2sudo timedatectl set-timezone Europe/Paris 3 4# 验证符号链接 5ls -la /etc/localtime 6 7# 如有必要,手动重新创建链接 8sudo rm /etc/localtime 9sudo ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime

问题:重启后时间不正确

Bash
1# 启用 NTP 以自动同步 2sudo timedatectl set-ntp true 3 4# 安装 chrony(NTP 替代方案) 5sudo apt install chrony -y 6sudo systemctl enable chrony 7sudo systemctl start chrony

✅ 最佳实践

  • 使用 timedatectl : 这是现代且推荐的方法
  • 启用 NTP : 以保持时间自动同步
  • 定期检查 : 系统时间对日志和 SSL 证书很重要
  • 不要手动修改 : 让 NTP 处理同步

🆘 故障排除

验证完整配置

Bash
1# 验证所有时间信息 2timedatectl 3 4# 检查配置文件 5cat /etc/timezone 6ls -la /etc/localtime 7 8# 检查 TZ 环境变量 9echo $TZ

完全重置

如果您遇到问题,可以重置:

Bash
1# 启用 NTP 2sudo timedatectl set-ntp true 3 4# 重新定义时区 5sudo timedatectl set-timezone Europe/Paris 6 7# 验证 8timedatectl 9date

📚 其他资源

❓ 常见问题

问:CET 和 CEST 有什么区别?
答:CET(中欧时间)是冬季时间(UTC+1),CEST(中欧夏令时)是夏季时间(UTC+2)。系统每年自动更改两次。

问:我应该使用 Europe/Paris 还是直接使用 CET?
答:始终使用 Europe/Paris,因为它自动包含夏令时规则。不要直接使用 CET/CEST。

问:时间是否随夏令时自动更改?
答:是的,如果您使用 Europe/Paris,系统会在夏令时转换期间自动调整时间。

问:如何检查 NTP 是否正常工作?
答:使用 timedatectl status 并验证 "NTP service" 是 "active" 且 "System clock synchronized" 是 "yes"。

问:我可以在 VPS 上使用另一个时区吗?
答:是的,在 timedatectl set-timezone 命令中用所需时区替换 Europe/Paris