1. 程式人生 > >Nginx配置hbaseweb轉發

Nginx配置hbaseweb轉發

目標

為了公司叢集的安全考慮,hadoop和hbase的web訪問只能供有限的人訪問 而要實現內網機器給外網訪問,要解決的問題是:  1.hadoop、hbase頁面上的url替換成外網能訪問的url  2.通過有限的埠、外網ip對外提供整叢集訪問  下面就通過nginx反向代理的方式實現

步驟

整個實現步驟為:

### 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.8.0.tar.gz  

tar -zxf nginx-1.8.0.tar.gz 
編譯安裝
cd nginx-1.8.0
4../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=/data/ngx_http_substitutions_filter_module/  
#######  add-module後面是 ngx_http_substitutions_filter_module的路徑

報錯:the HTTP rewrite module requires the PCRE library.

yum -y install pcre-devel

5. make  
6. make install 
7. 配置cd /usr/local/nginx/conf目錄下的nginx.conf
server {
        listen       80;

        location / {
                proxy_pass http://node2:16010/;
                subs_filter_types text/css text/xml;
                subs_filter node2:16030 node2/hd11;
                subs_filter node3:16030 node2/hd22;
            #root   html;
            #index  index.html index.htm;
        }

		#hbase 預設的連結是加rs-status的,避免需要手動去掉,新增這個
        location /hd11/rs-status {
            proxy_pass http://node2:16030/rs-status;
        }
		#storeFile.jsp介面顯示不出來,新增
        location /hd11/storeFile.jsp {
            proxy_pass http://node2:16030/storeFile.jsp;
        }
		#region.jsp介面顯示不出來,新增
        location /hd11/region.jsp {
            proxy_pass http://node2:16030/region.jsp;
        }

        location /hd22/region.jsp {
            proxy_pass http://node3:16030/region.jsp;
        }
        location /hd22/storeFile.jsp {
            proxy_pass http://node3:16030/storeFile.jsp;
        }
        location /hd22/rs-status {
            proxy_pass http://node3:16030/rs-status;
        }

### 本次的叢集是node2和node3兩個節點,hbase為1.2.6
8. 配置好之後cd /usr/local/nginx/sbin/目錄下
./nginx啟動
Ps -ef | grep nginx  檢視啟動的nginx程序

root     17369     1  0 14:21 ?        00:00:00 nginx: master process ./nginx
nobody   17370 17369  0 14:21 ?        00:00:00 nginx: worker process
root     19090 16107  0 15:48 pts/0    00:00:00 grep nginx

輸入node2即可檢視hbase介面(因為nginx配置的是80埠,頁面node2開啟預設也是80埠,所以並不需要輸入埠號) 

Regionserver節點地址 

9. 接下來,配置iptables,限制原來的16010埠
iptables -A INPUT -p tcp --dport 16010 -j DROP
禁止訪問16010埠
iptables -I INPUT -s node2 -ptcp --dport 16010 -j ACCEPT 
iptables -I INPUT -s node3 -ptcp --dport 16010 -j ACCEPT 
允許hbase叢集的兩個節點訪問16010埠
service iptables save
service iptables restart
重啟結束

直接通過node2:16010訪問不成功

通過80埠依舊ok

Nginx通過80埠反向代理連線hbaseweb成功

參考文章:http://blackwing.iteye.com/blog/1949154