1. 下载tomcat7.0:
http://tomcat.apache.org/download-70.cgi
2. 使用tar -zxvf xxx.tar.gz进行解压,然后把解压后的文件夹重命名为tomcat7.0;
3. 此时用浏览器访问:http://localhost:8080有时可能访问不了,出现这种情况需要配置/etc/profile文件:
添加如下内容:
export CATALINA_HOME=/usr/local/tomcat7.0
(由于已经装了jdk,所以profile文件中应该还有如下内容:
export JAVA_HOME=/usr/local/jdk
export JAVA_BIN=/usr/local/jdk/bin
export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:.
export PATH=.:$JAVA_HOME/bin:$PATH)
所以完整的配置如下:
export JAVA_HOME=/usr/local/jdk
export JAVA_BIN=/usr/local/jdk/bin(加上这句之后,下面的JRE_HOME会指向 /usr/local/jdk )
export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:.
export CATALINA_HOME=/usr/local/tomcat7.0
export PATH=.:$JAVA_HOME/bin:$PATH
修改之后,执行:source /etc/profile使得配置生效。
4. 启动tomcat:
cd到tomcat7.0/bin目录下,输入: ./startup.sh即可启动了,启动若出现下面则表示成功了。
[root@huyanping tomcat7.0]# bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat7.0/
Using CATALINA_HOME: /usr/local/tomcat7.0/
Using CATALINA_TMPDIR: /usr/local/tomcat7.0//temp
Using JRE_HOME: /usr/local/jdk (该JRE_HOME一定要指向jdk目录)
Using CLASSPATH: /usr/local/tomcat7.0//bin/bootstrap.jar:/usr/local/tomcat7.0//bin/tomcat-juli.jar
Tomcat started.
5. 浏览器中输入:http://localhost:8080即可访问了。
参考网站:
http://blog.csdn.net/zhuying_linux/article/details/6583096
注1:安装tomcat之前要先安装jdk。
注2:可以改变tomcat默认端口8080,cd到tomcat7.0/conf/,然后vi server.xml,修改其中的8080端口,然后关闭tomcat(执行./shutdown.sh),然后启动tomcat(执行./startup.sh)即可,一定要这样,不关闭tomcat,直接再次启动tomcat没有用的。
server.xml对应内容如下:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!-- 注释内容
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
注3:关闭tomcat,执行./shutdown.sh,出现类似下面内容就表示关闭成功了。
[root@huyanping bin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat7.0/
Using CATALINA_HOME: /usr/local/tomcat7.0/
Using CATALINA_TMPDIR: /usr/local/tomcat7.0//temp
Using JRE_HOME: /usr/local/jdk
Using CLASSPATH: /usr/local/tomcat7.0//bin/bootstrap.jar:/usr/local/tomcat7.0//bin/tomcat-juli.jar
若出现No Such File之类的输出,则关闭失败,此时JRE_HOME可能没指向/usr/local/jdk目录,即没指向jdk目录,此时只要在bin/catalina.sh中添加JRE_HOME=/usr/local/jdk即可。
参考网站:http://www.educity.cn/wenda/211390.html
解决上面问题后关闭又可能出现下面问题,如下提示:
Dec 20, 2005 9:08:06 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.<init>(Socket.java:365)
at java.net.Socket.<init>(Socket.java:178)
有人说此时关闭不了tomcat服务是一个bug,我们可以kill tomcat即可。