標籤: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伺服器中的部署