tiddlers: 选择时区
This data as json
title | meta | text | revision |
---|---|---|---|
选择时区 | {"created": "20230406102555594", "creator": "root", "tags": ["Linux"], "title": "\u9009\u62e9\u65f6\u533a", "modified": "20230406103142925", "modifier": "root", "type": "text/vnd.tiddlywiki"} | 目的:方便系统之间的同步,如搭建hadoop系统,需要各服务器之间时间误差极小。 ```bash # 查看当前系统时间 $ date -R Sat, 26 Dec 2020 03:21:28 +0000 #不是东八区 ``` 不是目标时区,需要调整。 !! tzselect方法 ```bash $ tzselect # 选择亚洲 Asia,确认之后选择中国(China),最后选择北京(Beijing) Here is that TZ value again, this time on standard output so that you can use the /usr/bin/tzselect command in shell scripts: Asia/Shanghai #防止系统重启后时区改变 $ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime # 检查结果 $ date -R Sat, 26 Dec 2020 11:27:48 +0800 ``` 在修改时间以后,修改硬件CMOS的时间 ``` $ hwclock --systohc #非常重要,如果没有这一步的话,后面时间还是不准 ``` !! timedatectl方法 ```bash $ timedatectl Local time: Sat 2020-12-26 11:38:22 CST Universal time: Sat 2020-12-26 03:38:22 UTC RTC time: Sat 2020-12-26 03:38:21 Time zone: Europe/London (CST, +0800) Network time on: yes NTP synchronized: yes RTC in local TZ: no ``` “Time zone”显示不对,实际系统已经更改。再执行以下`timedatectl set-timezone Asia/Shanghai`,这样显示就正常了。要切换回 UTC 时区,只需运行`timedatectl set-timezone UTC`。 !!! 使用timedatectl控制时间同步 大多数网络时间同步都由网络时间协议守护程序或ntpd处理。此服务连接到其他NTP服务器池,为其提供持续且准确的时间更新。 Ubuntu的默认安装现在使用timesyncd而不是ntpd。timesyncd连接到相同的时间服务器,并以大致相同的方式工作,但更轻量级,更集成systemd和Ubuntu的低级别工作。 * `System clock synchronized: yes`表示时间已成功同步 * `systemd-timesyncd.service active: yes`表示已启用并运行timesyncd 如果timesyncd未激活,使用timedatectl将其打开:`sudo timedatectl set-ntp on` > 如果要使用ntp的话,需要关闭timesyncd,即timedatectl set-ntp no. | 1 |