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

linux下安装配置tomcat

2016-07-10 12:13 447 查看


Linux下Tomcat安装配置以及Windows不能连接服务器Tomcat解决方案

一、从官方网站上下载tomcat软件包。

官网地址: http://tomcat.apache.org/

点击左侧的 download的一个版本,我选择的是 tomcat7.0,选择一个后缀名为.tar.gz文件直接下载到本地。

二、通过工具SSH Secure 上传至linux服务器中,进行解压

解压tomcat压缩文件: 

 #tar zxvf apache-tomcat-7.0.53.tar.gz

将解压后的tomcat文件移动至/usr/local下

 #mv apach-tomcat-6.0.16 /usr/local

三、配置tomcat环境;【之前我已经安装好JDK了】

 编辑profie文件:

#vi /etc/profile

将下面文件copy到export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL后面;具体jdk路径根据你安装的位置来配置;
export JAVA_HOME=/usr/java/jdk1.7.0_15

export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export PATH=$PATH:$JAVA_HOME/bin

export CATALINA_HOME=/usr/local/apache-tomcat-7.0.53

export CATALINA_BASE=/usr/local/apache-tomcat-7.0.53

保存退出,重新登录使之生效。 

   
四、启动tomcat服务器

进入到/usr/local/apach-tomcat-6.0.20/bin目录

运行./startup.sh

启动成功会出现如下内容:

Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.53

Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.53

Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.53/temp

Using JRE_HOME:        /usr/java/jdk1.7.0_15

Using CLASSPATH:       /usr/local/apache-tomcat-7.0.53/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.53/bin/tomcat-juli.jar

Tomcat started.

五、测试是否启动成功

在linux浏览器中输入http://localhost:8080/就可以看到tomcat的log了

如果8080端口被占用,或者你只是想修改tomcat的端口,请参考如下文件,我直接copy上来了。【我这里是修改为9080端口】
<?xml version='1.0' encoding='utf-8'?><!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.You may obtain a copy of the License at	 http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.--><!-- Note:A "Server" is not itself a "Container", so you may not	define subcomponents such as "Valves" at this level.	Documentation at /docs/config/server.html --><Server port="9005" shutdown="SHUTDOWN"><!--APR library loader. Documentation at /docs/apr.html --><Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /><!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --><Listener className="org.apache.catalina.core.JasperListener" /><!-- Prevent memory leaks due to use of particular java/javax APIs--><Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /><!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html --><Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /><Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /><!-- Global JNDI resources	Documentation at /docs/jndi-resources-howto.html--><GlobalNamingResources><!-- Editable user database that can also be used by	UserDatabaseRealm to authenticate users--><Resource name="UserDatabase" auth="Container"		type="org.apache.catalina.UserDatabase"		description="User database that can be updated and saved"		factory="org.apache.catalina.users.MemoryUserDatabaseFactory"		pathname="conf/tomcat-users.xml" /></GlobalNamingResources><!-- A "Service" is a collection of one or more "Connectors" that share	a single "Container" Note:A "Service" is not itself a "Container", 	so you may not define subcomponents such as "Valves" at this level.	Documentation at /docs/config/service.html --><Service name="Catalina"><!--The connectors can use a shared executor, you can define one or more named thread pools--><!--<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 	 maxThreads="150" minSpareThreads="4"/>--><!-- A "Connector" represents an endpoint by which requests are received	and responses are returned. Documentation at :	Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)	Java AJPConnector: /docs/config/ajp.html	APR (HTTP/AJP) Connector: /docs/apr.html	Define a non-SSL HTTP/1.1 Connector on port 8080--><Connector port="9080" 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" />-->		 <!-- Define a SSL HTTP/1.1 Connector on port 8443	This connector uses the JSSE configuration, when using APR, the 	connector should be using the OpenSSL style configuration	described in the APR documentation --><!--<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"			maxThreads="150" scheme="https" secure="true"			clientAuth="false" sslProtocol="TLS" />--><!-- Define an AJP 1.3 Connector on port 8009 --><Connector port="9009" protocol="AJP/1.3" redirectPort="8443" /><!-- An Engine represents the entry point (within Catalina) that processes	every request.The Engine implementation for Tomcat stand alone	analyzes the HTTP headers included with the request, and passes them	on to the appropriate Host (virtual host).	Documentation at /docs/config/engine.html --><!-- You should set jvmRoute to support load-balancing via AJP ie :<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">	--> <Engine name="Catalina" defaultHost="localhost">	 <!--For clustering, please take a look at documentation at:		/docs/cluster-howto.html(simple how to)		/docs/config/cluster.html (reference documentation) -->	 <!--	 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>	 -->	 	 <!-- The request dumper valve dumps useful debugging information about		 the request and response data received and sent by Tomcat.		 Documentation at: /docs/config/valve.html -->	 <!--	 <Valve className="org.apache.catalina.valves.RequestDumperValve"/>	 -->	 <!-- This Realm uses the UserDatabase configured in the global JNDI		 resources under the key "UserDatabase".Any edits		 that are performed against this UserDatabase are immediately		 available for use by the Realm.-->	 <Realm className="org.apache.catalina.realm.UserDatabaseRealm"		 resourceName="UserDatabase"/>	 <!-- Define the default virtual host		 Note: XML Schema validation will not work with Xerces 2.2.	-->	 <Host name="localhost"appBase="webapps"		unpackWARs="true" autoDeploy="true"		xmlValidation="false" xmlNamespaceAware="false">	 <!-- SingleSignOn valve, share authentication between web applications		 Documentation at: /docs/config/valve.html -->	 <!--	 <Valve className="org.apache.catalina.authenticator.SingleSignOn" />	 -->	 <!-- Access log processes all example.		 Documentation at: /docs/config/valve.html -->	 <!--	 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"			prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>	 -->	 </Host></Engine></Service></Server>

修改完后,启动tomcat,如果Windows访问Linux的Tomcat,显示无法连接,先查看tomcat下的logs日志文件,如果现实地址已被占用,则需重新修改,如果已经正常启动,说明防火墙未关闭。则只有修改linux防火墙的配置,打开8080端口。

1,在开启了防火墙时,做如下设置,开启相关端口,修改/etc/sysconfig/iptables 文件,添加以下内容:

        -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

2、直接关闭Linux防火墙。

在此说一下关于启动和关闭防火墙的命令

1) 重启后生效

       开启: chkconfig iptables on

       关闭: chkconfig iptables off

   2) 即时生效,重启后失效

       开启: service iptables start

       关闭: service iptables stop
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: