个人工具

UbuntuHelp:UbuntuTime

来自Ubuntu中文

Oneleaf讨论 | 贡献2007年5月24日 (四) 14:34的版本 (新页面: {{From|https://help.ubuntu.com/community/UbuntuTime}} {{Languages|UbuntuHelp:UbuntuTime}} == Ubuntu Time Management == This page gives useful information about the way that Ubuntu manage...)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索


Ubuntu Time Management

This page gives useful information about the way that Ubuntu manages time by changing the timezone, setting up synchronization using Network Time Protocol(NTP), and adjusting servers.

Changing the Time Zone

This section shows you how to accomplish this task using either the Graphical User Interface(GUI) or by using the command line(terminal).

Using the GUI

Perhaps the most user friendly way to change the time zone of your Ubuntu system is to use the Graphical User Interface(GUI). 0. Right-click on your clock, and choose Adjust Time & Date, it will open up the following window: UbuntuTime?action=AttachFile&do=get&target=ntpgui0.png 0. Click on the currently selected time zone to bring up the selection map. UbuntuTime?action=AttachFile&do=get&target=ntpgui5.png 0. Click in the general area of your location on the time zone map, the map will zoom in. UbuntuTime?action=AttachFile&do=get&target=ntpgui7.png 0. Select the closest city then choose Close UbuntuTime?action=AttachFile&do=get&target=ntpgui8.png

Using the Command Line(terminal)

Using the command line, you can use tzconfig. The man page of this tool has a good explanation on how to set time on a Linux system, how it differs from other systems, and what you have to consider when using computers in a network.

0. Open a terminal window by going to Applications>Accessories>Terminal 0. `tzconfig` 0. Follow the directions in the terminal.

Time Synchronization using NTP

This page describes methods for automatically keeping your computer's time accurate. This is extremely useful for servers, and is also recommended for desktop machines.

Network Time Protocol(NTP) is a TCP/IP protocol for synchronizing time over a network connection. Basically a client requests the current time from a server, and then uses the servers response to set its own clock.

Beyond this simple description, there is a lot of complexity. There are multiple tiers of NTP servers, with the tier one NTP servers connected to atomic clocks (often via GPS), and tier two and three servers spreading the load of actually handling requests across the internet. The client software is a lot more complex than you might think as it has to factor communication delays, and adjust the time in a way that does not affect the other processes that run on the system. Luckily all that complexity is hidden from the user.

Using the GUI

This is how to enable NTP time synchronization using the GUI(Graphical User Interface). 0. Right click on the clock in the top right hand corner of your desktop and select Adjust Date & Time UbuntuTime?action=AttachFile&do=get&target=ntpgui0.png 0. You may have to enter your password to continue. UbuntuTime?action=AttachFile&do=get&target=ntpgui1.png 0. Select the configuration option Keep synchronized with Internet servers UbuntuTime?action=AttachFile&do=get&target=ntpgui2.png 0. You may get a dialog box informing you that NTP support has to be installed. UbuntuTime?action=AttachFile&do=get&target=ntpgui3.png 0. After selecting Install NTP Support it will download the needed files. UbuntuTime?action=AttachFile&do=get&target=ntpgui4.png 0. You are now finished and you can click Close or you can customize the NTP servers(default is ntp.ubuntu.com) that your computer uses to synchronize with by choosing Select Servers. UbuntuTime?action=AttachFile&do=get&target=ntpgui5.png


Command Line ntpdate

Ubuntu comes with ntpdate as standard, and will run it once at boot time to set up your time according to Ubuntu's NTP server. However, a system's clock is likely to drift considerably between reboots if the time between reboots is long. In that case it makes sense to correct the time occasionally. The easiest way to do this is to get cron to run it every day. With your favorite editor, create a file `/etc/cron.daily/ntpdate` containing:

sudo ntpdate ntp.ubuntu.com

Make sure that you make this new file executable:

sudo chmod 755 /etc/cron.daily/ntpdate

Command Line ntpd

ntpdate is a bit of a blunt instrument as it can only adjust the time once a day in one big correction. The ntp daemon ntpd is far more subtle as it calculates the drift of your system clock and continuously adjusts it in small increments. Using ntpd there are no large corrections that could lead to inconsistent logs for instance. The cost is a little processing power and memory, but for a modern system this is negligible.

To set up ntpd pre Ubuntu 7.04:

sudo apt-get install ntp-simple

To setup ntpd in versions of Ubuntu 7.04 and higher

sudo apt-get install ntp


Changing NTP Time Servers

In both cases above, your system will use Ubuntu's NTP server at `ntp.ubuntu.com` by default. This is OK, but you might want to use several servers to increase accuracy and resilience, and you may want to use time servers that are geographically closer to you.

Using the GUI

0. Right click on the clock in the top right hand corner of your desktop and select Adjust Date & Time UbuntuTime?action=AttachFile&do=get&target=ntpgui0.png 0. You may have to enter your password to continue. UbuntuTime?action=AttachFile&do=get&target=ntpgui1.png 0. Select Configure Servers UbuntuTime?action=AttachFile&do=get&target=ntpgui5.png 0. Enable the box next to your choice of server(s) or add your own. UbuntuTime?action=AttachFile&do=get&target=ntpgui6.png


ntpdate

Change the contents of `/etc/cron.daily/ntpdate` to:

ntpdate ntp.ubuntu.com pool.ntp.org

ntpd

Change the contents of `/etc/ntp.conf` to include additional server lines:

ntp.ubuntu.com
server pool.ntp.org

You may notice `pool.ntp.org` in the examples above. This is a really good idea which uses round-robin DNS to return an NTP server from a pool, spreading the load between several different servers. Even better, they have pools for different regions - I am in New Zealand, so I use `nz.pool.ntp.org` instead of `pool.ntp.org`. Look at http://www.pool.ntp.org/ for more details.

You can also Google for NTP servers in your region, and add these to your configuration. To test that a server works, just type `sudo ntpdate ntp.server.name` and see what happens.

Multiple Boot Systems Time Conflicts

Operating systems store and retrieve the time in the hardware clock located on your motherboard so that it can keep track of the time even when the system does not have power. Most current operating systems(Linux/Unix/Mac) store the time on the hardware clock as UTC/GMT, though some systems(MSWindows) store the time on the hardware clock as the 'local' time. This causes problems in a dual boot system as both systems view the hardware clock differently.

It is usually better to have the hardware clock as UTC because then you don't need to change the hardware clock when Daylight Savings Time(DST) begins or ends as UTC does not have DST.

Make Windows use UTC

To make MS Windows calculate the time from the hardware clock as UTC. Create a file named https://help.ubuntu.com/community/UbuntuTime?action=AttachFile&do=get&target=WindowsTimeFixUTC.reg with the following contents and then double click on it to merge the contents with the registry:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
"RealTimeIsUniversal"=dword:00000001

Make Linux use 'Local' time

To make your Ubuntu system read the hardware clock as 'local' 0. edit /etc/default/rcS 0. add or change the following section

# Set UTC=yes if your system clock is set to UTC (GMT)
UTC=no