如何快速搭建一个JAVA持续交付环境

  1. JDK 2.
  2. maven
js 复制代码
https://downloads.apache.org/maven/maven-3/3.9.12/

sudo wget https://archive.apache.org/dist/maven/maven-3/3.9.12/binaries/apache-maven-3.9.12-bin.tar.gz -P /opt
sudo tar -zxvf apache-maven-3.8.8-bin.tar.gz -C /usr/local
sudo mv /usr/local/apache-maven-3.8.8 /usr/local/maven3.8

# 4. 配置环境变量
echo "export MAVEN_HOME=/usr/local/maven3.8" | sudo tee -a /etc/profile
echo "export PATH=\$PATH:\$MAVEN_HOME/bin" | sudo tee -a /etc/profile
source /etc/profile

# 5. 验证安装
mvn -v
  1. 调整设置私有仓库
xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  
  <!-- 本地仓库路径(可选) -->
  <localRepository>${user.home}/.m2/repository</localRepository>
  
  <!-- 交互模式设置 -->
  <interactiveMode>true</interactiveMode>
  
  <!-- 离线模式设置 -->
  <offline>false</offline>
  
  <!-- 插件组设置 -->
  <pluginGroups></pluginGroups>
  
  <!-- 代理设置(如果使用代理) -->
  <proxies></proxies>
  
  <!-- 镜像配置 -->
  <mirrors>
    <mirror>
      <id>zgf-mirror</id>
      <name>zgf Public Repository Mirror</name>
      <url>http://nexus.zgf.com:8081/nexus/content/groups/public/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>
  
  <!-- Profile 配置 -->
  <profiles>
    <profile>
      <id>zgf-repo</id>
      <!-- 普通依赖仓库 -->
      <repositories>
        <repository>
          <id>zgf-public</id>
          <name>zgf Public Repository</name>
          <url>http://nexus.zgf.com:8081/nexus/content/groups/public/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
          </snapshots>
        </repository>
      </repositories>
      <!-- 插件仓库 -->
      <pluginRepositories>
        <pluginRepository>
          <id>zgf-public</id>
          <name>zgf Public Plugin Repository</name>
          <url>http://nexus.zgf.com:8081/nexus/content/groups/public/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  
  <!-- 激活的 Profile -->
  <activeProfiles>
    <activeProfile>zgf-repo</activeProfile>
  </activeProfiles>
  
  <!-- 服务器认证信息(如果需要) -->
  <servers>
    <!-- 如果需要认证,添加以下配置 -->
    <!--
             <server>
      <id>juzifenqi-public</id>
      <username>your-username</username>
      <password>your-password</password>
    </server>
    -->
  </servers>
  
</settings>
  1. git
shell 复制代码
# 1. 安装Git
sudo yum install -y git

# 2. 验证安装
git --version
  1. 配置公钥到GIT
shell 复制代码
### 1. 生成SSH密钥

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
### 2. 添加SSH密钥到ssh-agent
eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_rsa

cat ~/.ssh/id_rsa.pub
  1. 发布脚本
shell 复制代码
#!/bin/bash
cd /data/zgf
echo "开始克隆代码"
if [ ! -d "cmmmmmmm" ]; then
  git clone -b test-uat-251227 git@git.zgf.cn:background/cmmmmmmm.git
  cd cmmmmmmm
  git branch --set-upstream-to=origin/test-uat-251227 test-uat-251227
else
  echo "代码已存在,开始更新"
  cd cmmmmmmm
  git checkout test-uat-251227
  git fetch --all
  git pull origin test-uat-251227 || { echo "拉取失败,尝试重置"; git reset --hard origin/test-uat-251227; }
fi
cd cmmmmmmm-backend
pwd
# 打包
echo "开始打包"
mvn clean package -DskipTests
echo "打包完成"
# 备份旧包
TIMESTAMP=$(date +%Y%m%d%H%M%S)
echo "开始备份旧包到 bak/cmmmmmmm-backend.jar.$TIMESTAMP"
mv /data/App/cmmmmmmm-backend/cmmmmmmm-backend.jar /home/ops/zgfjar/cmmmmmmm-backend.jar.bak.$TIMESTAMP
# 替换新包
echo "替换新包到部署目录"
cp target/cmmmmmmm-backend.jar /data/App/cmmmmmmm-backend/
# 重启服务

cd /data/App/cmmmmmmm-backend/bin
echo "停止服务"
sh stop.sh
echo "启动服务"
sh start.sh
echo "部署完成"
js 复制代码
shell 复制代码
相关推荐
Hommy8819 分钟前
【剪映小助手】添加图片接口(Add Images)
后端·github·剪映小助手·视频剪辑自动化
GetcharZp1 小时前
别再盲目用 OpenCV 读图了,这才是 CV 预处理的终极杀手锏!
后端
徐小夕2 小时前
Loop Engineering 深度解析与实战指南(全网最全)
前端·算法·github
Cosolar4 小时前
Docsify零构建文档站完全指南:从快速搭建到企业级部署
前端·开源·github
星栈独行4 小时前
Makepad 应用如何读文件、调接口、保存数据
前端·程序人生·ui·rust·github
IT_陈寒5 小时前
Vite热更新失效?可能你在用Windows
前端·人工智能·后端
椰椰椰耶6 小时前
[SpringCloud][14]OpenFeign参数传递方法
后端·spring·spring cloud
onething3656 小时前
Spring Boot + Spring AI 从入门到实战:7天转型计划 Day 3 —— 消息表设计 + 级联删除 + 事务管理
人工智能·后端
荣江6 小时前
Hermes Agent 代码仓库打包工具使用指南(repomix-rs 高性能版)
后端
王某某人6 小时前
LangChain4j 入门:Java 程序员的第一个 AI 对话程序
人工智能·后端