~kim0/serverguide/serverguide-review-ch19

« back to all changes in this revision

Viewing changes to build/serverguide/C/NTP.html

  • Committer: Matthew East
  • Date: 2011-05-03 07:11:18 UTC
  • Revision ID: mdke@ubuntu.com-20110503071118-081aatibsr9k2yqy
Add files from ubuntu-docs natty branch, trim to use only those necessary for serverguide

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
<html xmlns="http://www.w3.org/1999/xhtml">
 
4
  <head xmlns="http://www.w3.org/1999/xhtml">
 
5
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
6
    <title xmlns="">Time Synchronisation with NTP</title>
 
7
    <link rel="stylesheet" href="../../libs/ubuntu-book.css" type="text/css" />
 
8
    <link rel="home" href="index.html" title="Ubuntu Server Guide" />
 
9
    <link rel="up" href="networking.html" title="Chapter 4. Networking" />
 
10
    <link rel="prev" href="dhcp.html" title="Dynamic Host Configuration Protocol (DHCP)" />
 
11
    <link rel="next" href="remote-administration.html" title="Chapter 5. Remote Administration" />
 
12
    <link rel="copyright" href="legal.html" title="Credits and License" />
 
13
  </head>
 
14
  <body>
 
15
    <div id="round">
 
16
      <img id="topcap" alt="" src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-top.png" />
 
17
      <div id="layout" class="container clear-block">
 
18
        <script xmlns="" src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script>
 
19
        <script xmlns="" type="text/javascript">
 
20
_uacct = "UA-1018242-8";
 
21
urchinTracker();
 
22
</script>
 
23
        <div id="header">
 
24
          <div id="logo-floater">
 
25
            <h1>
 
26
              <a href="https://help.ubuntu.com" title="Ubuntu Documentation">
 
27
                <img alt="Ubuntu" id="logo" src="https://help.ubuntu.com/htdocs/ubuntunew/img/logo.png" />
 
28
              </a>
 
29
            </h1>
 
30
          </div>
 
31
          <noscript>
 
32
            <form action="http://www.google.com/cse" id="cse-search-box">
 
33
              <div>
 
34
                <input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />
 
35
                <input type="hidden" name="ie" value="UTF-8" />
 
36
                <input type="text" name="q" size="27" />
 
37
                <input type="submit" name="sa" value="Search" />
 
38
              </div>
 
39
            </form>
 
40
          </noscript>
 
41
          <script>
 
42
 document.write('<form action="https://help.ubuntu.com/search.html" id="cse-search-box">');
 
43
 document.write('  <div>');
 
44
 document.write('    <input type="hidden" name="cof" value="FORID:9" />');
 
45
 document.write('    <input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />');
 
46
 document.write('    <input type="hidden" name="ie" value="UTF-8" />');
 
47
 document.write('    <input type="text" name="q" size="27" />');
 
48
 document.write('    <input type="submit" name="sa" value="Search" />');
 
49
 document.write('  </div>');
 
50
 document.write('</form>');
 
51
</script>
 
52
          <div id="sitename">
 
53
            <a href="https://help.ubuntu.com/">
 
54
              <img alt="Official Documentation" src="https://help.ubuntu.com/htdocs/ubuntunew/img/help-about.png" />
 
55
              <span>Official Documentation</span>
 
56
            </a>
 
57
          </div>
 
58
        </div>
 
59
        <div id="page">
 
60
          <div id="content">
 
61
            <div class="breadcrumbs"><a href="https://help.ubuntu.com/">Ubuntu Documentation</a> &gt; <a href="https://help.ubuntu.com/11.04">Ubuntu 11.04</a> &gt; <span class="breadcrumb-link"><a href="index.html">Ubuntu Server Guide</a></span> &gt; <span class="breadcrumb-link"><a href="networking.html">Networking</a></span> &gt; <span class="breadcrumb-node">Time Synchronisation with NTP</span></div>
 
62
            <div xmlns="http://www.w3.org/1999/xhtml" class="sect1" title="Time Synchronisation with NTP">
 
63
              <div class="titlepage">
 
64
                <div>
 
65
                  <div>
 
66
                    <h2 class="title" style="clear: both"><a id="NTP"></a>Time Synchronisation with NTP</h2>
 
67
                  </div>
 
68
                </div>
 
69
              </div>
 
70
              <p>
 
71
This page describes methods for keeping your computer's time accurate. This is useful for servers, but is not necessary (or desirable) for desktop machines. 
 
72
</p>
 
73
              <p>
 
74
NTP is a TCP/IP protocol for synchronising time over a network. Basically a client requests the current time from a server, and uses it to set its own clock.  
 
75
</p>
 
76
              <p>
 
77
Behind this simple description, there is a lot of complexity - there are 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. Also the client software is a lot more complex than you might think - it has to factor out communication delays, and adjust the time in a way that does not upset all the other processes that run on the server. But luckily all that complexity is hidden from you! 
 
78
</p>
 
79
              <p>
 
80
Ubuntu has two ways of automatically setting your time: ntpdate and ntpd. 
 
81
</p>
 
82
              <div class="sect2" title="ntpdate">
 
83
                <div class="titlepage">
 
84
                  <div>
 
85
                    <div>
 
86
                      <h3 class="title"><a id="ntpdate"></a>ntpdate</h3>
 
87
                    </div>
 
88
                  </div>
 
89
                </div>
 
90
                <p>
 
91
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 server's clock is likely to drift considerably between reboots, so it makes sense to correct the time occasionally. The easiest way to do this is to get cron to run ntpdate every day. With your favorite editor, as root, create a file 
 
92
<code class="code">/etc/cron.daily/ntpdate</code>
 
93
 containing: 
 
94
</p>
 
95
                <pre class="programlisting">
 
96
ntpdate -s ntp.ubuntu.com
 
97
</pre>
 
98
                <p>
 
99
The file <code class="code">/etc/cron.daily/ntpdate</code> must also be executable.
 
100
</p>
 
101
                <pre class="screen">sudo chmod 755 /etc/cron.daily/ntpdate
 
102
</pre>
 
103
              </div>
 
104
              <div class="sect2" title="ntpd">
 
105
                <div class="titlepage">
 
106
                  <div>
 
107
                    <div>
 
108
                      <h3 class="title"><a id="ntpd"></a>ntpd</h3>
 
109
                    </div>
 
110
                  </div>
 
111
                </div>
 
112
                <p>
 
113
   ntpdate is a bit of a blunt instrument - it can only adjust the time once a day, in one big correction. The ntp daemon ntpd is far 
 
114
   more subtle. It calculates the drift of your system clock and continuously adjusts it, so there are no large corrections that could 
 
115
   lead to inconsistent logs for instance. The cost is a little processing power and memory, but for a modern server this is negligible. 
 
116
   </p>
 
117
                <p>
 
118
   To install ntpd, from a terminal prompt enter: 
 
119
   </p>
 
120
                <pre class="screen">
 
121
<span class="command"><strong>sudo apt-get install ntp</strong></span>
 
122
</pre>
 
123
              </div>
 
124
              <div class="sect2" title="Changing Time Servers">
 
125
                <div class="titlepage">
 
126
                  <div>
 
127
                    <div>
 
128
                      <h3 class="title"><a id="timeservers"></a>Changing Time Servers</h3>
 
129
                    </div>
 
130
                  </div>
 
131
                </div>
 
132
                <p>
 
133
  In both cases above, your system will use Ubuntu's NTP server at <span class="emphasis"><em>ntp.ubuntu.com</em></span> by default. This is OK, but you might
 
134
  want to use several servers to increase accuracy and resilience, and you may want to use time servers that are geographically closer 
 
135
  to you. to do this for ntpdate, change the contents of <code class="filename">/etc/cron.daily/ntpdate</code> to: 
 
136
  </p>
 
137
                <pre class="programlisting">
 
138
ntpdate -s ntp.ubuntu.com pool.ntp.org 
 
139
</pre>
 
140
                <p>
 
141
  And for ntpd edit <code class="filename">/etc/ntp.conf</code> to include additional server lines: 
 
142
  </p>
 
143
                <pre class="programlisting">
 
144
server ntp.ubuntu.com
 
145
server pool.ntp.org
 
146
</pre>
 
147
                <p>
 
148
  You may notice <span class="emphasis"><em>pool.ntp.org</em></span> in the examples above. This is a really good idea which uses round-robin DNS to
 
149
  return an NTP server from a pool, spreading the load between several different servers. Even better, they have pools for different
 
150
  regions - for instance, if you are in New Zealand, so you could use <span class="emphasis"><em>nz.pool.ntp.org</em></span> instead of 
 
151
  <span class="emphasis"><em>pool.ntp.org</em></span>. Look at <a class="ulink" href="http://www.pool.ntp.org/" target="_top">http://www.pool.ntp.org/</a> for more details. 
 
152
  </p>
 
153
                <p>
 
154
  You can also Google for NTP servers in your region, and add these to your configuration. To test that a server works, just type:
 
155
  </p>
 
156
                <pre class="screen">
 
157
<span class="command"><strong>sudo ntpdate ntp.server.name</strong></span>
 
158
</pre>
 
159
              </div>
 
160
              <div class="sect2" title="References">
 
161
                <div class="titlepage">
 
162
                  <div>
 
163
                    <div>
 
164
                      <h3 class="title"><a id="ntp-references"></a>References</h3>
 
165
                    </div>
 
166
                  </div>
 
167
                </div>
 
168
                <div class="itemizedlist">
 
169
                  <ul class="itemizedlist" type="disc">
 
170
                    <li class="listitem">
 
171
                      <p>
 
172
          See the <a class="ulink" href="https://help.ubuntu.com/community/UbuntuTime" target="_top">Ubuntu Time</a> wiki page for more information.
 
173
        </p>
 
174
                    </li>
 
175
                    <li class="listitem">
 
176
                      <p>
 
177
          <a class="ulink" href="http://support.ntp.org/bin/view/Support/WebHome" target="_top">NTP Support</a>
 
178
        </p>
 
179
                    </li>
 
180
                    <li class="listitem">
 
181
                      <p>
 
182
          <a class="ulink" href="http://www.ntp.org/ntpfaq/NTP-a-faq.htm" target="_top">The NTP FAQ and HOWTO</a>
 
183
        </p>
 
184
                    </li>
 
185
                  </ul>
 
186
                </div>
 
187
              </div>
 
188
            </div>
 
189
          </div>
 
190
          <div xmlns="http://www.w3.org/1999/xhtml" class="navfooter">
 
191
            <hr />
 
192
            <table width="100%" summary="Navigation footer">
 
193
              <tr>
 
194
                <td width="40%" align="left"><a accesskey="p" href="dhcp.html"><img src="../../libs/navig/prev.png" alt="Prev" /></a> </td>
 
195
                <td width="20%" align="center">
 
196
                  <a accesskey="u" href="networking.html">
 
197
                    <img src="../../libs/navig/up.png" alt="Up" />
 
198
                  </a>
 
199
                </td>
 
200
                <td width="40%" align="right"> <a accesskey="n" href="remote-administration.html"><img src="../../libs/navig/next.png" alt="Next" /></a></td>
 
201
              </tr>
 
202
              <tr>
 
203
                <td width="40%" align="left" valign="top">Dynamic Host Configuration Protocol (DHCP) </td>
 
204
                <td width="20%" align="center">
 
205
                  <a accesskey="h" href="index.html">
 
206
                    <img src="../../libs/navig/home.png" alt="Home" />
 
207
                  </a>
 
208
                </td>
 
209
                <td width="40%" align="right" valign="top"> Chapter 5. Remote Administration</td>
 
210
              </tr>
 
211
            </table>
 
212
          </div>
 
213
          <hr />
 
214
          <div id="footer">
 
215
            <div id="ubuntulinks">
 
216
              <p>The material in this document is available under a free license, see <a href="/legal.html">Legal</a> for details<br />
 
217
        For information on contributing see the <a href="https://wiki.ubuntu.com/DocumentationTeam">Ubuntu Documentation Team wiki page</a>. To report a problem, visit the <a href="https://bugs.launchpad.net/ubuntu/+source/ubuntu-docs">bug page for Ubuntu Documentation</a></p>
 
218
            </div>
 
219
          </div>
 
220
          <div id="bottomcap">
 
221
            <img src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-bottom.png" alt="" />
 
222
          </div>
 
223
        </div>
 
224
      </div>
 
225
    </div>
 
226
  </body>
 
227
</html>