- 使用終端 通過ssh命令 遠(yuǎn)程操作服務(wù)器
<!-- root表示用戶名 @接host -->
ssh root@ip地址
<!-- 接下來輸入密碼 -->
balabala這是密碼
這樣就連上服務(wù)器了。
- cd到指定的目錄
cd /data/install/node-photo/SBEARAPI/
使用git更新代碼
git pull 或者 git clone重新啟動(dòng)
<!-- 端口7070 守護(hù)進(jìn)程 -->
PORT=7070 node app.js &
如果報(bào)錯(cuò)
events.js:160
throw er; // Unhandled 'error' event
可能是之前的進(jìn)程沒殺掉,需要?dú)⒌暨M(jìn)程
pkill node
然后重新運(yùn)行第4步即可
- 安全退出ssh
點(diǎn)擊回車
回到命令行界面
輸入exit安全退出ssh
推薦使用進(jìn)程pm2管理進(jìn)程
pm2 是專門管理node進(jìn)程的,他可以讓你的應(yīng)用永久存活,
- 安裝pm2
npm install pm2 -g
- 使用pm2
pm2 start app.js
General
$ npm install pm2 -g # Install PM2
$ pm2 start app.js # Start, Daemonize and auto-restart application (Node)
$ pm2 start app.py # Start, Daemonize and auto-restart application (Python)
$ pm2 start npm -- start # Start, Daemonize and auto-restart Node application
Listing all running processes:
$ pm2 list
Managing your processes is straightforward:
$ pm2 stop <app_name|id|'all'|json_conf>
$ pm2 restart <app_name|id|'all'|json_conf>
$ pm2 delete <app_name|id|'all'|json_conf>
To make sure it re-evaluates enviroment variables declared in your json_conf pass it as argument, and optionally your custom env name from your json_conf if any:
$ pm2 restart <json_conf> [--env <env_name>]