Deployment spring boot + pit (permissions, refresh 404, cross-domain, memory) Vue encounter

Deployment spring boot + pit (permissions, refresh 404, cross-domain, memory) Vue encounter

  Background front end is the use of separate, use of the front end VUE, backend springboot.

tool

  工欲善其事必先利其器 tools, we first find a Linux operating system is highly recommended FinalShell.

  

 

  A glance is not feeling very convenient, monitoring of memory, CPU can also be seen in real time, it is convenient to access the directory, for Linux is simply white magic weapon.

  Well, I want to start into the pit.

One problem: insufficient privileges

  The vue bags at the tomcat- next> webapps-> ROOT directory.

  Start tomcat: cd to the tomcat bin directory, and then execute ./startup.sh command.

  The first question appears: -bash: ./startup.sh: Permission denied , said the authority is not enough.

  After Baidu, execute this command: chmod + U * .sh the X- performed again on OK

Question two: Refresh 404

  I first tested Vue pack is normal, then start tomcat, can successfully access the page, but there have been 404 refresh. 

  Troubleshoot 404, in tomcat-> webapps-> ROOT directory is created under the WEB-INF directory, built web.xml file under WEB-INF directory

 

 

 

  document content:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
 4 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 5 version="3.1" metadata-complete="true">
 6 <display-name>Router for Tomcat</display-name>
 7   <error-page>
 8   <error-code>404</error-code>
 9   <location>/index.html</location>
10   </error-page>
11 </web-app>

  Restart tomcat, refresh again and will not appear 404.

Question three: Port occupation & Cross-Domain

  Start J AVA -jar xxx.jar and found to have a tomcat would get up, because the port is occupied, springboot played jar package, built tomcat server, if the server and port settings outside of the same, there will be a port conflict, If not, you can start a start, but there will be cross-domain problems.

  Is to solve the port conflict or cross-domain problem how do you choose, I will resolve the port conflict it.

  Then think of a way, since the jar package does not work, then it war package

  1, where the packet into war

1 <packaging>war</packaging>

  2, tomcat container built exclude

1 <dependency>
2    <groupId>org.springframework.boot</groupId>
3    <artifactId>spring-boot-starter-tomcat</artifactId>
4    <scope>provided</scope>
5 </dependency>

  3, modify the Application class, it inherits SpringBootServletInitializer, as follows.

1 @SpringBootApplication
2 public class Application {
3 
4     public static void main(String[] args) {
5         SpringApplication.run(Application.class, args);
6     }
7 
8 }

  改成:

 1 @SpringBootApplication
 2 public class Application extends SpringBootServletInitializer {
 3 
 4     public static void main(String[] args) {
 5         SpringApplication.run(Application.class, args);
 6     }
 7 
 8     @Override
 9     protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
10         return builder.sources(Application.class);
11     }
12 }

 问题四:配置docbase

  打完war包,访问接口时要加项目名称,为了让前端不再改代码,就在tomcat->bin->server.xml中加上如下配置:

<Context path="" docBase="/webapps/项目名称"  reloadable="true" />

  好,重启tomcat,发现页面访问不到了,猜测是因为改了docbase路径,才导致的,于是把Vue文件放到项目路径下面,

  重启tomcat,可以访问,但是刷新页面404又出现了,就是加了web.xml文件也不行。

  头疼了好半天,行吧,不折腾了,我去折腾前端去,“前端小姐姐,把你的url路径上都加上项目名称”

  前端小姐姐:“好的”。

  “卧槽,这么好说话”。

  折腾完之后,把之前的配置再改回去。

  去掉了docbase的配置,Vue文件还是放在ROOT下面。

  好了,重启tomcat,访问项目,完美解决,心里高兴了好一会儿,卧槽,牛逼呀,给自己点个赞。 

问题五:内存不够

  我怕是高兴的太早了。

  因为项目的更新,我做的反复操作就是,./shutdown.sh./srartup.sh反复的关闭tomcat和打开tomcat。

  用着用着发现启动不了了,启动的时候,报了一个内存不够的错误(当时没截图,现在不想折腾去重现这个问题了,这里就简单描述一下)。

  一看FinalShell,卧槽,内存占用完了(现在的图是后来截的,所有显示的是内存还够)。

 

 

 

  当时已经用到了15.4G,卧槽,瞬间崩溃,头都大了没找到原因。最后看一下哪些进程占用了内存吧,

  查看所有进程

1 ps -ef

  查看tomcat进程

1 ps -ef | grep tomcat

 

  发现有好三个tomcat进程,而且都是同一个tomcat,因为服务器部署了几个tomcat,看路径可以看出是同一个。但是不对呀,我每次都是先关闭tomcat,再打开,不可能会出现这么多进程呀。

  猜想不会是./shutdown.sh只会关闭tomcat不会杀死进程吧,卧槽,上网一搜有的说可以直接杀死进程,有的说不行,不管怎样都要解决呀。

  问了度娘,度娘给我两种方案,

  一种是直接杀死进程,kill -s 9 PID ,杀死PID的进程,法相确实是,杀死了两个,发现内存瞬间降下来了 。

  但是我每次关闭tomcat之后,再杀进程,那也太麻烦了。

  于是用了第二种方案。

  第一步 :vim修改tomcat下bin/catalina.sh文件,添加点东西,主要是记录tomcat的pid,如下:

 

 1 #设置记录CATALINA_PID。
 2  
 3 #该设置会在启动时候bin下新建一个CATALINA_PID文件
 4  
 5 #关闭时候从CATALINA_PID文件找到pid,kill。。。同时删除CATALINA_PID文件
 6  
 7 if [ -z "$CATALINA_PID" ]; then
 8  
 9       CATALINA_PID=$PRGDIR/CATALINA_PID
10  
11 fi

  

  第二步 vim tomcat的shutdown.sh文件,在最后一行加上-force:

 

 

 问题六:tomcat启动

 

  好,启动tomcat,访问正常,解决完毕,收工,关闭FinalShell,第一次再Linux上部署项目出现的问题都一步一步解决了,但是怎么感觉事情没那么简单。

  果然,关闭FinalShell之后,项目访问不了了。卧槽,无情 ,是不是要这样折腾我。上网搜了之后发现:

 

   1、启动tomcat服务

  方式一:直接启动 ./startup.sh

  方式二:作为服务启动 nohup ./startup.sh &

  方式三:控制台动态输出方式启动 ./catalina.sh run 动态地显示tomcat后台的控制台输出信息,Ctrl+C后退出并关闭服务

  2、解释

  通过方式一、方式三启动的tomcat有个弊端,当客户端连接断开的时候,tomcat服务也会立即停止,

  通过方式二可以作为linux服务一直运行 通过方式一、方式二方式启动的tomcat,其日志会写到相应的日志文件中,而不能动态地查看tomcat控制台的输出信息与错误情况,

  通过方式三可以以控制台模式启动tomcat服务,

  直接看到程序运行时后台的控制台输出信息,不必每次都要很麻烦的打开catalina.out日志文件进行查看,这样便于跟踪查阅后台输出信息。tomcat控制台信息包括log4j和System.out.println()等输出的信息。

  最后nohup ./startup.sh &这样启动,完美解决。小夜的第一次Linux部署项目之旅就此结束了,一路上也是坎坎坷坷,一步一个坑,但是也都一个一个解决了。

 

Guess you like

Origin www.cnblogs.com/yeshensi/p/11812391.html