maven,git python脚本 自动化 部署 spring boot进销存系统

准备环境

虚拟机两台

centos 7.2 192.168.255.128

centos 7.2 192.168.255.129

maven 3.0.5

java 1.8.0_181

 

git version 1.8.3.1

安装 git 
yum install git
初始化git
git  config  --global  user.name  "laoqian666"
git  config  --global  user.email  "laoqin666@abc.com"
ssh-keygen  -t  rsa  -C  "laoqian666@abc.com"
将Git 证书配置到github 上,保证linux服务器与码云 之间可以
  头像 -- 设置 -- >>
  cd ~/.ssh  把公钥文件粘贴到对话框中

 

Python 2.7.5

 

项目地址:https://gitee.com/shenduedu/JXC.git 要在自行配好数据库环境

 

centos 192.168.255.128 装上 maven,java,git

centos 192.168.255.129 装上 java

环境安装  此处不再累赘

 

注意:

1 因为要远程执行,所以要在两台虚拟机上配置ssh key

ssh-keygen -t rsa

一路按回车,然后将生成的公钥复制到 129机器上

ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.255.129

2 要在码云好配置好公钥

因为要用git 拉代码

 

 

执行任务时主要流程是

1 先从git 上pull 代码 到指定文件夹

2 然后 用maven 进行打包

3 使用scp 把打包后的文件 复制到对应服务器上

4 然后执行

 

为可方便演示,我代码都是采用硬编码的方式,请读者们谅解

python 脚本

# -*- coding: UTF-8 -*-

import os
import sys

if os.path.exists('/usr/local/deployer.lock'):
    print '程序正在执行.................'
    sys.exit(1)

file = open('/usr/local/' + 'deployer' + '.lock','w')
file.close()


res = os.system('rm -rf /usr/local/gitsource/*')
if res != 0:
    print 'delete gitsource files fail'
    res =os.remove('/usr/local/deployer.lock')
    sys.exit(1)

res = os.system('cd /usr/local/gitsource/ &&  git clone https://gitee.com/shenduedu/JXC.git')
if res != 0:
    print 'https://gitee.com/shenduedu/JXC.git fail'
    res =os.remove('/usr/local/deployer.lock')
    sys.exit(1)

res = os.system('cd /usr/local/gitsource/JXC/ &&  mvn clean package')
if res != 0:
    print 'mvn package fail'
    res =os.remove('/usr/local/deployer.lock')
    sys.exit(1)

res = os.system('ssh root@192.168.255.129 "rm -rf /opt/project/*"')

res = os.system('scp /usr/local/gitsource/JXC/target/JXC-0.0.1-SNAPSHOT.war 192.168.255.129:/opt/project/')

res = os.system('ssh root@192.168.255.129 "cd /opt/project && java -jar JXC-0.0.1-SNAPSHOT.war"')

res =os.remove('/usr/local/deployer.lock')

 

此时 执行http://192.168.255.129/

 

 

 

欢迎加入 微服务交流群

222700500

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值