nodejs應用在linux伺服器中的部署

來源:互聯網
上載者:User

標籤:zed   ati   linux伺服器   default   ejs   com   1.3   一個   visudo   

1.(可選)添加使用者:

addgroup wmui添加使用者組
useradd -d /home/wmui -s /bin/bash -m wmui建立wmui使用者
passwd wmui設定密碼,如果忘記密碼,也可用此命令重設密碼
usermod -a -G wmui wmui 添加使用者到組
visudo 設定sudo許可權
然後會跳轉到下面頁面

root ALL=(ALL:ALL) ALL下面添加wmui ALL=(ALL) NOPASSWD: ALL
ctrl+x儲存退出
接下來開啟一個新的視窗,測試是否登陸成功。

2.(可選)ssh無密碼登陸配置

首先你需要在本地安裝git並產生id_rsa.pub,開啟命令列
在本地產生公開金鑰和私密金鑰:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
在伺服器產生公開金鑰和私密金鑰:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
在伺服器視窗輸入:
echo "[your public key]" > ~/.ssh/authorized_keys將原生公開金鑰拷貝到伺服器的authorized_keys檔案

完成以上操作,測試是否生效,重啟服務:sudo service ssh restart新開啟一個視窗,輸入使用者名稱斷行符號,登陸成功

3.nodejs環境搭建

安裝常用軟體
sudo apt-get install vim openssl build-essential libssl-dev wget curl git
nvm安裝
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
開啟新的視窗
nvm install node v8.1.3  這裡也可以下載編譯好的壓縮包進行安裝
nvm use node v8.1.3
nvm alias default v8.1.3 預設版本
安裝常用node包
npm i pm2 webpack vue-cli -g

4.建立和部署hello world

以root使用者身份在根目錄下建立www目錄,www目錄下建立myNodeApp檔案夾,裡面就一個檔案,app.js,內容如下:

const http = require(‘http‘)http.createServer(function(req,res) {res.writeHead(200,{‘Content-Type‘:‘text/plain‘})res.end(‘hello world‘)}).listen(8081)console.log(‘server test‘)

(如果你是自己結合nodejs架構如express編寫的應用(含有package.json),則直接將項目代碼拷貝至www目錄下,進入項目目錄如myNodeApp,執行命令

npm install 安裝依賴。)

進入到www下myNodeApp檔案夾下
hello world測試:
pm2 start app.js
pm2 list 查看啟動的應用
pm2 show hello 查看詳細資料
pm2 logs 查看當前資訊
pm2 stop hello 停止hello
pm2 delete hello 刪除hello

表示啟動成功,輸入hello.86886.wang就可以看到hello world了

nodejs應用在linux伺服器中的部署

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.