騰訊云:theia安裝+登錄認證

來源: 騰訊云
作者:諦聽
時間:2020-10-12
18920
本文介紹用騰訊云進行theia安裝+登錄認證的過程。

1 theia 介紹

theia 安裝后的樣子:

tktqekdrn2.png

theia界面

theia 是一套構(gòu)建基于 web 的云端工具和 IDE 的開源框架。theia 提供了一個工作框架、模塊系統(tǒng)、和 git 集成等一些可重用的特性?;?theia 的工具可以遠程部署,并通過瀏覽器或桌面應(yīng)用如 Electron 進行訪問。theia 基于 Typescript、HTML、CSS、LSP(Language Server Protocol)和 VS Code 提供的 Monaco 代碼編輯器構(gòu)建。

它是一套開源框架,而不是一個最終產(chǎn)品,開發(fā)者可以基于 theia 構(gòu)建和自定義一款屬于自己的 IDE 或工具,例如 gitpod、建模工具等。

1.1 優(yōu)點

·為終端用戶提供完整的多語言 IDE(不僅僅是智能編輯器)。

·同時支持桌面和云端的 IDE。

·和 VS Code 體驗高度一致,大大降低學(xué)習(xí)成本。

·方便擴展,開發(fā)者可定制自己的 IDE。

·由 Eclipse 基金會托管,是一個與廠商無關(guān)的項目。

1.2 不足

·第一次打開界面或刷新界面時,會加載所有插件,耗時較長,20s~1min。

·增加一個新插件需要重新編譯整個 IDE。

·默認只支持 nodejs 語言,其它語言可在擴展處安裝,或者在 theia 自帶的命令行終端中安裝。

·通過界面操作,只能打開服務(wù)器上已有的項目或新建文件夾。不能上傳項目,但是可以在 theia 上自帶的終端執(zhí)行 git 命令拉取 git 項目,也可以通過其它命令如 rsync 或 scp 命令自行將本地項目拷貝到遠程服務(wù)器。

2 theia 安裝

有如下幾種方式:

·從源代碼克隆、構(gòu)建和運行

·基于自定義 package.json 構(gòu)建包啟動

·基于預(yù)配置的 Docker Image 構(gòu)建

·在 gitpod 中啟動

本文介紹第 1 種方式,即通過源碼安裝。

為了提高安裝速速,并且避免網(wǎng)絡(luò)錯誤,可在騰訊云硅谷買一臺 CVM,操作系統(tǒng)為 ubuntu 18。

安裝 node 10 和 yarn:

wget https://nodejs.org/dist/latest-v10.x/node-v10.22.0-linux-x64.tar.gz

tar zxvf node-v10.21.0-linux-x64.tar.gz -C /usr/local

echo "export PATH=/usr/local/node-v10.21.0-linux-x64/bin:$PATH" >> /etc/profile

echo "export PATH=/usr/local/node-v10.21.0-linux-x64/bin:$PATH" >> /etc/bash.bashrc 

source /etc/profile


npm install -g yarn

theia 前置安裝:

apt-get install -y g++ gcc make

apt-get install -y pkg-config

apt-get install -y build-essential

apt-get install -y libx11-dev libxkbfile-dev

apt-get install -y git

安裝 theia

git clone https://github.com/eclipse-theia/theia

cd theia

yarn

cd examples/browser

yarn run start --hostname 0.0.0.0 --port 3000

如果安全組開放了 3000 端口,此時便可以通過 http://IP:3000 訪問了。

3 登錄認證

theia 沒有登錄認證功能,任何人都可以訪問,不安全,可借助 ngx_http_auth_digest 模塊進行登錄認證。

下載 ngx_http_auth_digest:

wget https://github.com/atomx/nginx-http-auth-digest/archive/v1.0.0.tar.gz

tar zxvf v1.0.0.tar.gz

編譯安裝 nginx 時,加上參數(shù):

--add-module=nginx-http-auth-digest的路徑

生成登錄密碼:

apt-get install -y apache2-utils

htdigest -c /usr/local/passwd.digest theia admin

其中

·/usr/local/passwd.digest 為密碼文件路徑

·theia 為 realm,必須與后面要提到的 nginx 配置文件保持一致。

·admin 為登錄用戶名

在 nginx 配置文件中添加 server 段:

server {

listen 80 default_server;


    auth_digest_user_file /usr/local/passwd.digest;

    auth_digest_shm_size  8m;   # the storage space allocated for tracking active sessions

    

    location / {

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection "upgrade";


        auth_digest 'theia';

        auth_digest_timeout 60s;    # allow users to wait 1 minute between receiving the

                                    # challenge and hitting send in the browser dialog box

        auth_digest_expires 600s;   # after a successful challenge/response, let the client

                                    # continue to use the same nonce for additional requests

                                    # for 600 seconds before generating a new challenge

        auth_digest_replays 60;     # also generate a new challenge if the client uses the

                                    # same nonce more than 60 times before the expire time limit


        proxy_pass http://127.0.0.1:3000;

    }

}

其中,

·auth_digest_user_file 必須與設(shè)置密碼的 htdigest 命令中的密碼文件參數(shù)保持一致。

·auth_digest 必須與設(shè)置密碼的 htdigest 命令的 realm 參數(shù)保持一致。

·proxy_set_header Upgrade $http_upgrade; 

 proxy_set_header Connection "upgrade";

    這兩行必須有,否則不能正確代理 websocket。

這個配置相當于每 (auth_digest_timeout+auth_digest_expires)=660s 允許 auth_digest_shm_size/((48 + ceil(auth_digest_replays/8))bytes)=(8*1024*1024)/(48+8)=149.8k 次請求,即每 660s 允許約 149.8k 次請求。登錄認證 10min 后過期。

最后啟動 nginx,會彈出登錄認證框,輸入用戶名和密碼后即可登錄,跳轉(zhuǎn)到 theia 界面。

為了更加安全,需要先停掉 theia,將啟動方式

yarn run start --hostname 0.0.0.0 --port 3000

改為:

yarn start

默認監(jiān)聽端口為 3000。

參考

https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#quick-start

https://www.nginx.com/resources/wiki/modules/auth_digest

https://www.yangyang.cloud/blog/2015/07/17/session-with-express-and-nginx

立即登錄,閱讀全文
版權(quán)說明:
本文內(nèi)容來自于騰訊云,本站不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。文章內(nèi)容系作者個人觀點,不代表快出海對觀點贊同或支持。如有侵權(quán),請聯(lián)系管理員(zzx@kchuhai.com)刪除!
優(yōu)質(zhì)服務(wù)商推薦
更多