Linux自动化部署OPS
- 脚本
- 10天前
- 19热度
- 0评论
通过脚本实现OPS
1、java项目
1.1、OPS服务器部署脚本
#!/bin/bash
source /etc/profile
ws=/opt/source/shopai
cd /opt/source/shopai
git pull
mvn clean package -Dmaven.test.skip=true
echo "scp jar"
cd $ws/perass-api/target
jar=$(ls perass-api-*.jar)
scp ./$jar web@192.168.1.100:/opt/deploy/
ssh web@192.168.1.100 "/opt/bin/kill_perass.sh"
sleep 3
ssh web@192.168.1.100 "/opt/bin/start_perass.sh"
echo "OK"
1.2、生产服务器
kill_perass.sh
#!/bin/bash
source /etc/profile
ps -ef | grep perass-api | grep -v grep | awk '{print $2}' | xargs kill -9
start_perass.sh
#!/bin/bash
source /etc/profile
cd /opt/deploy
jar=$(ls -th perass-api-*.jar | head -1)
nohup java -Xms1024m -Xmx2048m -jar -server $jar --spring.profiles.active=prod >logs/perass-api.log 2>&1 &
echo "perass-api OK"
2、前端项目
2.1、OPS服务器部署脚本
#!/bin/bash
source /etc/profile
cd /opt/source/perass-web
git pull
npm install
npm run build:prod
zip -r dist.zip dist
ssh web@192.168.1.100 "/opt/bin/kill_perass_web.sh"
scp dist.zip web@192.168.1.100:/opt/nginx/nginx/html/
ssh web@192.168.1.100 "cd /opt/nginx/nginx/html/; unzip dist.zip; mv dist/* ./; rm -fr dist dist.zip"
2.2、生产服务器
kill_perass_web.sh (主要是备份,保留最近的6个版本)
#!/bin/bash
source /etc/profile
cd /opt/nginx/nginx/
ls -th html-*.zip | tail -n +6 | xargs rm -f
FILEDATETIME=`date +%Y%m%d-%H%M%S`
zip -r html-"$FILEDATETIME".zip html
cd html
rm -rf ./*