如何快速搭建一个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 复制代码
相关推荐
子兮曰3 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰3 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
爱勇宝3 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
胡写代码3 天前
别再前后端各写一套表单校验了
java·后端
大勇前进3 天前
原生 PHP 还是 Laravel?小项目到底要不要上框架
后端
yuzhi_liu3 天前
我用 LangGraph4j 实现 Multi-Agent Supervisor
后端
alsmile3 天前
Node-RED 之外,国产规则引擎的新方案:基于标准语法,Go 先行实现
后端·开源·go
大白803 天前
PHP 内存溢出排查思路:看懂报错日志,精准定位问题
后端
二月龙3 天前
PHP 接口返回统一响应封装,让前后端对接更省心
后端
盖伦发发3 天前
软件工程SOLID 五大设计原则
后端·软件工程