遠端伺服器部署spring boot 專案(centos7為例)
阿新 • • 發佈:2018-12-22
1.打包專案(可以是jar包,也可以是war包)以jar包為例(用eclipse打包):
1.專案目錄右擊--debug as(run as)--maven build,然後輸入package,點選debug,就會在t
arget目錄生成相應的包:
2.上傳專案:上傳方法可選如下兩種
第一種方式:SecureCRT下上傳檔案只需在shell終端模擬器中輸入命令“rz”,即可從彈出的對話方塊中選擇本地磁碟上的檔案,利用Zmodem上傳到伺服器當前路徑下。下載檔案只需在shell終端模擬器中輸入命令“sz 檔名”,即可利用Zmodem將檔案下載到本地某目錄下。通過“File Transfer”可以修改下載到本地的預設路徑。設定預設目錄:options-->session options-->file transfer。
quit: 斷開FTP連線
3.為了讓我們的程式在關閉終端後仍然能繼續執行我們需要寫兩個指令碼:satrt.sh和stop.sh/chck.sh
centos下命令:
vim start.sh
#!/bin/sh rm -f tpid nohup java -jar [執行檔名].jar >[日誌檔名].out 2>&1 & echo $! > tpid echo Start Success!
vim stop.sh
#!/bin/sh
APP_NAME=執行檔名
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
else
echo 'Stop Success!'
fi
vim chck.sh
#!/bin/sh
APP_NAME=執行檔名
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'App is running.'
else
echo 'App is NOT running.'
fi
接著,修改start.sh/stop.sh許可權
chmod 777 start.sh
chmod 777 stop.sh
chmod 777 chck.sh
4.執行start.sh
./start.sh