1、war包部署需要依赖外部的tomcat,项目需要排除springboot内部的tomcat
1)修改项目中pom.xml
①修改打包方式 <packaging>war</packaging> ②修改maven插件 <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <!-- 打war包,忽略所有的jar包 --> <configuration> <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes> </configuration> </plugin> </plugins>
2)添加SpringBootWebApplication类和启动类同级别目录,部署时排除内部tomcat,builder.sources(BsApplication.class);BsApplication.class为启动类
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; public class SpringBootWebApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { // 注意这里要指向原先用main方法执行的Application启动类 return builder.sources(BsApplication.class); } }
2、将tomcat拷贝到目标目录中【地址8080】
3、修改tomcat的server.xml文件
1)查看tomcat端口号* omcat8confserver.xml,
<Connector port="15002" rotocol="org.apache.coyote.http11.Http11Nio2Protocol" connectionTimeout="20000" redirectPort="8443" executor="tomcatThreadPool" enableLookups="false" acceptCount="200" maxPostSize="10485760" disableUploadTimeout="true" acceptorThreadCount="2" URIEncoding="utf-8"/>
查看服务器上的端口号,一共三个端口,看看是否都被占用,如果被占用需要修改,执行命令
netstat -tunlp |grep 端口号 或 lsof -i:端口号
2)Host 标签中添加部署的项目名称,否则部署后访问404,将标签<Context docBase="bs-dev" path="/" reloadable="true"/>中的bs-dev换成自己的项目名称
<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" /> <Context docBase="bs-dev" path="/" reloadable="true"/> </Host>
4、将前端项目放到项目目录中
/data/dm_bs_service/tomcat_bs/webapps/bs-dev/
5、如果没有执行权限,执行命令
chmod +x catalina.sh
6、进入bin目录启动项目
./shutdown.sh 关闭 ./startup.sh 启动
7、项目的访问,服务器IP+端口
其他
解决上传大小限制
修改maxPostSize="10485760" 将其删除或者-1(代表无限制)
修改java堆栈大小 omcat8incatalina.sh
JAVA_OPTS='-server -Xms1024m -Xmx2048m'