JAVA project in the server deployment process

1. Deploy after local packaging and uploading to the server

recommend the first

Manual packaging in the springboot project

Packaging dependencies
LcebLj.png

	<parent>
        <artifactId>spring-boot-dependencies</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>2.3.3.RELEASE</version>
    </parent>

he contains

<!--将应用打包成一个可以执行的jar包-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

But it is recommended to write a build tag yourself
Build detailed configuration reference article https://www.cnblogs.com/whx7762/p/7911890.html

	<!--将应用打包成一个可以执行的jar包-->
	<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Pack

LcmD7n.png

jar package location

LcmoA1.png

LcnP9f.png

Use winSCP to upload to the server /data/tmp file

LcnTbj.png

启动项目:把jar复制到程序目录,通过java命令行的方式启动jar包文件。因为本项目是使用了spring boot框架,所以jar中内置了web容器,不需要额外安装tomcat了。

mkdir -p /data/app/pro-stuleave-boot

cd /data/tmp

mv /data/tmp/pro-stuleave-boot-1.0.jar /data/app/pro-stuleave-boot/

cd /data/app/pro-stuleave-boot

nohup java -jar pro-stuleave-boot-1.0.jar &

#如果出现:nohup: ignoring input and redirecting stderr to stdout
#意思是 :忽略输入并将输出附加到`nohup.out’
他在当前目录创建了一个nohup.out文件记录日志
直接回车
然后输
tail -300f nohup.out
程序就正常启动了

也可以不执行nohup java -jar pro-stuleave-boot-1.0.jar &
执行这条命令
nohup java -jar kaoqin20210327.jar >nohup.out 2>&1 &
或者自定义日志文件位置
-------------------------------------------
#这种方法会把日志文件输入到你指定的文件中,没有则会自动创建。进程会在后台运行。
nohup java -jar pro-stuleave-boot-1.0.jar >temp.txt &

#如果出现:nohup: ignoring input and redirecting stderr to stdout
#意思是 :忽略输入并将输出附加到`nohup.out’

直接回车
然后输
#查看日志,验证项目是否成功运行。 
tail -300f temp.txt
程序就正常启动了
启动成功后按Ctrl+c退出项目,项目也不会停止运行


Linux运行jar包与停止命令
a、执行jar包的命令和在windows操作系统上是一样的,都是java -jar xxxx.jar。
b、后台运行,nohup 意思是不挂断运行命令,当账户退出或终端关闭时,程序仍然运行
#当用 nohup 命令执行作业时,缺省情况下该作业的所有输出被重定向到nohup.out的文件中,除非另外指定了输出文件。
#nohup java -jar pro-stuleave-boot-1.0.jar

c、如果想杀掉运行中的jar程序,查看进程命令为:
ps aux|grep pro-stuleave-boot-1.0.jar

将会看到此jar的进程信息
root     22337  0.5 18.1 3123956 347272 pts/1  Sl   16:48   0:11 java -jar pro-stuleave-boot-1.0.jar
root     22521  0.0  0.1 221592  2408 pts/2    S+   17:26   0:00 grep --color=auto pro-stuleave-boot-1.0.jar

其中22337则为此jar的pid,杀掉命令为
kill -9 22337

启动项目重复上述操作

2. The server uses the git command to pull down the project and package the deployment process

Notice: The same configuration as above is still required in maven

1. Clone the latest code from the git repository.

#创建git仓库目录,clone项目源代码
mkdir -p /data/gitee
cd /data/gitee
#[email protected]:y_project/RuoYi.git为自己项目的ssh
git clone [email protected]:y_project/RuoYi.git

2. Use the visual database development tool Navicat to link the server MySQL locally. Create a database and execute the required data script.sql

3. Modify the configuration file in the project, configuration file application.yml

#进入自己项目的resources文件夹下
cd /data/gitee/   .....   /src/main/resources/
#修改application.yml的项目启动端口号,该端口号必须在服务器安全组有配置,且不被使用
vim application.yaml
#修改application.yaml的数据源(MySQL、Redis等和自己在application配置的一些数据)
vim application.yml
server:
  port: 端口号

spring:
  application:
    name: 项目名

  aop:
    auto: true
    proxy-target-class: true

  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://服务器ip:3306/数据库名?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
    username: 
    password: 
    druid:
      max-active: 300
      filters: stat
      initialSize: 2
      maxWait: 60000
      timeBetweenEvictionRunsMillis: 60000
      minEvictableIdleTimeMillis: 300000
      validationQuery: SELECT 1
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      poolPreparedStatements: false
      maxPoolPreparedStatementPerConnectionSize: 200
      
  redis:
    # Redis数据库索引(默认为0)
    database: 0
    # Redis服务器地址
    host: 
    # Redis服务器连接端口
    port: 6379
    # Redis服务器连接密码
    password: 
    lettuce:
      pool:
        # 连接池最大连接数(使用负值表示没有限制) 默认 8
        # 这里要参考Redis服务器的最大连接配置
        maxActive: 100
        # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1
        maxWait: 3000
        # 连接池中的最大空闲连接 默认 8
        maxIdle: 1
        # 连接池中的最小空闲连接 默认 0
        minIdle: 1

mybatis:
  mapper-locations: classpath:mapper/**/*.xml
  type-aliases-package: run.leave.mapper

management:
  endpoints:
    web:
      exposure:
        include: '*'

4. After modifying the configuration file of the project, package the entry project. Packaged into an executable jar package through mvn.

cd /data/gitee/RuoYi-Vue/
mvn clean install -pl com.ruoyi:ruoyi-admin -am

5. Start the project: copy the jar to the program directory, and start the jar package file through the java command line. Because this project uses the spring boot framework, the web container is built into the jar, and there is no need to install tomcat additionally.

mkdir -p /data/app/ruoyi-vue
cp /data/gitee/RuoYi-Vue/ruoyi-admin/target/ruoyi-admin.jar /data/app/ruoyi-vue/ruoyi-admin.jar
cd /data/app/ruoyi-vue/
nohup java -jar ruoyi-admin.jar &
#nohup和&用来表示本命令需要在后台执行,这样退出命令行程序后,java程序也不会停止。

L2nyVJ.png

This press Enter or Ctrl+c appears

enter

#查看日志,验证项目是否成功运行。 
tail -300f nohub.out

Just start the project normally

After the startup is successful, press Ctrl+c to exit the project, and the project will not stop running

如果想杀掉运行中的jar程序,查看进程命令为:
ps aux|grep pro-stuleave-boot-1.0.jar

将会看到此jar的进程信息
root     22337  0.5 18.1 3123956 347272 pts/1  Sl   16:48   0:11 java -jar pro-stuleave-boot-1.0.jar
root     22521  0.0  0.1 221592  2408 pts/2    S+   17:26   0:00 grep --color=auto pro-stuleave-boot-1.0.jar

其中22337则为此jar的pid,杀掉命令为
kill -9 22337

启动项目重复上述操作

note resources
Link: https://pan.baidu.com/s/1MQQGnCJr3XPhMviS96u0mQ
Extraction code: 3wls

Reference document
https://mp.weixin.qq.com/s/FqfGbYRvhiTU7q0aB1d2EA

https://mp.weixin.qq.com/s?__biz=Mzg2ODU0NTA2Mw==&mid=2247484347&idx=1&sn=087b67ecbd0896146f4787dfe55d52be&source=41#wechat_redirect

Guess you like

Origin blog.csdn.net/munangs/article/details/124345341