Tomcat on Ubuntu
如果直接去 tomcat 官网下载压缩包,则解压到 /opt/tomcat 或其他目录使用即可,使用比这个简单。但要注意的是,在 Linux 平台,{tomcat dir}/bin 目录下的 *.sh 档案是没有可执行权限的,必须通过执行 chmod +x *.sh
授权後方可使用。
下面只描述通过 apt-get
方式安装的 Tomcat.
常用操作
安装:sudo apt-get install tomcat6
卸载:sudo apt-get remove --purge tomcat6
启动:sudo /etc/init.d/tomcat6 start
(后面可以接一些参数,比如 -run 来查看启动时的日志)
关闭:sudo /etc/init.d/tomcat6 stop
重启:sudo /etc/init.d/tomcat6 restart
目录结构
用习惯了在 apache 下载的压缩包直接解压的 tomcat,一时间还不能适应这个 tomcat. 安装好后,通过"whereis tomcat6" 查找到如下两个目录:
/etc/tomcat6 (一些配置文件)
/usr/share/tomcat6
但实际上,还有另外几个目录:
/usr/share/tomcat6
/usr/share/tomcat6-admin
/usr/share/tomcat6-docs
/usr/share/tomcat6-examples
/var/lib/tomcat6(自己写的应用,可放在这个目录下的 webapp 里)
/etc/tomcat6$ tree
.
|-- Catalina
| `-- localhost
| |-- docs.xml
| |-- examples.xml
| |-- host-manager.xml
| |-- manager.xml
| `-- ROOT.xml
|-- catalina.properties
|-- context.xml
|-- logging.properties
|-- policy.d
| |-- 01system.policy
| |-- 02debian.policy
| |-- 03catalina.policy
| |-- 04webapps.policy
| |-- 10examples.policy
| `-- 50local.policy
|-- server.xml
|-- tomcat-users.xml
`-- web.xml
================================================
/usr/share/tomcat6$ tree
.
|-- bin(但直接用这里的脚本启动和关闭 tomcat,会报错,直接用前面提到的指令,就没问题)
| |-- bootstrap.jar
| |-- catalina.sh
| |-- catalina-tasks.xml
| |-- digest.sh
| |-- setclasspath.sh
| |-- shutdown.sh
| |-- startup.sh
| |-- tomcat-juli.jar -> ../../java/tomcat-juli.jar
| |-- tool-wrapper.sh
| `-- version.sh
|-- lib
| |-- annotations-api.jar -> ../../java/annotations-api-6.0.24.jar
| |-- catalina-ant.jar -> ../../java/catalina-ant-6.0.24.jar
| |-- catalina-ha.jar -> ../../java/catalina-ha-6.0.24.jar
| |-- catalina.jar -> ../../java/catalina-6.0.24.jar
| |-- catalina-tribes.jar -> ../../java/catalina-tribes-6.0.24.jar
| |-- commons-dbcp.jar -> ../../java/commons-dbcp.jar
| |-- commons-pool.jar -> ../../java/commons-pool.jar
| |-- el-api.jar -> ../../java/el-api-2.1.jar
| |-- jasper-el.jar -> ../../java/jasper-el-6.0.24.jar
| |-- jasper.jar -> ../../java/jasper-6.0.24.jar
| |-- jasper-jdt.jar -> ../../java/ecj.jar
| |-- jsp-api.jar -> ../../java/jsp-api-2.1.jar
| |-- servlet-api.jar -> ../../java/servlet-api-2.5.jar
| |-- tomcat-coyote.jar -> ../../java/tomcat-coyote-6.0.24.jar
| |-- tomcat-i18n-es.jar -> ../../java/tomcat-i18n-es-6.0.24.jar
| |-- tomcat-i18n-fr.jar -> ../../java/tomcat-i18n-fr-6.0.24.jar
| `-- tomcat-i18n-ja.jar -> ../../java/tomcat-i18n-ja-6.0.24.jar
|-- skel
| |-- bin
| | `-- setenv.sh
| `-- conf
| |-- catalina.properties
| |-- context.xml
| |-- logging.properties
| |-- server.xml
| |-- tomcat-users.xml
| `-- web.xml
`-- webapps //鄙人很郁闷的是,在公司的测试服务器上,这个 webapps 目录的位置是:/var/lib/tomcat6/webapps
`-- default_root
|-- index.html
`-- META-INF
`-- context.xml
PS: to view the tree of file system, you should install 'tree' and then can you use the command 'tree' to do so.
自述文件
从新立得安装好 tomcat 并启动后,本机访问 http://localhost:8080 可以看到如下内容:
It works !
If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!
This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat6/webapps/ROOT/index.html
Tomcat6 veterans might be pleased to learn that this system instance of Tomcat is installed with CATALINA_HOME in /usr/share/tomcat6 and CATALINA_BASE in /var/lib/tomcat6, following the rules from /usr/share/doc/tomcat6-common/RUNNING.txt.gz.
You might consider installing the following packages, if you haven't already done so:
tomcat6-docs: This package installs a web application that allows to browse the Tomcat 6 documentation locally. Once installed, you can access it by clicking here.
tomcat6-examples: This package installs a web application that allows to access the Tomcat 6 Servlet and JSP examples. Once installed, you can access it by clicking here.
tomcat6-admin: This package installs two web applications that can help managing this Tomcat instance. Once installed, you can access the manager webapp and the host-manager webapp.
NOTE: For security reasons, using the manager webapp is restricted to users with role "manager". The host-manager webapp is restricted to users with role "admin". Users are defined in /etc/tomcat6/tomcat-users.xml.
以上说明了一些重要的目录信息。