~ubuntu.cat/ubuntaires/ajuda

« back to all changes in this revision

Viewing changes to jaunty/build/html/serverguide/tomcat.html

  • Committer: Arnau Alcázar Lleopart
  • Date: 2009-07-15 17:38:44 UTC
  • Revision ID: arnau@alcalleop.net-20090715173844-67maxucr1l9enivg
Afegida la traducció de la Jaunty

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="">Apache Tomcat</title>
 
7
    <link rel="stylesheet" href="../libs/ubuntu-book.css" type="text/css" />
 
8
    <link rel="start" href="index.html" title="Guia del servidor de l'Ubuntu" />
 
9
    <link rel="up" href="web-servers.html" title="Capítol 9. Web Servers" />
 
10
    <link rel="prev" href="ruby-on-rails.html" title="Ruby on Rails" />
 
11
    <link rel="next" href="databases.html" title="Capítol 10. Databases" />
 
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="Documentació d'Ubuntu">
 
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="Documentació oficial" src="https://help.ubuntu.com/htdocs/ubuntunew/img/help-about.png" />
 
55
              <span>Documentació oficial</span>
 
56
            </a>
 
57
          </div>
 
58
        </div>
 
59
        <div id="page">
 
60
          <div id="content">
 
61
            <div class="breadcrumbs"><a href="https://ajuda.ubuntu.cat">Documentació de l'Ubuntu</a> &gt; <a href="https://ajuda.ubuntu.cat/9.04">Ubuntu 9.04</a> &gt; <span class="breadcrumb-link"><a href="index.html">Guia del servidor de l'Ubuntu</a></span> &gt; <span class="breadcrumb-link"><a href="web-servers.html">Web Servers</a></span> &gt; <span class="breadcrumb-node">Apache Tomcat</span></div>
 
62
            <div xmlns="http://www.w3.org/1999/xhtml" class="sect1" lang="ca" xml:lang="ca">
 
63
              <div class="titlepage">
 
64
                <div>
 
65
                  <div>
 
66
                    <h2 class="title" style="clear: both"><a id="tomcat"></a>Apache Tomcat</h2>
 
67
                  </div>
 
68
                </div>
 
69
              </div>
 
70
              <p>Apache Tomcat is a web container that allows you to serve Java Servlets
 
71
                and JSP (Java Server Pages) web applications.</p>
 
72
              <p>The <span class="application"><strong>Tomcat 6.0</strong></span> packages in Ubuntu support
 
73
                two different ways of running Tomcat. You can install them as a classic
 
74
                unique system-wide instance, that will be started at boot time and will run
 
75
                as the tomcat6 unpriviledged user. But you can also deploy private
 
76
                instances that will run with your own user rights, and that you should
 
77
                start and stop by yourself. This second way is particularly useful in a
 
78
                development server context where multiple users need to test on their own
 
79
                private Tomcat instances.</p>
 
80
              <div class="sect2" lang="ca" xml:lang="ca">
 
81
                <div class="titlepage">
 
82
                  <div>
 
83
                    <div>
 
84
                      <h3 class="title"><a id="tomcat-installation"></a>System-wide installation</h3>
 
85
                    </div>
 
86
                  </div>
 
87
                </div>
 
88
                <p>To install the <span class="application"><strong>Tomcat</strong></span> server,
 
89
                        you can enter the following command in the terminal prompt:</p>
 
90
                <pre class="screen">
 
91
<span class="command"><strong>sudo apt-get install tomcat6</strong></span>
 
92
</pre>
 
93
                <p>This will install a Tomcat server with just a default ROOT webapp
 
94
                        that displays a minimal "It works" page by default.</p>
 
95
              </div>
 
96
              <div class="sect2" lang="ca" xml:lang="ca">
 
97
                <div class="titlepage">
 
98
                  <div>
 
99
                    <div>
 
100
                      <h3 class="title"><a id="tomcat-configuration"></a>Configuration</h3>
 
101
                    </div>
 
102
                  </div>
 
103
                </div>
 
104
                <p>Tomcat configuration files can be found in
 
105
                        <code class="filename">/etc/tomcat6</code>. Only a few common configuration tweaks
 
106
                        will be described here, please see
 
107
                        <a class="ulink" href="http://tomcat.apache.org/tomcat-6.0-doc/index.html" target="_top">Tomcat
 
108
                        6.0 documentation</a> for more.</p>
 
109
                <div class="sect3" lang="ca" xml:lang="ca">
 
110
                  <div class="titlepage">
 
111
                    <div>
 
112
                      <div>
 
113
                        <h4 class="title"><a id="tomcat-configuration-ports"></a>Changing default ports</h4>
 
114
                      </div>
 
115
                    </div>
 
116
                  </div>
 
117
                  <p>By default Tomcat 6.0 runs a HTTP connector on port 8080 and an
 
118
                                AJP connector on port 8009. You might want to change those default
 
119
                                ports to avoid conflict with another server on the system. This is
 
120
                                done by changing the following lines in
 
121
                                <code class="filename">/etc/tomcat6/server.xml</code>:</p>
 
122
                  <pre class="programlisting">
 
123
&lt;Connector port="8080" protocol="HTTP/1.1" 
 
124
               connectionTimeout="20000" 
 
125
               redirectPort="8443" /&gt;
 
126
...
 
127
&lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /&gt;
 
128
</pre>
 
129
                </div>
 
130
                <div class="sect3" lang="ca" xml:lang="ca">
 
131
                  <div class="titlepage">
 
132
                    <div>
 
133
                      <div>
 
134
                        <h4 class="title"><a id="tomcat-configuration-jvm"></a>Changing JVM used</h4>
 
135
                      </div>
 
136
                    </div>
 
137
                  </div>
 
138
                  <p>By default Tomcat will run preferably with OpenJDK-6, then try
 
139
                                Sun's JVM, then try some other JVMs. If you have various JVMs
 
140
                                installed, you can set which should be used by setting JAVA_HOME in
 
141
                                <code class="filename">/etc/default/tomcat6</code>:</p>
 
142
                  <pre class="programlisting">
 
143
JAVA_HOME=/usr/lib/jvm/java-6-sun
 
144
</pre>
 
145
                </div>
 
146
                <div class="sect3" lang="ca" xml:lang="ca">
 
147
                  <div class="titlepage">
 
148
                    <div>
 
149
                      <div>
 
150
                        <h4 class="title"><a id="tomcat-configuration-users"></a>Declaring users and roles</h4>
 
151
                      </div>
 
152
                    </div>
 
153
                  </div>
 
154
                  <p>Usernames, passwords and roles (groups) can be defined centrally
 
155
                                in a Servlet container. In Tomcat 6.0 this is done in the
 
156
                                <code class="filename">/etc/tomcat6/tomcat-users.xml</code> file:</p>
 
157
                  <pre class="programlisting">
 
158
&lt;role rolename="admin"/&gt;
 
159
&lt;user username="tomcat" password="s3cret" roles="admin"/&gt;
 
160
</pre>
 
161
                </div>
 
162
              </div>
 
163
              <div class="sect2" lang="ca" xml:lang="ca">
 
164
                <div class="titlepage">
 
165
                  <div>
 
166
                    <div>
 
167
                      <h3 class="title"><a id="tomcat-webapps"></a>Using Tomcat standard webapps</h3>
 
168
                    </div>
 
169
                  </div>
 
170
                </div>
 
171
                <p>Tomcat is shipped with webapps that you can install
 
172
                        for documentation, administration or demo purposes.</p>
 
173
                <div class="sect3" lang="ca" xml:lang="ca">
 
174
                  <div class="titlepage">
 
175
                    <div>
 
176
                      <div>
 
177
                        <h4 class="title"><a id="tomcat-installation-docs"></a>Tomcat documentation</h4>
 
178
                      </div>
 
179
                    </div>
 
180
                  </div>
 
181
                  <p>The <span class="application"><strong>tomcat6-docs</strong></span> package contains
 
182
                                Tomcat 6.0 documentation, packaged as a webapp that you can access by
 
183
                                default at http://yourserver:8080/docs. You can install it by entering
 
184
                                the following command in the terminal prompt:</p>
 
185
                  <pre class="screen">
 
186
<span class="command"><strong>sudo apt-get install tomcat6-docs</strong></span>
 
187
</pre>
 
188
                </div>
 
189
                <div class="sect3" lang="ca" xml:lang="ca">
 
190
                  <div class="titlepage">
 
191
                    <div>
 
192
                      <div>
 
193
                        <h4 class="title"><a id="tomcat-installation-admin"></a>Tomcat administration webapps</h4>
 
194
                      </div>
 
195
                    </div>
 
196
                  </div>
 
197
                  <p>The <span class="application"><strong>tomcat6-admin</strong></span> package contains
 
198
                                two webapps that can be used to administer the Tomcat server using a
 
199
                                web interface. You can install them by entering the
 
200
                                following command in the terminal prompt:</p>
 
201
                  <pre class="screen">
 
202
<span class="command"><strong>sudo apt-get install tomcat6-admin</strong></span>
 
203
</pre>
 
204
                  <p>The first one is the <span class="emphasis"><em>manager</em></span> webapp, which
 
205
                                you can access by default at http://yourserver:8080/manager/html. It is
 
206
                                primarily used to get server status and restart webapps.</p>
 
207
                  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
 
208
                    <table border="0" summary="Note">
 
209
                      <tr>
 
210
                        <td rowspan="2" align="center" valign="top" width="25">
 
211
                          <img alt="[Nota]" src="../libs/admon/note.png" />
 
212
                        </td>
 
213
                        <th align="left"></th>
 
214
                      </tr>
 
215
                      <tr>
 
216
                        <td align="left" valign="top">
 
217
                          <p>Access to the <span class="emphasis"><em>manager</em></span> application is
 
218
                                protected by default: you need to define a user with the role "manager"
 
219
                                in <code class="filename">/etc/tomcat6/tomcat-users.xml</code>
 
220
                                before you can access it.</p>
 
221
                        </td>
 
222
                      </tr>
 
223
                    </table>
 
224
                  </div>
 
225
                  <p>The second one is the <span class="emphasis"><em>host-manager</em></span> webapp,
 
226
                                which you can access by default at
 
227
                                http://yourserver:8080/host-manager/html.
 
228
                                It can be used to create virtual hosts dynamically.</p>
 
229
                  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
 
230
                    <table border="0" summary="Note">
 
231
                      <tr>
 
232
                        <td rowspan="2" align="center" valign="top" width="25">
 
233
                          <img alt="[Nota]" src="../libs/admon/note.png" />
 
234
                        </td>
 
235
                        <th align="left"></th>
 
236
                      </tr>
 
237
                      <tr>
 
238
                        <td align="left" valign="top">
 
239
                          <p>Access to the <span class="emphasis"><em>host-manager</em></span> application is
 
240
                                also protected by default: you
 
241
                                need to define a user with the role "admin" in
 
242
                                <code class="filename">/etc/tomcat6/tomcat-users.xml</code>
 
243
                                before you can access it.</p>
 
244
                        </td>
 
245
                      </tr>
 
246
                    </table>
 
247
                  </div>
 
248
                  <p>For security reasons, the tomcat6 user cannot write to the
 
249
                                <code class="filename">/etc/tomcat6</code> directory by default. Some features
 
250
                                in these admin webapps (application deployment, virtual host creation)
 
251
                                need write access to that directory. If you want to use these
 
252
                                features execute the following, to give users in the tomcat6 group the necessary
 
253
                                rights:</p>
 
254
                  <pre class="screen">
 
255
<span class="command"><strong>sudo chgrp -R tomcat6 /etc/tomcat6</strong></span>
 
256
<span class="command"><strong>sudo chmod -R g+w /etc/tomcat6</strong></span> 
 
257
</pre>
 
258
                </div>
 
259
                <div class="sect3" lang="ca" xml:lang="ca">
 
260
                  <div class="titlepage">
 
261
                    <div>
 
262
                      <div>
 
263
                        <h4 class="title"><a id="tomcat-installation-examples"></a>Tomcat examples webapps</h4>
 
264
                      </div>
 
265
                    </div>
 
266
                  </div>
 
267
                  <p>The <span class="application"><strong>tomcat6-examples</strong></span> package contains
 
268
                                two webapps that can be used to test or demonstrate Servlets and JSP
 
269
                                features, which you can access them by default at
 
270
                                http://yourserver:8080/examples. You can install them by entering the
 
271
                                following command in the terminal prompt:</p>
 
272
                  <pre class="screen">
 
273
<span class="command"><strong>sudo apt-get install tomcat6-examples</strong></span>
 
274
</pre>
 
275
                </div>
 
276
              </div>
 
277
              <div class="sect2" lang="ca" xml:lang="ca">
 
278
                <div class="titlepage">
 
279
                  <div>
 
280
                    <div>
 
281
                      <h3 class="title"><a id="tomcat-user"></a>Using private instances</h3>
 
282
                    </div>
 
283
                  </div>
 
284
                </div>
 
285
                <p>Tomcat is heavily used in development and testing scenarios
 
286
                        where using a single system-wide instance doesn't meet the requirements
 
287
                        of multiple users on a single system. The Tomcat 6.0 packages in
 
288
                        Ubuntu come with tools to help deploy your own user-oriented instances,
 
289
                        allowing every user on a system to run (without root rights) separate
 
290
                        private instances while still using the system-installed
 
291
                        libraries.</p>
 
292
                <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
 
293
                  <table border="0" summary="Note">
 
294
                    <tr>
 
295
                      <td rowspan="2" align="center" valign="top" width="25">
 
296
                        <img alt="[Nota]" src="../libs/admon/note.png" />
 
297
                      </td>
 
298
                      <th align="left"></th>
 
299
                    </tr>
 
300
                    <tr>
 
301
                      <td align="left" valign="top">
 
302
                        <p>It is possible to run the system-wide instance and the private
 
303
                        instances in parallel, as long as they do not use the same TCP
 
304
                        ports.</p>
 
305
                      </td>
 
306
                    </tr>
 
307
                  </table>
 
308
                </div>
 
309
                <div class="sect3" lang="ca" xml:lang="ca">
 
310
                  <div class="titlepage">
 
311
                    <div>
 
312
                      <div>
 
313
                        <h4 class="title"><a id="tomcat-user-install"></a>Installing private instance support</h4>
 
314
                      </div>
 
315
                    </div>
 
316
                  </div>
 
317
                  <p>You can install everything necessary to run private instances
 
318
                                by entering the following command in the terminal prompt:</p>
 
319
                  <pre class="screen">
 
320
<span class="command"><strong>sudo apt-get install tomcat6-user</strong></span>
 
321
</pre>
 
322
                </div>
 
323
                <div class="sect3" lang="ca" xml:lang="ca">
 
324
                  <div class="titlepage">
 
325
                    <div>
 
326
                      <div>
 
327
                        <h4 class="title"><a id="tomcat-user-create"></a>Creating a private instance</h4>
 
328
                      </div>
 
329
                    </div>
 
330
                  </div>
 
331
                  <p>You can create a private instance directory by entering the
 
332
                                following command in the terminal prompt:</p>
 
333
                  <pre class="screen">
 
334
<span class="command"><strong>tomcat6-instance-create my-instance</strong></span>
 
335
</pre>
 
336
                  <p>This will create a new <code class="filename">my-instance</code> directory
 
337
                                with all the necessary subdirectories and scripts.
 
338
                                You can for example install your common libraries in the
 
339
                                <code class="filename">lib/</code> subdirectory and deploy your webapps in the
 
340
                                <code class="filename">webapps/</code> subdirectory. No webapps are deployed
 
341
                                by default.</p>
 
342
                </div>
 
343
                <div class="sect3" lang="ca" xml:lang="ca">
 
344
                  <div class="titlepage">
 
345
                    <div>
 
346
                      <div>
 
347
                        <h4 class="title"><a id="tomcat-user-config"></a>Configuring your private instance</h4>
 
348
                      </div>
 
349
                    </div>
 
350
                  </div>
 
351
                  <p>You will find the classic Tomcat configuration files for your
 
352
                                private instance in the <code class="filename">conf/</code>
 
353
                                subdirectory. You should for
 
354
                                example certainly edit the <code class="filename">conf/server.xml</code> file
 
355
                                to change the default ports used by your private Tomcat instance to
 
356
                                avoid conflict with other instances that might be running.</p>
 
357
                </div>
 
358
                <div class="sect3" lang="ca" xml:lang="ca">
 
359
                  <div class="titlepage">
 
360
                    <div>
 
361
                      <div>
 
362
                        <h4 class="title"><a id="tomcat-user-start"></a>Starting/stopping your private instance</h4>
 
363
                      </div>
 
364
                    </div>
 
365
                  </div>
 
366
                  <p>You can start your private instance by entering the following
 
367
                                command in the terminal prompt (supposing  your instance is located
 
368
                                in the <code class="filename">my-instance</code> directory):</p>
 
369
                  <pre class="screen">
 
370
<span class="command"><strong>my-instance/bin/startup.sh</strong></span>
 
371
</pre>
 
372
                  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
 
373
                    <table border="0" summary="Note">
 
374
                      <tr>
 
375
                        <td rowspan="2" align="center" valign="top" width="25">
 
376
                          <img alt="[Nota]" src="../libs/admon/note.png" />
 
377
                        </td>
 
378
                        <th align="left"></th>
 
379
                      </tr>
 
380
                      <tr>
 
381
                        <td align="left" valign="top">
 
382
                          <p>You should check the <code class="filename">logs/</code> subdirectory for
 
383
                                any error. If you have a <span class="emphasis"><em>java.net.BindException: Address
 
384
                                already in use&lt;null&gt;:8080</em></span> error, it means that the
 
385
                                port you're using is already taken and that you should change it.
 
386
                                </p>
 
387
                        </td>
 
388
                      </tr>
 
389
                    </table>
 
390
                  </div>
 
391
                  <p>You can stop your instance by entering the following
 
392
        command in the terminal prompt (supposing  your instance is located
 
393
        in the <code class="filename">my-instance</code> directory):</p>
 
394
                  <pre class="screen">
 
395
<span class="command"><strong>my-instance/bin/shutdown.sh</strong></span>
 
396
</pre>
 
397
                </div>
 
398
              </div>
 
399
              <div class="sect2" lang="ca" xml:lang="ca">
 
400
                <div class="titlepage">
 
401
                  <div>
 
402
                    <div>
 
403
                      <h3 class="title"><a id="tomcat-references"></a>References</h3>
 
404
                    </div>
 
405
                  </div>
 
406
                </div>
 
407
                <div class="itemizedlist">
 
408
                  <ul type="disc">
 
409
                    <li>
 
410
                      <p>
 
411
                      See the <a class="ulink" href="http://tomcat.apache.org/" target="_top">Apache Tomcat</a> website for more information.
 
412
                      </p>
 
413
                    </li>
 
414
                    <li>
 
415
                      <p>
 
416
                      <a class="ulink" href="http://oreilly.com/catalog/9780596003180/" target="_top">Tomcat: The Definitive Guide</a> is a good
 
417
                      resource for building web applications with Tomcat.
 
418
                      </p>
 
419
                    </li>
 
420
                    <li>
 
421
                      <p>
 
422
                      For additional books see the <a class="ulink" href="http://wiki.apache.org/tomcat/Tomcat/Books" target="_top">Tomcat Books</a> list page.
 
423
                      </p>
 
424
                    </li>
 
425
                  </ul>
 
426
                </div>
 
427
              </div>
 
428
            </div>
 
429
          </div>
 
430
          <div xmlns="http://www.w3.org/1999/xhtml" class="navfooter">
 
431
            <hr />
 
432
            <table width="100%" summary="Navigation footer">
 
433
              <tr>
 
434
                <td width="40%" align="left"><a accesskey="p" href="ruby-on-rails.html"><img src="../libs/navig/prev.png" alt="Anterior" /></a> </td>
 
435
                <td width="20%" align="center">
 
436
                  <a accesskey="u" href="web-servers.html">
 
437
                    <img src="../libs/navig/up.png" alt="Pujar" />
 
438
                  </a>
 
439
                </td>
 
440
                <td width="40%" align="right"> <a accesskey="n" href="databases.html"><img src="../libs/navig/next.png" alt="Següent" /></a></td>
 
441
              </tr>
 
442
              <tr>
 
443
                <td width="40%" align="left" valign="top">Ruby on Rails </td>
 
444
                <td width="20%" align="center">
 
445
                  <a accesskey="h" href="index.html">
 
446
                    <img src="../libs/navig/home.png" alt="Inici" />
 
447
                  </a>
 
448
                </td>
 
449
                <td width="40%" align="right" valign="top"> Capítol 10. Databases</td>
 
450
              </tr>
 
451
            </table>
 
452
          </div>
 
453
          <hr />
 
454
          <div id="footer">
 
455
            <div id="ubuntulinks">
 
456
              <p>Aquest material es troba sota una llicència lliure, vegeu<a href="/legal.html">això</a> per a més detalls<br /></p>
 
457
            </div>
 
458
          </div>
 
459
          <div id="bottomcap">
 
460
            <img src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-bottom.png" alt="" />
 
461
          </div>
 
462
        </div>
 
463
      </div>
 
464
    </div>
 
465
  </body>
 
466
</html>