Linux中设置时区
- 列出所有的时区
timedatectl list-timezones
- 替换成你的时区 Europe/Berlin
sudo timedatectl set-timezone Europe/Berlin
以下是如何在 CentOS 8 中配置 chrony 来同步网络时间的步骤:
安装 chrony
首先,确保你的系统已经安装了 chrony。你可以使用以下命令来安装它:
bash sudo dnf install chrony 启动并启用 chrony 服务 安装完成后,启动 chrony 服务并设置它在系统启动时自动运行: bash sudo systemctl start chronyd sudo systemctl enable chronyd 配置 chrony 默认情况下,chrony 应该已经配置好了使用公共 NTP 服务器。但是,你可以通过编辑 /etc/chrony.conf 文件来更改配置。 例如,你可以添加或更改 NTP 服务器列表。以下是一个示例配置: # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). 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 # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is too large. makestep 1.0 3 # Enable kernel RTC synchronization. rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. allow 192.168.0.0/16 # Serve time even if not synchronized to a time source. local stratum 10 # Specify the key identifier to use with the ntpdc utility. #keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking
4.检查状态
你可以使用以下命令来检查 chrony 的状态:
如果一切正常,你应该会看到你的 NTP 服务器列表以及它们的状态(通常是 ^* 表示当前正在使用的服务器)。
chronyc sources -v
- 同步时间
你可以使用以下命令来手动同步时间(尽管 chrony 通常会自动进行):
sudo chronyc -a makestep
- 查看时间同步状态
#chronyc tracking #或者 #timedatectl status
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性