转载请标明出处:http://blackwing.iteye.com/blog/1949154
不少公司为了安全,hadoop、hbase集群都是不对外开放,只有一台入口机对外,那么当要查看hadoop、hbase集群机器状态等信息时,就没办法了。
而要实现内网机器给外网访问,要解决的问题是:
1.hadoop、hbase页面上的url替换成外网能访问的url
2.通过有限的端口、外网ip对外提供整集群访问
强大的nginx正好能解决这个问题。而nginx要替换返回的页面内容,虽然它自己有模块可以实现,但据了解只能替换一次,而网上比较常用的是第三方的替换模块nginx_substitutions_filter,其主页:
整个实现步骤为:
1. 下载nginx_substitutions_filter并解压:
根据官方的建议:
2. 下载nginx稳定版并解压:
3. 编译安装
根据自己需要选择要适应的模块,并且指定substitutions4nginx模块的路径
4. 配置nginx.conf
重启ng服务让配置生效。
这样就可以通过统一ng入口访问内网集群了,后面如果有需要添加的修改nginx.conf就行。
不少公司为了安全,hadoop、hbase集群都是不对外开放,只有一台入口机对外,那么当要查看hadoop、hbase集群机器状态等信息时,就没办法了。
而要实现内网机器给外网访问,要解决的问题是:
1.hadoop、hbase页面上的url替换成外网能访问的url
2.通过有限的端口、外网ip对外提供整集群访问
强大的nginx正好能解决这个问题。而nginx要替换返回的页面内容,虽然它自己有模块可以实现,但据了解只能替换一次,而网上比较常用的是第三方的替换模块nginx_substitutions_filter,其主页:
- http://code.google.com/p/substitutions4nginx/
整个实现步骤为:
1. 下载nginx_substitutions_filter并解压:
根据官方的建议:
- git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
2. 下载nginx稳定版并解压:
- wget http://nginx.org/download/nginx-1.4.2.tar.gz
3. 编译安装
根据自己需要选择要适应的模块,并且指定substitutions4nginx模块的路径
- ./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx.pid --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-debug --add-module=/home/hadoop/nginx/third-party-md/ngx_http_substitutions_filter_module/
- make
- make install
4. 配置nginx.conf
- #替换hbase
- server {
- listen 8000;
- location / {
- proxy_pass http://master;
- subs_filter_types text/html text/css text/xml;
- subs_filter hd1:60030 192.168.1.25:8000/hd11;
- subs_filter hd2:60030 192.168.1.25:8000/hd22;
- }
- location /hd11/ {
- proxy_pass http://192.168.1.25:60030/rs-status;
- }
- location /hd22/ {
- proxy_pass http://192.168.1.30:60030/rs-status;
- }
- }
- #替换hadoop jt
- server {
- listen 8001;
- location / {
- proxy_pass http://master2;
- subs_filter_types text/html text/css text/xml;
- subs_filter hd1:50060 192.168.1.25:8001/hd11;
- subs_filter hd2:50060 192.168.1.25:8001/hd22;
- }
- location /hd11/ {
- proxy_pass http://192.168.1.25:50060/tasktracker.jsp;
- }
- location /hd22/ {
- proxy_pass http://192.168.1.30:50060/tasktracker.jsp;
- }
- }
- #替换hadoop nn
- server {
- listen 8002;
- location / {
- proxy_pass http://master3;
- subs_filter_types text/html text/css text/xml;
- subs_filter hd1:50075 192.168.1.25:8002/hd11;
- subs_filter hd2:50075 192.168.1.25:8002/hd22;
- }
- location /hd11/ {
- proxy_pass http://192.168.1.25:50075/;
- }
- location /hd22/ {
- proxy_pass http://192.168.1.30:50075/;
- }
- }
- upstream master {
- server 192.168.1.30:60010;
- }
- upstream master2 {
- server 192.168.1.25:50030;
- }
- upstream master3 {
- server 192.168.1.25:50070;
- }
重启ng服务让配置生效。
这样就可以通过统一ng入口访问内网集群了,后面如果有需要添加的修改nginx.conf就行。