记录一次在云服务器上部署一个springboot项目的记录,为了打破部署很难的认知哈哈哈。
本文只是为了记思路,不是一篇操作贴
前置准备
- 华为云服务器
- 宝塔工具(一款运维工具,在服务器上安装mysql,redis等工具就像呼吸一样自然)
- 打包一个springboot项目的jar
- 服务器连接工具,如XShell或者MobaXterm这种
问题汇总
- 华为云服务器,如何配置安全组、为什么要配置安全组
- 服务器防火墙的启用,开放端口,reload防火墙配置
- springboot项目打包(项目没加日志时)需要的插件
- springboot项目打包(加日志时)需要的插件
- 额外找到的,如何根据springboot官网文档的提示配好配置文件(屏蔽等级太低的日志)
- java -jar命令
- 思考:目前项目的jar是死的,因为没有托管到Git管理。操作jar的时候我反复从服务器删掉旧jar再上传新jar。这个操作贼麻烦。有了Jenkins和git应该就能更灵活了吧
- 请求接口,为什么只能请求通外网的,内网ip+端口请求不同
- arthas安装很丝滑
- maven打包时碰到单元测试导致打包失败(可是我根本没写单元测试啊喂)最后的解决方案是我加了个插件跳过了
- 宝塔关于java项目的部署文档挺清晰的。印象深刻的是讲java项目分成三类:springboot项目,非springboot项目还是有来着,反正每种都有不同的部署方法。学到的一点是先分类再解决
- mkdir创建文件夹,rm删除指定文件的指令
- springboot版本太高和JDK8不适配
代码备忘
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo0710</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo0710</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
<!-- 尝试解决Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project demo0710: There are test failures. -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<!--加了日志配置之后(放到resource之后),不配置这个插件会报错 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project demo0710: Input length = 1 -> [Help 1]-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- 尝试跳过告警:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project demo0710: There are test failures. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<!--让Surefire插件在构建过程中跳过执行任何测试-->
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- -----------------------------------
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project gulimall-common: There are test failures.
https://blog.51cto.com/u_15127692/4536801-->
</plugins>
</build>
</project>
server.port=9998
# 阻止tomcat无效日志打印 [http-nio-9998-Poller] DEBUG org.apache.tomcat.util.net.NioEndpoint - timeout completed: keys processed=0; now=1688976795882; nextExpiration=1688976795878; keyCount=0; hasEvents=false; eval=false
logging.level.org.apache.tomcat=INFO
logging.level.org.apache.tomcat.util.net=WARN
#阻止无效日志打印
logging.level.root=info