如何快速搭建一个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 复制代码
相关推荐
涡能增压发动积21 小时前
同样的代码循环 10次正常 循环 100次就抛异常?自定义 Comparator 的 bug 让我丢尽颜面
后端
Wenweno0o21 小时前
0基础Go语言Eino框架智能体实战-chatModel
开发语言·后端·golang
swg32132121 小时前
Spring Boot 3.X Oauth2 认证服务与资源服务
java·spring boot·后端
tyung21 小时前
一个 main.go 搞定协作白板:你画一笔,全世界都看见
后端·go
逛逛GitHub21 小时前
面壁智能开源了支持音色设计、克隆、30语言+9 种方言的语音大模型
github
gelald21 小时前
SpringBoot - 自动配置原理
java·spring boot·后端
小领航21 小时前
用 Three.js + Vue 3 打造炫酷的 3D 行政地图可视化组件
前端·github
李同学Lino21 小时前
别再让Agent瞎写屎山代码了!带你用Superpowers重塑Vibe Coding体验(附保姆级教程)
github
殷紫川21 小时前
深入拆解 Java 内存模型:从原子性、可见性到有序性,彻底搞懂 happen-before 规则
java·后端
元宝骑士21 小时前
FIND_IN_SET使用指南:场景、优缺点与MySQL优化策略
后端·mysql