1、解压缩Tomcat的tar包,默认放在opt下
tar -zxvf apache-tomcat-6.0.35.tar.gz
2、输入如下命令修改tomcat配置文件
vi /opt/apache-tomcat-6.0.35/conf/server.xml
3、在最下面</Host>前面输入:
<Context reloadable="true" path="" docBase="war包名"/>
比如war包是god.war,例子:
<Context reloadable="true" path="" docBase="go"/>
4.将war包放入webapps,输入如下命令启动tomcat
cd /opt/apache-tomcat-6.0.35/bin chmod 777 *.sh sh /opt/apache-tomcat-6.0.35/bin/startup.sh
PS:如果要将几个项目发布到一台电脑,就需要多个tomcat,并修改端口。复制tomcat文件夹到任何位置,这里还是放在/opt下,并修改文件夹名称,输入如下命令:
vi /opt/apache-tomcat-6.0.35/conf/server.xml
下面附上完整的配置文件内容
<?xml version="1.0" encoding="UTF-8"?> <Server shutdown="SHUTDOWN" port="8005"> <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/> <Listener className="org.apache.catalina.core.JasperListener"/> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/> <GlobalNamingResources> <Resource pathname="conf/tomcat-users.xml" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" description="User database that can be updated and saved" type="org.apache.catalina.UserDatabase" auth="Container" name="UserDatabase"/></GlobalNamingResources> <Service name="Catalina"> <Connector port="8080" redirectPort="8443" connectionTimeout="20000" protocol="HTTP/1.1"/> <Connector port="8009" redirectPort="8443" protocol="AJP/1.3"/> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> <Host name="localhost" xmlNamespaceAware="false" xmlValidation="false" autoDeploy="true" unpackWARs="true" appBase="webapps"> <Context reloadable="true" path="" docBase="god"/></Host> </Engine> </Service> </Server>
将文件中port="xxx"的端口号改掉,8080端口改成和apache配置文件serverName一致。
比如
<VirtualHost *:80> ServerName http: //二级域名 .域名.com DocumentRoot "/opt/apache2.2/htdocs" ProxyPass /authpic/ ! ProxyPass /avatar/ ! ProxyPass /merchantpic/ ! ProxyPass /ad/ ! ProxyPass /vchi_credit/ ! ProxyPass /img/ ! ProxyPass / http: // 服务器IP:48080/ ProxyPassReverse / http: // 服务器IP:48080/ </VirtualHost> 那么本机的hosts文件中vip.iyouyii.com就要映射到服务器IP。 然后项目所在tomcat端口号改成48080即可
启动tomcat后在linux中输入命令curl 127.0.0.1:48080.看到项目界面即表示成功。或者在本机输入配置好的网址。