clock.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-scripts-clock" revision="systemd">
  8. <?dbhtml filename="clock.html"?>
  9. <title>配置系统时钟</title>
  10. <indexterm zone="ch-scripts-clock">
  11. <primary sortas="d-clock">clock</primary>
  12. <secondary>configuring</secondary></indexterm>
  13. <!--para>This section discusses how to configure the
  14. <command>systemd-timedated</command> system service, which configures
  15. system clock and timezone.</para-->
  16. <para>本节讨论如何配置 <command>systemd-timedated</command> 系统服务,
  17. 它的作用是配置系统时钟和时区。</para>
  18. <!--para>If you cannot remember whether or not the hardware clock is set to UTC,
  19. find out by running the <userinput>hwclock localtime show</userinput>
  20. command. This will display what the current time is according to the hardware
  21. clock. If this time matches whatever your watch says, then the hardware clock is
  22. set to local time. If the output from <command>hwclock</command> is not local
  23. time, chances are it is set to UTC time. Verify this by adding or subtracting
  24. the proper amount of hours for the timezone to the time shown by
  25. <command>hwclock</command>. For example, if you are currently in the MST
  26. timezone, which is also known as GMT -0700, add seven hours to the local
  27. time.</para-->
  28. <para>如果您不确定您的硬件时钟是否设置为 UTC ,运行
  29. <userinput>hwclock --localtime --show</userinput> 命令,
  30. 它会显示硬件时钟给出的当前时间。如果这个时间和您的手表显示的一致,
  31. 则说明硬件时钟被设定为本地时间。相反,如果 <command>hwclock</command>
  32. 输出的时间不是本地时间,则硬件时钟很可能被设定为 UTC 时间。
  33. 根据您的时区,在 <command>hwclock</command>
  34. 显示的时间上加减对应的小时数,进行进一步的验证。
  35. 例如,如果您现在处于莫斯科时区,即 GMT -0700 ,在本地时间上加
  36. 7 小时,再进行比较。</para>
  37. <note><title>译注</title>
  38. <para>Windows 会将硬件时钟设定为本地时间,因此如果您要同时安装
  39. Windows 和 Linux,就要将 Linux (包括 LFS 和其他发行版)
  40. 配置为使用本地时间,除非能够忍受 Windows 和 Linux 显示的不同时间
  41. (必有一个是错误的)。
  42. </para>
  43. </note>
  44. <para><command>systemd-timedated</command> 读取
  45. <filename>/etc/adjtime</filename>,
  46. 并根据其内容将硬件时钟设定为 UTC 或本地时间。</para>
  47. <para>如果您的硬件时钟设置为本地时间,以下列内容创建
  48. <filename>/etc/adjtime</filename> 文件:</para>
  49. <screen role="nodump"><userinput>cat &gt; /etc/adjtime &lt;&lt; "EOF"
  50. <literal>0.0 0 0.0
  51. 0
  52. LOCAL</literal>
  53. EOF</userinput></screen>
  54. <para>如果 <filename>/etc/adjtime</filename> 在初次引导时不存在,
  55. <command>systemd-timedated</command> 会假设硬件时钟使用 UTC ,
  56. 并据此调整该文件。</para>
  57. <para>您也可以使用 <command>timedatectl</command> 工具告诉
  58. <command>systemd-timedated</command> 您的硬件时钟是 UTC 还是本地时间:
  59. </para>
  60. <screen role="nodump"><userinput>timedatectl set-local-rtc 1</userinput></screen>
  61. <para><command>timedatectl</command> 也能修改系统时间和时区。</para>
  62. <para>如果要修改系统时间,执行以下命令:</para>
  63. <screen role="nodump"><userinput>timedatectl set-time YYYY-MM-DD HH:MM:SS</userinput></screen>
  64. <para>硬件时钟也会同时被更新。</para>
  65. <para>要修改当前时区,执行以下命令:</para>
  66. <screen role="nodump"><userinput>timedatectl set-timezone TIMEZONE</userinput></screen>
  67. <para>您可以通过运行以下命令查看可用的时区列表:</para>
  68. <screen role="nodump"><userinput>timedatectl list-timezones</userinput></screen>
  69. <note><para>注意 <command>timedatectl</command> 命令只能用于
  70. systemd 引导的系统。</para></note>
  71. <note><title>译注</title>
  72. <para><command>timedatectl</command> 在 chroot 环境中无法使用,
  73. 如果需要重新设定系统时间,要么在引导进入 LFS 系统后再使用
  74. <command>timedatectl</command> ,要么使用传统的
  75. <command>hwclock --set</command> 命令。系统时区可以按照
  76. <xref linkend="conf-zone"/> 中的方法设置。</para>
  77. </note>
  78. <sect2>
  79. <title>网络时钟同步</title>
  80. <!--para>Starting with version 213, systemd ships a daemon called
  81. <command>systemd-timesyncd</command> which can be used to
  82. synchronize the system time with remote NTP servers.</para-->
  83. <para>从版本 213 开始,systemd 附带了一个名为
  84. <command>systemd-timesyncd</command> 的守护进程,
  85. 可以用于将系统时间与远程 NTP 服务器同步。</para>
  86. <!--para>The daemon is not intended as a replacement for the well
  87. established NTP daemon, but as a client only implementation
  88. of the SNTP protocol which can be used for less advanced
  89. tasks and on resource limited systems.</para-->
  90. <para>该守护进程没有被设计为替代现有的 NTP 守护进程,
  91. 而是一个仅仅实现了 SNTP 协议的客户端,可以被用于一些不太复杂的任务,
  92. 或是资源紧张的系统。</para>
  93. <!--para>Starting with systemd version 216, the
  94. <command>systemd-timesyncd</command> daemon is enabled by
  95. default. If you want to disable it, issue the following
  96. command:</para-->
  97. <para>从 systemd 版本 216 开始,<command>systemd-timesyncd</command>
  98. 守护进程被默认启用。如果希望禁用它,执行以下命令:</para>
  99. <screen role="nodump"><userinput>systemctl disable systemd-timesyncd</userinput></screen>
  100. <para>可以在 <filename>/etc/systemd/timesyncd.conf</filename>
  101. 中修改 <command>systemd-timesyncd</command> 使用的服务器。</para>
  102. <note><title>译注</title>
  103. <para><ulink url="http://www.ntp.org.cn/pool.php"/>
  104. 提供了 NTP 服务器的域名和 IP 地址列表。</para>
  105. </note>
  106. <!--para>Please note that when system clock is set to Local Time,
  107. <command>systemd-timesyncd</command> won't update hardware
  108. clock.</para-->
  109. <para>注意,当系统时钟设定为本地时间时,
  110. <command>systemd-timesyncd</command> 不会更新硬件时钟。</para>
  111. </sect2>
  112. </sect1>