閱讀955 返回首頁    go 財經資訊


反向代理__ECS設置_操作指南_高性能計算-阿裏雲

阿裏雲GPU物理機本身不能被外網直接訪問,需要通過ECS反向代理。本文檔將指導用戶如何設置代理服務器。

1. 確定IP地址

用戶應首先確認這幾個IP地址: ECS外網IP(不便於透露,本文用XXX.XXX.XXX.XXX表示)和內網IP(實驗用10.10.10.10); GPU物理機內網IP(實驗用10.239.23.4);

2. 登錄ECS跳板機

用戶可以用PUTTY工具(Windows環境)或SSH命令(Linux環境)登錄ECS,注意應使用ECS外網IP登入。

ssh -l login_name XXX.XXX.XXX.XXX(ECS外網IP)

登錄成功後,可以在ECS跳板機上用SSH命令登錄GPU物理機:

ssh -l root 10.239.23.4(GPU物理機內網IP)

3. ECS跳板機上部署代理服務器

這裏選擇Tengine,它是在NGINX的基礎上由淘寶網發起的開源Web服務器項目。用戶應注意,NGINX做前向代理服務器是不支持HTTPS連接的,所以客戶端隻能訪問HTTP服務。

3.1 安裝Tengine

重新開一個終端,登錄到ECS跳板機。 獲取Tengine源碼:

wget https://tengine.taobao.org/download/tengine-2.1.1.tar.gz

解壓:

tar zxvf tengine-2.1.1.tar.gz
cd tengine-2.1.1/

配置和編譯:

./configure
make
sudo make install

默認情況下安裝位置在 /usr/local/nginx/ 出於測試目的,我們需要在GPU物理機上也安裝Tengine,步驟與ECS上安裝基本一致,安裝路徑也在/usr/local/nginx/。

3.2 編輯ECS Tengine配置文件

登錄ECS跳板機,用root權限打開 /usr/local/nginx/conf/nginx.conf 文件,增加一個server塊,作用為監聽本機的10000端口,將所有請求轉發給GPU物理機(10.239.23.4:10000),配置內容如下:("//”後麵為注釋,真正的conf文件中應刪除)

server {
        listen       10000;        // 監聽本機的10000端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass https://10.239.23.4:10000;
                    // 10.239.23.4為本實驗物理機內網IP,請根據需要修改
                    // 這裏實現了將來自外網的請求轉發至物理機
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

保存該文件。

3.3 編輯GPU物理機Tengine配置文件和主頁

登錄GPU物理機,用root權限編輯 /usr/local/nginx/conf/nginx.conf

server {
        listen       10000;
                    // 本文實驗將默認的80改為10000,用戶可根據需要修改
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        ..........略.............
    }

為了區分GPU物理機和ECS跳板機的主頁內容,我們修改物理機的主頁( /usr/local/nginx/html/index.html)代碼如下:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to GPU tengine!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to GPU tengine!</h1>
<p>If you see this page, the tengine web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="https://tengine.taobao.org/">tengine.taobao.org</a>.</p>

<p><em>Thank you for using tengine.</em></p>
</body>
</html>

ECS上主頁保持不變即可。

3.4 啟動GPU物理機上的Tengine

登錄到GPU物理機,用root權限運行:sudo /usr/local/nginx/sbin/nginx 如果報錯,請根據報錯信息對3.2節中的nginx.conf配置文件做必要的修改。 查看NGINX進程:

# ps -ef | grep nginx
root     17205     1  0 10:58 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   17206 17205  0 10:58 ?        00:00:00 nginx: worker process
root     20108 17042  0 11:54 pts/1    00:00:00 grep --color=auto nginx

可以看到NGINX主進程的pid為17205,worker進程的pid為17206,在需要關閉web server時可以直接以root權限運行:kill master_pid

3.5 設置GPU物理機防火牆

3.5.1 開啟GPU物理機防火牆

CentOS6: service iptables start
CentOS7: systemctl start firewalld

3.5.2 添加防火牆規則

GPU物理機服務器需要使用10000端口,故添加防火牆例外:

iptables -I INPUT -p TCP --dport 10000 -j ACCEPT

4. 啟動ECS反向代理服務

回到ECS跳板機終端,啟動代理服務。 在啟動ECS跳板機上的Tengine之前,我們需要確定ECS跳板機能訪問物理機上的web server。在ECS跳板機上運行: curl 物理機內網IP:端口號 這裏物理機內網IP為10.239.23.4,端口號在3.2節配置為10000,因此命令如下:

# curl 10.239.23.4:10000
<!DOCTYPE html>
<html>
<head>
<title>Welcome to GPU tengine!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to GPU tengine!</h1>
<p>If you see this page, the tengine web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="https://tengine.taobao.org/">tengine.taobao.org</a>.</p>

<p><em>Thank you for using tengine.</em></p>
</body>
</html>

根據返回內容,對照3.3節的主頁修改情況可以確認返回內容來自GPU物理機。 確認ECS跳板機可以訪問HPC物理機上的web server之後,開啟ECS跳板機上的Tengine:(root權限執行)/usr/local/nginx/sbin/nginx 如果啟動時報錯,請根據報錯信息修改。 查看ECS跳板機上的Tengine進程:

# ps -ef | grep nginx
root     16487     1  0 11:33 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   16488 16487  0 11:33 ?        00:00:12 nginx: worker process
root     16565 16419  0 12:06 pts/8    00:00:00 grep nginx

可以看到相應主進程和worker進程的pid。注意不要與物理機上的pid混淆。

5. 測試

5.1 ECS上本地回環測試

可以在ECS跳板機上直接用curl進行本地回環測試:

# curl https://localhost:10000
<!DOCTYPE html>
<html>
<head>
<title>Welcome to GPU tengine!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to GPU tengine!</h1>
<p>If you see this page, the tengine web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="https://tengine.taobao.org/">tengine.taobao.org</a>.</p>

<p><em>Thank you for using tengine.</em></p>
</body>
</html>

對比3.3節的主頁內容,可見返回的確實是GPU物理機上web server主頁。

5.2 遠程web頁麵測試

在瀏覽器的地址欄輸入:https://XXX.XXX.XXX.XXX:10000/ (這裏XXX.XXX.XXX.XXX是ECS跳板機的公網IP),顯示結果如下圖所示:

ECS_proxy_1.png

可見,實現了遠程訪問HPC物理機上的web server,也驗證了通過ECS進行反向代理的有效性。

最後更新:2016-11-23 17:16:02

  上一篇:go 正向代理__ECS設置_操作指南_高性能計算-阿裏雲
  下一篇:go 實例操作__控製台使用_操作指南_高性能計算-阿裏雲