linux一键部署
linux一键自动部署
一、部署本地jar包
使用如下shell脚本,修改server_file和user变量指向本地环境,运行脚本完成部署
#!/bin/bash server_file="algorithm" user="ec2-user" echo "$server_file killing..." ps -ef |grep $server_file-0.0.1.jar |grep -v grep |awk '{print $2}'|xargs kill -9 cd /home/$user echo "cd /home/$user" echo "move jar file $server_file.jar to target folder" cp ./$server_file-0.0.1.jar ./application/$server_file/$server_file-0.0.1.jar echo "cd ./application/$server_file" cd ./application/$server_file echo "init environment variable" export SERVER_PORT=8000 echo "starting service.." echo "java -server -Xms512m -Xmx1024m -jar ./$server_file-0.0.1.jar > test.log &.." nohup java -server -Xms512m -Xmx1024m -jar ./$server_file-0.0.1.jar > test.log &
二、部署git分支
1.安装git和maven至Linux环境
2.使用git clone命令克隆git分支至linux
#配置用户名邮箱
git config --global user.name cmbt@mail.com
git config --global user.email cmbt@mail.com
配置查询
git config --list --global
生成秘钥,并把公钥添加至git
ssh-keygen -t rsa -C "******@mail.com"
克隆代码至linux
git clone git@github.com:....git
查看所有分支
git branch -a
切换至需部署的远程分支创建本地分支
git checkout -b test origin/test
3.使用如下shell脚本拉取代码并打包部署
cd /home/ec2-user/workspace/project git pull mvn clean package rm -rf /home/ec2-user/project-0.0.1.jar mv target/project-0.0.1.jar /home/ec2-user/ ps -ef |grep project-0.0.1.jar |grep -v grep |awk '{print $2}'|xargs kill -9 cd /home/ec2-user nohup java -jar /home/ec2-user/project-0.0.1.jar --server.port=8000 &