接上文安装了JDK,配置了环境变量后,就可以安装tomcat了。
1、下载tomcat:
http://mirrors.cnnic.cn/apache/tomcat/tomcat-7/v7.0.67/bin/apache-tomcat-7.0.67.tar.gz
2、将tomcat解压缩到/usr/local/tomcat/下面。
tar -zxvf apache-tomcat-7.0.67.tar.gz
操作完成查看:
[[email protected] tomcat]# pwd
/usr/local/tomcat
[[email protected] tomcat]# ll
总用量 4
drwxr-xr-x 9 root root 4096 1月 8 18:09 apache-tomcat-7.0.67
3、进入/usr/local/tomcat/apache-tomcat-7.0.67/bin下,检查JAVA_HOME环境变量是否生效存在
[[email protected] bin]# echo $JAVA_HOME
/usr/java/jdk1.8.0_65
如果不存在,则有两种可能,一种是配置了$JAVA_HOME后没有重启,或者没配置。如果确定是前者,则执行如下命令即可:
source /etc/profile
4、确定JAVA_HOME正常出来后,就直接启动tomcat了。
[[email protected] bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-7.0.67
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-7.0.67
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-7.0.67/temp
Using JRE_HOME: /usr/java/jdk1.8.0_65
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-7.0.67/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-7.0.67/bin/tomcat-juli.jar
Tomcat started.
5、查看tomcat运行时日志:
进入/usr/local/tomcat/apache-tomcat-7.0.67/logs下面执行
[[email protected] logs]# tail -f catalina.out
一月 08, 2016 6:29:56 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory /usr/local/tomcat/apache-tomcat-7.0.67/webapps/manager
一月 08, 2016 6:29:56 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory /usr/local/tomcat/apache-tomcat-7.0.67/webapps/manager has finished in 108 ms
一月 08, 2016 6:29:56 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
一月 08, 2016 6:29:56 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
一月 08, 2016 6:29:56 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 822 ms
就可以动态看到tomcat的运行时日志。
如果形成自动化脚本:
cd /usr mkdir -p local/tomcat mv apache-tomcat-7.0.67.tar.gz local/tomcat cd local/tomcat tar -zxvf apache-tomcat-7.0.67.tar.gz source /etc/profile cd apache-tomcat-7.0.67/bin ./startup.sh |
6、有关tomcat端口、字符集、软连接等配置,和windows下一样的。
端口,URI编码配置:
71 <Connector port="8080" protocol="HTTP/1.1"
72 connectionTimeout="20000"
73 redirectPort="8443" URIEncoding="UTF-8"/>
74 <!-- A "Connector" using the shared thread pool-->
软连接访问问题,需要配置context属性,context可以配置在不同的地方,例如:
# pwd
/usr/local/tomcat6.0/webapps
# ln -s site test
# cat site/META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/usr/local/tomcat6.0/webapps/site" allowLinking="true">
</Context>