阅读955 返回首页    go 阿里云 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 实例操作__控制台使用_操作指南_高性能计算-阿里云