个人工具
登录
查看“UbuntuHelp:ApacheTomcat5”的源代码 - Ubuntu中文
UbuntuHelp
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“UbuntuHelp:ApacheTomcat5”的源代码
来自Ubuntu中文
←
UbuntuHelp:ApacheTomcat5
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{From|https://help.ubuntu.com/community/ApacheTomcat5}} {{Languages|UbuntuHelp:ApacheTomcat5}} This is to help people setup and install Apache Tomcat 5. Jakarta Tomcat, a Java servlet container, is now part of the Apache family under the name of Apache Tomcat. It can be installed in Ubuntu 6.06 (Dapper Drake) following the steps below. === Installation === ==== Needed before installing Apache Tomcat ==== '''Java virtual machine''' Follow this [[UbuntuHelp:Java|link]] paying attention to download the JDK and not the JRE. Enable the universe and multiverse repositories * [[UbuntuHelp:Repositories/CommandLine| I am using Ubuntu server (command line)]] * [[UbuntuHelp:AddingRepositoriesHowto| I am using a desktop]] In Ubuntu 6.06, do: <pre><nowiki> sudo apt-get install sun-java5-jdk </nowiki></pre> '''Set Java environment variables''' <pre><nowiki> $ export JAVA_HOME="path of your java home" $ export PATH=$PATH:$JAVA_HOME/bin </nowiki></pre> In Ubuntu 6.06,do: <pre><nowiki> export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun-1.5.0.06 </nowiki></pre> You may have to change the numbers for updated versions. ==== Installing Apache Tomcat 5 ==== <pre><nowiki> $ sudo aptitude install tomcat5 tomcat5-admin tomcat5-webapps </nowiki></pre> (The package <pre><nowiki>tomcat5-webapps</nowiki></pre> just contains some example applications. It is interesting for developers, but you should omit it on production servers.) Depending on your JDK version, you must set (or not) the <pre><nowiki>JAVA_HOME</nowiki></pre> variable in <pre><nowiki>/etc/default/tomcat5</nowiki></pre>. The start script tests for a couple of JDKs, but only finds older versions. Probably you must set (the already existing) <pre><nowiki>JAVA_HOME</nowiki></pre> variable as follows: <pre><nowiki> JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun </nowiki></pre> ==== Run, Stop, And Restart Apache Tomcat ==== Use the following command to run Apache Tomcat: <pre><nowiki> $ sudo /etc/init.d/tomcat5 start </nowiki></pre> To stop it, use : <pre><nowiki> $ sudo /etc/init.d/tomcat5 stop </nowiki></pre> Finally, to restart it, run : <pre><nowiki> $ sudo /etc/init.d/tomcat5 restart </nowiki></pre> ==== Using Tomcat5 ==== You can find tomcat up and running (if you have followed the previous steps) at the following ip: <pre><nowiki> 127.0.0.1:8180 </nowiki></pre> === Configuration === [http://www.coreservlets.com/Apache-Tomcat-Tutorial/#Directory-Listings Configuring & Using Apache Tomcat 6] and [http://www.owasp.org/index.php/Securing_tomcat Securing tomcat] are good external resources about this topic. ==== Administering Tomcat5 ==== If you have installed also the admin package as listed before you will be able to enter in the administation window only if you edit the file <pre><nowiki> $ /usr/share/tomcat5/conf/tomcat-users.xml </nowiki></pre> and add the following lines for creating new users with admin and manager privilegies as described in Tomcat's main page <pre><nowiki> <role rolename="manager"/> <role rolename="admin"/> <user username="YOUR USERNAME " password="YOUR PASSWORD" roles="admin,manager"/> </nowiki></pre> Obviously if you want only one kind of role you've to delete the one you are not interested in. Example only admin <pre><nowiki> <role rolename="admin"/> <user username="YOUR USERNAME " password="YOUR PASSWORD" roles="admin"/> </nowiki></pre> ==== Installing new servlet or jsp pages in Tomcat5 ==== Using the Tomcat manager included in the installed packages you'll be able to to control your servlet/jsp properly. 1.Enter in your server (by default 127.0.0.1:8180). 2.Enter in the Tomcat manager page (you find the link on the left) typing username and password chosen in the previous step. 3.Search the section ''Deploy'' and in the field ''WAR or Directory URL'' type: <pre><nowiki> file://YOUR SERVLET or JSP PAGE DIRECTORY </nowiki></pre> Usually servlet/jsp pages are located in the directory ''/usr/share/tomcat5/webapps''. ==== Tomcat on port 80 ==== If you run Tomcat without a separate web server, but you want it to listen on port 80, then you should redirect port 80 to 8180 with iptables. For this you should create two files: ''/etc/network/if-pre-up.d/tomcat5-port80'' <pre><nowiki> #!/bin/sh [ "$IFACE" == "eth0" ] || exit 0; iptables -t nat -A PREROUTING -i eth0 -p tcp --dport http -j REDIRECT --to-ports 8180 </nowiki></pre> ''/etc/network/if-post-down.d/tomcat5-port80'' <pre><nowiki> #!/bin/sh [ "$IFACE" == "eth0" ] || exit 0; iptables -t nat -D PREROUTING -i eth0 -p tcp --dport http -j REDIRECT --to-ports 8180 </nowiki></pre> They must be executable, but only root should be able to modify them (e.g. use <pre><nowiki>chmod 744</nowiki></pre>). Please do also adjust your network interface as needed. After restarting the server, you can access Tomcat on port 80 and 8180. There are a couple of other possibilities to achieve this goal (see the sections in [http://www.owasp.org/index.php/Securing_tomcat#Using_Port_80 Securing tomcat] and [http://www.coreservlets.com/Apache-Tomcat-Tutorial/#Change-Port Configuring & Using Apache Tomcat 6]). For most situations the given solution should be appropriate. But please pay attention to avoid running Tomcat as root! ==== Turn of directory listings ==== For security reasons and to not disturbe guests you might want to turn of directory listings in case of non-existing welcome pages (e.g. if index.html is missing). To do this modify the ''listings'' parameter in <pre><nowiki>conf/web.xml</nowiki></pre>: <pre><nowiki> <init-param> <param-name>listings</param-name> <param-value>false</param-value> </init-param> </nowiki></pre> ==== User friendly error pages in case of a Java exception ==== Tomcat shows a stack trace per default, if an uncaught Java exception occurs. It is the task of the web application to adjust the response. The [http://tomcat.apache.org/faq/misc.html#error Tomcat FAQ] gives a hint. ==== Securing Tomcat ==== When omiting the webapps-package and creating reasonable user accounts, Tomcat is already rather secure as shipped in Ubuntu (most important: it does not run as root) . For further improvements the Open Web Application Security Project (OWASP) has a good [http://www.owasp.org/index.php/Securing_tomcat howto] to secure your Tomcat installation. [[category:UbuntuHelp]]
该页面使用的模板:
模板:From
(
查看源代码
)
模板:Languages
(
查看源代码
)(受保护)
模板:Languages/Lang
(
查看源代码
)(受保护)
返回至
UbuntuHelp:ApacheTomcat5
。