摘要:如何在環(huán)境下部署配置一鍵啟動(dòng)的項(xiàng)目我在內(nèi)要啟動(dòng)寫(xiě)的項(xiàng)目,我使用的是去運(yùn)行和管理項(xiàng)目。所以運(yùn)行會(huì)報(bào)沒(méi)有權(quán)限的錯(cuò)誤。不過(guò)有問(wèn)題每次啟動(dòng)的時(shí)候都要到虛擬機(jī)里面啟動(dòng)還是很麻煩還好有相關(guān)的解決方案,在目錄下有個(gè)的腳本就是用來(lái)啟動(dòng)后執(zhí)行相關(guān)操作的。
如何在 windows10 環(huán)境下部署配置一鍵啟動(dòng)的 Homestead + Laravel +vue + PM2 項(xiàng)目
我在homestead 內(nèi)要啟動(dòng)node寫(xiě)的項(xiàng)目,我使用的是pm2 去運(yùn)行和管理node 項(xiàng)目。使用pm2 的好處是方便調(diào)試和部署項(xiàng)目。不過(guò)homestead 里面并沒(méi)有內(nèi)置 pm2 功能,我只能自己安裝.
進(jìn)入homestead 虛擬機(jī)(用 vagrant ssh 或者 使用shell工具 我推薦使用 finalshell 是一個(gè)很強(qiáng)大的免費(fèi)工具)
安裝pm2
npm install pm2@latest -g
這個(gè)時(shí)候會(huì)有個(gè)報(bào)錯(cuò)
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/pm2 npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/pm2/node_modules npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules npm ERR! path /usr/local/lib/node_modules/pm2 npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error: EACCES: permission denied, access "/usr/local/lib/node_modules/pm2" npm ERR! { [Error: EACCES: permission denied, access "/usr/local/lib/node_modules/pm2"] npm ERR! stack: npm ERR! "Error: EACCES: permission denied, access "/usr/local/lib/node_modules/pm2"", npm ERR! errno: -13, npm ERR! code: "EACCES", npm ERR! syscall: "access", npm ERR! path: "/usr/local/lib/node_modules/pm2" } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator (though this is not recommended). npm ERR! A complete log of this run can be found in: npm ERR! /home/vagrant/.npm/_logs/2018-08-30T01_48_01_688Z-debug.log
因?yàn)閔omestead 默認(rèn)登陸的是 vagrant 用戶 。所以運(yùn)行npm install pm2@latest -g 會(huì)報(bào)沒(méi)有權(quán)限的錯(cuò)誤。
要切換到 root 用戶 或者 使用
sudo npm install pm2@latest
安裝。
我采用的是切換root 用戶,但是homestead沒(méi)有給root設(shè)置密碼,所以我們要先設(shè)置下root 用戶的密碼
sudo passwd root
然后用新設(shè)置的密碼登陸 root 用戶,安裝PM2.
安裝完成后, 初始化pm2
pm2 init
會(huì)生成配置文件 ecosystem.config.js ,設(shè)置好項(xiàng)目配置文件.
啟動(dòng)項(xiàng)目
pm2 start ecosystem.config.js
到這時(shí)候就可以訪問(wèn)node項(xiàng)目了。
不過(guò)有問(wèn)題每次啟動(dòng)homestead的時(shí)候都要到虛擬機(jī)里面啟動(dòng)pm2 還是很麻煩還好 homestead 有相關(guān)的解決方案,在 homestead 目錄下有個(gè) after.sh 的 shell 腳本就是用來(lái)啟動(dòng) homestead 后執(zhí)行相關(guān) shell 操作的。
我在里面加內(nèi)容
#!/usr/bin/env bash # If you would like to do some extra provisioning you may # add any commands you wish to this file and they will # be run after the Homestead machine is provisioned. # 切換到root 用戶 su root -c "root" # 啟動(dòng)微課堂后臺(tái)前端項(xiàng)目 npm install pm2@latest -g # 啟動(dòng)微課堂后臺(tái)前端項(xiàng)目 pm2 start ~/onlineducation.config.js
重啟 homestead 會(huì)報(bào)錯(cuò)
homestead: su: must be run from a terminal homestead: npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/pm2 homestead: npm WARN homestead: checkPermissions Missing write access to /usr/local/lib/node_modules/pm2/node_modules homestead: npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules homestead: npm ERR! path /usr/local/lib/node_modules/pm2 homestead: npm ERR! code EACCES homestead: npm ERR! errno homestead: -13 homestead: npm homestead: ERR! homestead: syscall homestead: access homestead: npm ERR! Error: EACCES: permission denied, access "/usr/local/lib/node_modules/pm2" homestead: npm ERR! homestead: { [Error: EACCES: permission denied, access "/usr/local/lib/node_modules/pm2"] homestead: npm ERR! homestead: stack: homestead: npm homestead: ERR! "Error: EACCES: permission denied, access "/usr/local/lib/node_modules/pm2"", homestead: npm homestead: ERR! homestead: errno: -13, homestead: npm ERR! homestead: code: "EACCES", homestead: npm ERR! syscall: "access", homestead: npm ERR! path: "/usr/local/lib/node_modules/pm2" } homestead: npm homestead: ERR! homestead: homestead: npm ERR! The operation was rejected by your operating system. homestead: npm ERR! It is likely you do not have the permissions to access this file as the current user homestead: npm ERR! homestead: npm ERR! homestead: If you believe this might be a permissions issue, please double-check the homestead: npm ERR! permissions of the file and its containing directories, or try running homestead: npm homestead: ERR! homestead: the command again as root/Administrator (though this is not recommended). homestead: npm homestead: ERR! A complete log of this run can be found in: homestead: npm ERR! /home/vagrant/.npm/_logs/2018-08-30T01_35_38_735Z-debug.log homestead: [PM2] Spawning PM2 daemon with pm2_home=/home/vagrant/.pm2
su 命令只能在終端運(yùn)行,看來(lái)只能用其他方法切換用戶了。
修改 after.sh 腳本 使用 expect改成可遠(yuǎn)程執(zhí)行的腳本
#!/usr/bin/env bash # If you would like to do some extra provisioning you may # add any commands you wish to this file and they will # be run after the Homestead machine is provisioned. # 安裝 expect sudo snap install expect # 安裝 pm2 sudo npm install pm2@latest -g # 切換到root 用戶 expect -c " spawn su - root expect ":" send "root " expect ":" send "cd /home/vagrant " expect ":" send "pm2 start onlineducation.config.js " expect ":" interact "
如果 expect 不能安裝,可以進(jìn)入虛擬機(jī)先安裝好,再重啟 homestead 就可以了。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/40100.html
摘要:如何在環(huán)境下部署配置一鍵啟動(dòng)的項(xiàng)目我在內(nèi)要啟動(dòng)寫(xiě)的項(xiàng)目,我使用的是去運(yùn)行和管理項(xiàng)目。所以運(yùn)行會(huì)報(bào)沒(méi)有權(quán)限的錯(cuò)誤。不過(guò)有問(wèn)題每次啟動(dòng)的時(shí)候都要到虛擬機(jī)里面啟動(dòng)還是很麻煩還好有相關(guān)的解決方案,在目錄下有個(gè)的腳本就是用來(lái)啟動(dòng)后執(zhí)行相關(guān)操作的。 如何在 windows10 環(huán)境下部署配置一鍵啟動(dòng)的 Homestead + Laravel +vue + PM2 項(xiàng)目 我在homestead 內(nèi)要...
摘要:阿里云服務(wù)器平臺(tái)在云端提供統(tǒng)一硬件平臺(tái)與中間件,可大大降低加速器的開(kāi)發(fā)與部署成本。我們相信,通過(guò)即開(kāi)即用的硬件資源統(tǒng)一的軟硬件邏輯開(kāi)發(fā)接口和市場(chǎng),阿里云能夠真正兌現(xiàn)計(jì)算資源平民化的承諾。 阿里云ECS的異構(gòu)計(jì)算團(tuán)隊(duì)和高性能計(jì)算團(tuán)隊(duì)一直致力于將計(jì)算資源平民化;高性能計(jì)算團(tuán)隊(duì)在做的E-HPC就是要讓所有云上用戶都能夠瞬間擁有一個(gè)小型的超算集群,使得超算不再僅僅是一些超算中心和高校的特權(quán);而...
摘要:一基礎(chǔ)學(xué)習(xí)模式下圖不僅概括了模式,還描述了在中是如何和以及進(jìn)行交互的。關(guān)于這一點(diǎn)我們將在后續(xù)反應(yīng)系統(tǒng)中討論。父組件通過(guò)向下傳遞數(shù)據(jù)給子組件,子組件通過(guò)給父組件發(fā)送消息。這個(gè)對(duì)象必須是普通對(duì)象原生對(duì)象,及原型屬性會(huì)被忽略。 Vue.js 是用于構(gòu)建交互式的 Web 界面的庫(kù)。Vue.js 提供了 MVVM 數(shù)據(jù)綁定和一個(gè)可組合的組件系統(tǒng),具有簡(jiǎn)單、靈活的 API。 其實(shí)和Jquery一樣...
閱讀 3845·2021-11-24 09:39
閱讀 3766·2021-11-22 12:07
閱讀 1116·2021-11-04 16:10
閱讀 809·2021-09-07 09:59
閱讀 1908·2019-08-30 15:55
閱讀 947·2019-08-30 15:54
閱讀 734·2019-08-29 14:06
閱讀 2484·2019-08-27 10:54