java项目部署
java项目构建
这里介绍maven项目的构建和部署:
-
进行maven项目的构建
mvn clean package
-
将生成的target当中的jar包传入服务器
使用scp命令或者通过软件。这里不做介绍
服务器运行springboot项目
-
安装java17的sdk
# 包放在opt当中 mkdir /opt/jdk17 # wget下载jdk包 wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz -P /opt/jdk17/ # 解压 tar xf /opt/jdk17/jdk-17_linux-x64_bin.tar.gz -C /opt/jdk17/ # 查询sdk路径 ls /opt/jdk17 # 将java_home环境变量和jdk环境变量,直接写入profile echo ' export JAVA_HOME=/opt/jdk17/jdk-17.0.9 export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile # 执行命令读取环境变量 source /etc/profile # 查看是否成功 java -version
-
后台运行jar包
主要是使用nohup命令直接跑就可以挂起,也可以使用挂起终端的命令screen。(这里介绍nohup)
nohup java -jar shareniu.jar >output.txt &
接下来书写nginx配置文件,进行动静分离部署
```shell
upstream java-jar{
server localhost:8000;
}
server {
# 设置虚拟主机代理jar端口
location / {
proxy_pass http://java-jar;
# include /opt/tengine12/conf/proxy_params;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 代理动静分离别名
location /uploads/ {
alias /opt/backend/uploads/;
}
}
```
标签:opt,java,springboot,jdk,部署,jar,jdk17,proxy
From: https://www.cnblogs.com/lmlsh/p/18342430