一、jar包和依赖包分离
在pom文件中新增:
<!-- 注释后和依赖包一起打包 取消注释则不打包依赖-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
</plugin><!-- 生成lib包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-lib</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
修改启动脚本-增加-Dloader.path=lib
nohup java -XX:+UseG1GC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -Xloggc:./gclog/gc.log -Xms3g -Xmx3g -jar -Dloader.path=lib -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5219 opera-system.jar > default.log 2>&1 &
~
二、配置文件外置
java -jar 启动的时候会优先读取config目录下的配置文、可以把配置文件外置到config目录下、可以通过spring.profiles.active:dev 读取特定文件
三、nginx配置
3.1 路由到特定服务
在配置文件中加如下代码
location /ds {
proxy_pass http://172.16.102.11:18088;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
}
3.2 路由特定web 服务
location /siling_gzxd_face/ {
alias /u01/isi/gzdx_face/;
}
3.3集群配置
upstream dsServer {
server 172.16.101.31:18091;
server 172.16.101.33:18090;
}
location /ds {
proxy_pass http://dsServer;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
}
四、session共享
1、在pom文件中引入
<dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> </dependency>
2、在启动类上添加注解
@EnableRedisHttpSession(redisNamespace = "ds_system_v2:session")
五、涉及的到常见linux命令
查看端口号: lsof -i: 18090
[isi@meixuan-33 dqgz-system]$ lsof -i:18090
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 20633 isi 285u IPv6 83827872 0t0 TCP *:18090 (LISTEN)
对 jar 解压:jar -xvf dqgz-system.jar
springboot 项目jar包解压后、修改配置文件后、在不依赖开发工具的情况下、重新压缩jar包、命令是:jar -cvfM0 xxx.jar .