您的位置:首页 > 运维架构 > Tomcat

Setting Up Tomcat 5 on Ubuntu 6.06

2007-06-26 19:11 483 查看
First a quick overview of what we are going to do:

1. install software
2. change 1 line in a configuration file.
3. start the Tomcat5 service
4. go to http://localhost:8180

And now for the good stuff.

First we want to install the right packages. basically we want to install apache2, a java jdk and tomcat (duh). I’ve chosen to use Sun’s java implementation. To install this you need to enable the multiverse repository. See this section of the Unofficial Ubuntu Starter Guide for help with enabling additional repositories. To install Tomcat itself you will also need to have the universe repository enabled.

Note: For Tomcat you MUST have a jdk not just a jre.

So, for the basic install use the following command.

sudo apt-get install apache2 tomcat5 sun-java5-jdk

If you want a shiny Tomcat welcome page when we finally get that far then install the example apps by adding tomcat5-webapps to the end of the last command. For the Tomcat admin web interface add tomcat5-admin, too.

My final command looks like this.

sudo apt-get install apache2 tomcat5 sun-java5-jdk tomcat5-webapps tomcat5-admin

By default Ubuntu uses a free Java implementation. We now need to tell Ubuntu that we want to use Sun Java as the default. Run the following command.

sudo update-alternatives --config java

Then enter the number of the version of Java you want from the list when prompted. The one I wanted was /usr/lib/jvm/java-1.5.0-sun/jre/bin/java.

Now we need to tell Tomcat where the jdk is. Open /etc/default/tomcat5 and change the variable JAVA_HOME to read…

JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun/

Make sure it’s NOT got a “#” at the start of the line. You can should now be able to start Tomcat5 with…

sudo /etc/init.d/tomcat5 start

Tomcat is listening on port 8180. So open up firefox and enter http://localhost:8180 in the address bar. Once the page loads you should see either a tomcat welcome page or, if you chose not to install the examples and admin packages, a fairly empty page with “Apache Tomcat/5.0″ at the bottom left. Congrats, you just installed a working Tomcat service. If you don’t see one of these pages, either you or I screwed up. ;)

If you installed them, the example apps can be found in “/usr/share/tomcat5/webapps/“. Also take a look at the configuration files in “/etc/tomcat5/“.

Hope that was helpful.

Update: Manolo Canga added a section in his Spanish translation of this tutorial that I’ve translated into English below.

Setting up an admin user

If you try to use the admin interface you’ll find you can’t because no admin user has been set up. To resolve that go into /var/lib/tomcat5/conf and edit tomcat-users.xml. You’ll see that 3 users have been created by default. We’re going to change the password of the user “tomcat” (<user username="tomcat" ) to something better than the default of “tomcat”. Duh!? Now we are going to give the user “tomcat” admin access. Add “admin” to the user tag’s roles attribute. It should look smilar to this.

<user username="tomcat" password="your_password" roles="tomcat,admin"/>

Now restart tomcat…

sudo /etc/init.d/tomcat5 restart

…and you’re done!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: