mirror of
https://github.com/LCTT/LFS-BOOK-7.7-systemd.git
synced 2026-01-14 00:49:09 +00:00
116 lines
6.2 KiB
HTML
116 lines
6.2 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<title> 7.5. Configuring the system clock </title>
|
||
<link rel="stylesheet" type="text/css" href="../stylesheets/lfs.css">
|
||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||
<link rel="stylesheet" href="../stylesheets/lfs-print.css"
|
||
type="text/css" media="print">
|
||
</head>
|
||
<body class="lfs" id="lfs-7.7-systemd">
|
||
<div class="navheader">
|
||
<h4> Linux From Scratch - Version 7.7-systemd </h4>
|
||
<h3> 第 7 章. 基本系统配置 </h3>
|
||
<ul>
|
||
<li class="prev"> <a accesskey="p" href="symlinks.html"
|
||
title="Creating Custom Symlinks to Devices">上一页</a>
|
||
<p> 创建自定义符号连接设备 </p>
|
||
</li>
|
||
<li class="next"> <a accesskey="n" href="console.html"
|
||
title="Configuring the Linux Console">下一页</a>
|
||
<p> Configuring the Linux Console </p>
|
||
</li>
|
||
<li class="up"> <a accesskey="u" href="chapter07.html"
|
||
title="Chapter 7. Basic System Configuration">返回</a>
|
||
</li>
|
||
<li class="home"> <a accesskey="h" href="../index.html"
|
||
title="Linux From Scratch - Version 7.7-systemd">主页</a> </li>
|
||
</ul>
|
||
</div>
|
||
<div class="sect1" xml:lang="en" lang="en">
|
||
<h1 class="sect1"> <a id="ch-scripts-clock"
|
||
name="ch-scripts-clock"></a>7.5. 配置系统时间 </h1>
|
||
<p> 本节将会讨论如何配置 <span class="command"><strong>systemd-timedated</strong></span>
|
||
系统服务,包括配置系统时间和时区。</p>
|
||
<p> 如果你不确定是否将硬件时钟设置为 UTC,可以通过 <strong class="userinput"><code>hwclock
|
||
|
||
--localtime --show</code></strong>
|
||
来查看。这将根据硬件时钟显示当前的时间。如果实现和手表的时间相同,应该是设置为本地时间了;如果时间不一致,应该是设置为 UTC
|
||
了。通过增减数小时,可以确定你所在时区。</p>
|
||
<p> <span class="command"><strong>systemd-timedated</strong></span>
|
||
读取 <code class="filename">/etc/adjtime</code>,且取决于该文件的内容是本地时间还是
|
||
UTC。</p>
|
||
<p> <br>
|
||
如果想要将硬件时钟设置为本地时间,使用以下命令建立 <code class="filename">/etc/adjtime </code>:</p>
|
||
<pre class="userinput"><kbd class="command">cat > /etc/adjtime << "EOF"
|
||
<code class="literal">0.0 0 0.0
|
||
0
|
||
LOCAL</code>
|
||
EOF</kbd>
|
||
</pre>
|
||
<p> If <code class="filename">/etc/adjtime</code> isn't present
|
||
at first boot, <span class="command"><strong>systemd-timedated</strong></span>
|
||
will assume that hardware clock is set to UTC and adjust the
|
||
file according to that. </p>
|
||
<p> You can also use the <span class="command"><strong>timedatectl</strong></span>
|
||
utility to tell <span class="command"><strong>systemd-timedated</strong></span>
|
||
if your hardware clock is set to UTC or local time: </p>
|
||
<pre class="userinput"><kbd class="command">timedatectl set-local-rtc 1</kbd>
|
||
</pre>
|
||
<p> <span class="command"><strong>timedatectl</strong></span> can
|
||
also be used to change system time and time zone. </p>
|
||
<p> To change your current system time, issue: </p>
|
||
<pre class="userinput"><kbd class="command">timedatectl set-time YYYY-MM-DD HH:MM:SS</kbd>
|
||
</pre>
|
||
<p> Hardware clock will also be updated accordingly. </p>
|
||
<p> To change your current time zone, issue: </p>
|
||
<pre class="userinput"><kbd class="command">timedatectl set-timezone TIMEZONE</kbd>
|
||
</pre>
|
||
<p> You can get list of available time zones by running: </p>
|
||
<pre class="userinput"><kbd class="command">timedatectl list-timezones</kbd>
|
||
</pre>
|
||
<div class="admon note"> <img alt="[Note]"
|
||
src="../images/note.png">
|
||
<h3> Note </h3>
|
||
<p> Please note that <span class="command"><strong>timedatectl</strong></span>
|
||
command can be used only on a system booted with systemd. </p>
|
||
</div>
|
||
<div class="sect2" xml:lang="en" lang="en">
|
||
<h2 class="sect2"> 7.5.1. 网络时间同步</h2>
|
||
<p> 从版本号 213 的 systemd 开始,包括了一个名为<strong> </strong><span
|
||
class="command"><strong>systemd-timesyncd</strong></span>
|
||
的守护进程,将能够和远程的 NTP 服务器同步时间。 </p>
|
||
<p> 此守护进程并不是为了取代已有的 NTP 服务,而是作为 SNTP
|
||
协议的实现客户端,它可用于更高级的任务和资源有限的系统。</p>
|
||
<p> 从版本号 216 的 systemd 开始,<span class="command"><strong>systemd-timesyncd</strong></span>
|
||
守护进程默认启用,如果需要禁用,执行以下命令:</p>
|
||
<pre class="userinput"><kbd class="command">systemctl disable systemd-timesyncd</kbd>
|
||
</pre>
|
||
<p> <code class="filename">/etc/systemd/timesyncd.conf</code>
|
||
文件也可以通过<strong> </strong><span class="command"><strong>systemd-timesyncd</strong></span>
|
||
同步来更改 NTP 服务。</p>
|
||
<p> 需要注意的是,当使用本地时间作为系统时间时,<span class="command"><strong>systemd-timesyncd</strong></span>
|
||
无法更新硬件时钟。 </p>
|
||
</div>
|
||
</div>
|
||
<div class="navfooter">
|
||
<ul>
|
||
<li class="prev"> <a accesskey="p" href="symlinks.html"
|
||
title="Creating Custom Symlinks to Devices">上一页</a>
|
||
<p> 创建自定义符号连接设备 </p>
|
||
</li>
|
||
<li class="next"> <a accesskey="n" href="console.html"
|
||
title="Configuring the Linux Console">下一页</a>
|
||
<p> Configuring the Linux Console </p>
|
||
</li>
|
||
<li class="up"> <a accesskey="u" href="chapter07.html"
|
||
title="Chapter 7. Basic System Configuration">返回</a>
|
||
</li>
|
||
<li class="home"> <a accesskey="h" href="../index.html"
|
||
title="Linux From Scratch - Version 7.7-systemd">主页</a> </li>
|
||
</ul>
|
||
</div>
|
||
</body>
|
||
</html>
|