1. 程式人生 > >通過nginx實現內網hadoop叢集對外訪問web介面

通過nginx實現內網hadoop叢集對外訪問web介面

不少公司為了安全,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就行。