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

第一次部署javaweb项目到linux(详细)

2017-11-10 14:34 309 查看

0.准备工作:

先准备好工具:Xftp 5和Xshell 5

1.先安装tomcat(XShell5里进行):

sa@iZ94sgjyh2cZ:~/service$ tar -vxf apache-tomcat-8.0.43.tar.gz

把解压出来的文件夹改名为air(我个人的项目名):
sa@iZ94sgjyh2cZ:~/service$ mv apache-tomcat-8.0.43 air

现在air文件夹里的结构大概是这样的(在Xftp 5里看):



2.开始部署web项目:

先删除webapps文件加下的所有文件:

sa@iZ94sgjyh2cZ:~/service/air$ rm -rf webapps/*

再在webapps目录上创建一个名为ROOT的目录:
sa@iZ94sgjyh2cZ:~/service/air/webapps$ mkdir ROOT

然后把项目的war包拖进ROOT目录里(用Xftp 5),现在的结构是这样的:



然后解压air.war:
sa@iZ94sgjyh2cZ:~/service/air/webapps/ROOT$ jar -xvf air.war 

解压后大概是这样的:



3.修改tomcat端口配置(如果没有端口占用冲突,可以忽略此步骤):

在conf目录下修改tomcat配置文件:
sa@iZ94sgjyh2cZ:~/service/air/conf$ vim server.xml 

修改web登录端口,先找到这段:
<Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

如果当前有应用占用8080端口, 那么就需要改写port属性,这里我改为9081,即port="9081"

同理,修改服务停止的端口,找到这段:

<Server port="8005" shutdown="SHUTDOWN">

如果当前有应用占用8005端口, 那么就需要改写port属性,这里我改为9516,即port="9516"

另外,如果需要修改项目路径(我的项目里就不做这步一了),找到这段:

<Host name="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true">

        <!-- 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

             Note: The pattern used is equivalent to using pattern="common" -->

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"

               prefix="localhost_access_log" suffix=".txt"

               pattern="%h %l %u %t "%r" %s %b" />

</Host>

我们可以在Host标签中添加一个子节点:

<Context path="/air" docBase="/webapps/ROOT" debug="0" privileged="true" reloadable="false"  />

4.启动/停止tomcat服务:

做完以上步骤,现在可以尝试启动tomcat了,先进入tomcat的bin目录,然后执行./startup.sh命令启动tomcat:
sa@iZ94sgjyh2cZ:~/service/air/bin$ ./startup.sh 

我可以顺利启动了:
Using CATALINA_BASE:   /home/sa/service/air

Using CATALINA_HOME:   /home/sa/service/air

Using CATALINA_TMPDIR: /home/sa/service/air/temp

Using JRE_HOME:        /usr/lib/jvm/java-7-openjdk-amd64

Using CLASSPATH:       /home/sa/service/air/bin/bootstrap.jar:/home/sa/service/air/bin/tomcat-juli.jar

Tomcat started.

同理,如果想停止tomcat服务:

sa@iZ94sgjyh2cZ:~/service/air/bin$ ./shutdown.sh 

停止了:

Using CATALINA_BASE:   /home/sa/service/air

Using CATALINA_HOME:   /home/sa/service/air

Using CATALINA_TMPDIR: /home/sa/service/air/temp

Using JRE_HOME:        /usr/lib/jvm/java-7-openjdk-amd64

Using CLASSPATH:       /home/sa/service/air/bin/bootstrap.jar:/home/sa/service/air/bin/tomcat-juli.jar

5.没了

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