Linux CentOS下部署Java Web项目

Posted moonsoft

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux CentOS下部署Java Web项目相关的知识,希望对你有一定的参考价值。

本文讲解如何在Linux CentOS下部署Java Web项目的步骤。

一、环境准备:

(1)Linux CentOS

(2)apache-tomcat-9.0.10

(3)XShell

二、启动tomcat

1、启动Tomcat

进入 apache-tomcat-9.0.10 下的 bin 目录下

输入:  ./catalina.sh start

[root@izuf6famz0x92jd98na1kiz bin]# ./catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat/apache-tomcat-9.0.10
Using CATALINA_HOME:   /usr/local/tomcat/apache-tomcat-9.0.10
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.10/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_171
Using CLASSPATH:       /usr/local/tomcat/apache-tomcat-9.0.10/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.10/bin/tomcat-juli.jar
Tomcat started.

2、查看 tomcat 启动日志[可选]

进入 apache-tomcat-9.0.10/logs 下

[root@izuf6famz0x92jd98na1kiz apache-tomcat-9.0.10]# ls
bin  conf  lib  LICENSE  logs  NOTICE  RELEASE-NOTES  RUNNING.txt  temp  webapps  work
[root@izuf6famz0x92jd98na1kiz apache-tomcat-9.0.10]# cd logs
[root@izuf6famz0x92jd98na1kiz logs]# ls
catalina.2018-07-04.log  host-manager.2018-07-04.log  localhost.2018-07-05.log             manager.2018-07-04.log
catalina.2018-07-05.log  host-manager.2018-07-05.log  localhost_access_log.2018-07-04.txt  manager.2018-07-05.log
catalina.out             localhost.2018-07-04.log     localhost_access_log.2018-07-05.txt

执行 cat catalina.out

 

注: ./catalina.sh start 和 ./startup.sh 都能启动tomcat。使用 ./catalina.sh stop 或 ./shutdown.sh 停止tomcat。

 

可以查看 tomcat 启动日志:

[root@izuf6famz0x92jd98na1kiz logs]# cat catalina.out
04-Jul-2018 18:32:03.012 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/9.0.10
04-Jul-2018 18:32:03.013 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 20 2018 17:32:21 UTC
04-Jul-2018 18:32:03.013 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         9.0.10.0
04-Jul-2018 18:32:03.013 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
04-Jul-2018 18:32:03.013 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-693.2.2.el7.x86_64
04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/java/jdk1.8.0_171/jre
04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_171-b11
04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat/apache-tomcat-9.0.10
……省略05-Jul-2018 14:05:43.147 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-9.0.10/webapps/manager] has finished in [49] ms
05-Jul-2018 14:05:43.147 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/apache-tomcat-9.0.10/webapps/host-manager]
05-Jul-2018 14:05:43.187 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-9.0.10/webapps/host-manager] has finished in [39] ms
05-Jul-2018 14:05:43.198 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
05-Jul-2018 14:05:43.209 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
05-Jul-2018 14:05:43.210 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 565104 ms

3、访问浏览器,验证tomcat启动成功

二、上传要部署项目文件到服务器

1、安装上传文件到 Linux 中的工具软件

lrzsz

安装指令如下:

yum install lrzsz

[root@izuf6famz0x92jd98na1kiz download]# yum install lrzsz
Loaded plugins: fastestmirror
base                                                                                                  | 3.6 kB  00:00:00     
epel                                                                                                  | 3.2 kB  00:00:00     
extras                                                                                                | 3.4 kB  00:00:00     
updates                                                                                               | 3.4 kB  00:00:00     
(1/7): base/7/x86_64/group_gz                                                                         | 166 kB  00:00:00     
(2/7): epel/x86_64/group_gz                                                                           |  88 kB  00:00:00     
(3/7): epel/x86_64/updateinfo                                                                         | 927 kB  00:00:00     
(4/7): extras/7/x86_64/primary_db                                                                     | 149 kB  00:00:00     
(5/7): epel/x86_64/primary                                                                            | 3.5 MB  00:00:00     
(6/7): base/7/x86_64/primary_db                                                                       | 5.9 MB  00:00:00     
(7/7): updates/7/x86_64/primary_db                                                                    | 2.7 MB  00:00:00     
Determining fastest mirrors
epel                                                                                                             12608/12608
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                    Arch                        Version                              Repository                 Size
=============================================================================================================================
Installing:
 lrzsz                      x86_64                      0.12.20-36.el7                       base                       78 k

Transaction Summary
=============================================================================================================================
Install  1 Package

Total download size: 78 k
Installed size: 181 k
Is this ok [y/d/N]: 

输入 "y"

Is this ok [y/d/N]: y
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm                                                                                                                             |  78 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : lrzsz-0.12.20-36.el7.x86_64                                                                                                                                     1/1 
  Verifying  : lrzsz-0.12.20-36.el7.x86_64                                                                                                                                     1/1 

Installed:
  lrzsz.x86_64 0:0.12.20-36.el7                                                                                                                                                    

Complete!

验证是否安装成功:

[root@izuf6famz0x92jd98na1kiz download]# rpm -qa|grep lrzsz
lrzsz-0.12.20-36.el7.x86_64

出现如上,即是安装成功。

2、将项目部署文件上传到服务器

(1)使用 lrzsz 上传文件到服务器

输入 rz ,即弹出 本地电脑的文件选择框,选择要上传到服务器的文件

(2)选择要部署项目 的 war 文件

windows 下的文件:

上传到 阿里云的 linux服务器上:

3、ls指令查看当前目录

 

三、部署项目

1、将打包好的war包上传到tomcat服务器的webapps目录

[root@izuf6famz0x92jd98na1kiz webapps]# cp /usr/download/WeChatJPro_01.war /usr/local/tomcat/apache-tomcat-9.0.10/webapps
[root@izuf6famz0x92jd98na1kiz webapps]# ls
docs  examples  host-manager  manager  ROOT  WeChatJPro_01  WeChatJPro_01.war

可以发现Tomcat服务器自动解压缩war包

 

2、在浏览器上访问部署的项目

浏览器地址栏输入: http://IP地址:8080/项目名

最终:成功的在阿里云ECS 的 Linux CentOS服务器上部署好Java Web项目!

 

 

 扫个红包吧!

 

 

 

 

Donate捐赠

如果我的文章帮助了你,可以赞赏我 1 元给我支持,让我继续写出更好的内容)

   

  (微信)                                        (支付宝)

微信/支付宝 扫一扫

以上是关于Linux CentOS下部署Java Web项目的主要内容,如果未能解决你的问题,请参考以下文章

Linux(Centos)之安装tomcat并且部署Java Web项目

新手小白Linux(Centos6.5)部署java web项目(mongodb4.0.2安装及相关操作)

新手小白Linux(Centos6.5)部署java web项目(总)

Linux(Centos)之安装tomcat并且部署Java Web项目(转)

在linux环境下搭建java web测试环境(非常详细!!)

新手小白Linux(Centos6.5)部署java web项目(mysql5.7安装及相关操作)