Linux服务器部署tomcat服务
系统版本
- CentOS 7.5
- tomcat 7
- web项目war包
注意,tomcat服务正常使用,需要服务器已经安装好jdk,我的服务器已经安装好jdk1.7
部署操作
1、官网下载tomcat需要的版本
2、上传下载好的tomcat到服务器指定目录
可利用服务器连接工具完成
3、在需要的路径下创建文件夹,作为tomcat服务解压的服务提供路径,例如
mkdir /usr/local/tomcat
4、解压tomcat 7到指定路径,进入解压后的文件夹
tar -zxvf apache-tomcat-7.0.96.tar.gz -C /usr/local/tomcat
cd /usr/local/tomcat/apache-tomcat-7.0.96
5、启动之前要根据系统需要修改tomcat对应的配置文件,如果不需要特殊修改(如访问端口,最大连接数等),忽略此步骤
- 进入conf文件夹,修改server.xml文件中的配置,修改完成要保存
cd conf
vim server.xml
按键盘上的 i 开启编辑
添加:
<Executor name="tomcatThreadPool" namePrefix ="tyjrpt-exec-"
maxThreads="4000" minSpareThreads="1000"
maxSpareThreads="2000" />
<Connector executor="tomcatThreadPool" port="8080"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxConnections="10000" connectionTimeout="10000"
enableLookups="false"
redirectPort="8443" acceptCount="2000" URIEncoding="UTF-8" />
保存:
:wq + 回车
6、配置完成以后,返回tomcat 7目录下,进入bin目录,里面有启动和关闭tomcat服务的命令,执行启动
启动
./startup.sh
查看
ps -ef |grep tomcat
7、在执行tomcat运行命令之前,进入logs文件夹,如果是第一次执行tomcat之前,这个文件夹是空的,执行以后文件夹中会生成一些日志文件,我们可以命令查看日志,以检查tomcat运行情况
cd /***/apache-tomcat-7.0.96/logs/
查看日志
tail -f catalina.out
8、在Linux服务器中还可以根据命令来检查tomcat服务是否成功
curl http://(服务器IP地址):8080
9、到这里,tomcat 7在Linux中的部署就完了,此时可以进入 bin目录下,去执行停止服务
./shutdown.sh
10、此时可以上传项目的war包,到tomcat文件夹下的webapps下,重新启动tomcat 7,tomcat会自动将war包解压出来执行,然后就可以通过服务地址访问自己的项目了。
11、有的朋友在项目部署启动成功之后,通过另外的机器访问不通,这个时候就要根据具体情况分析原因,大多数因为Linux服务器的防火墙开启,或者端口没有开放,请参考:
12、在防火墙关闭以后启动项目发现仍然访问不到,这时候一定要记得关闭本地的网络连接代理(如果你的服务部署在本地虚拟的Linux服务器中)
13、在实际生产环境中,项目打包时本地机器上的JDK版本和Linux服务器中使用的JDK版本要对应一致,不然会出现一些想不到的问题
比如我在本地打包时使用的jdk是jdk1.8,服务器上使用的是jdk1.7.0_51,这个时候在项目上传启动tomcat后,会报出以下问题:
Oct 10, 2019 2:16:46 PM org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
Oct 10, 2019 2:16:46 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-8080"]
Oct 10, 2019 2:16:46 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Oct 10, 2019 2:16:46 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Oct 10, 2019 2:16:46 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-nio-8080"]
Oct 10, 2019 2:16:46 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
Oct 10, 2019 2:16:46 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-nio-8080"]
Oct 10, 2019 2:16:46 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
Oct 10, 2019 2:21:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Executor} Setting property 'maxSpareThreads' to '2000' did not find a matching property.
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/7.0.96
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jul 24 2019 13:00:10 UTC
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 7.0.96.0
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Linux
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 3.10.0-862.el7.x86_64
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: /u01/jdk/jre
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.7.0_51-b13
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /u01/jingdaijieru/apache-tomcat-7.0.96-bk
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /u01/jingdaijieru/apache-tomcat-7.0.96-bk
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.config.file=/u01/jingdaijieru/apache-tomcat-7.0.96-bk/conf/logging.properties
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dignore.endorsed.dirs=
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/u01/jingdaijieru/apache-tomcat-7.0.96-bk
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/u01/jingdaijieru/apache-tomcat-7.0.96-bk
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.io.tmpdir=/u01/jingdaijieru/apache-tomcat-7.0.96-bk/temp
Oct 10, 2019 2:21:35 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Oct 10, 2019 2:21:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Oct 10, 2019 2:21:35 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Oct 10, 2019 2:21:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 655 ms
Oct 10, 2019 2:21:35 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Oct 10, 2019 2:21:35 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.96
Oct 10, 2019 2:21:35 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /u01/jingdaijieru/apache-tomcat-7.0.96-bk/webapps/dscc.war
Oct 10, 2019 2:21:36 PM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
INFO: validateJarFile(/u01/jingdaijieru/apache-tomcat-7.0.96-bk/webapps/dscc/WEB-INF/lib/servlet-api-2.3.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Oct 10, 2019 2:21:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Oct 10, 2019 2:21:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/dscc] startup failed due to previous errors
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /u01/jingdaijieru/apache-tomcat-7.0.96-bk/webapps/dscc.war has finished in 4,696 ms
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /u01/jingdaijieru/apache-tomcat-7.0.96-bk/webapps/ROOT
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /u01/jingdaijieru/apache-tomcat-7.0.96-bk/webapps/ROOT has finished in 88 ms
Oct 10, 2019 2:21:40 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Oct 10, 2019 2:21:40 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Oct 10, 2019 2:21:40 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5066 ms