nginx反代mogilefs实现

一、网络拓扑

二、说明

1、规划说明

实验共有5台主机,nginx做为前端反向代理接收用户请求;mariadb作为存储mogilefs元数据的数据库;剩下的三台主机分别安装tracker+mogstore。

2、nginx反代流程

为了能够基于URL进行(而非fid),nginx需要安装一个第三方的mogilefs模块(nginx-mogilefs就是利用mogilefs的API开发的一个应用程序)来自动转换fid到URL的映射;当用户请求来的时候,nginx通过location的判定明确知道这是一个存储在后端mogilefs应用的话,将会启用反向代理机制,nginx把自己扮演为mogilefs的客户端,此时把URL当作键直接向后端发起文件查询请求,tracker就会返回一个地址;nginx再次扮演成客户端到对应的mogstored进程上取,当nginx拿到后就去响应前端的http请求

三、MogileFS分布式文件系统的实现

请参考博客 http://www.it165.net/admin/html/201405/3056.html

四、配置nginx服务器

1、解压nginx-mogilefs-module-master.zip模块

2、先停止nginx服务器,编译安装第三方模块

cd nginx-1.4.7
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-pcre --add-module=/root/mogilefs/nginx-mogilefs-module-master
make && make install

3、修改nginx配置文件

<pre class="html" name="code">[root@shuishui ~]# vim /etc/nginx/nginx.conf
http {
 include       mime.types;
 default_type  application/octet-stream;
 #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 #'$status $body_bytes_sent "$http_referer" '
 #'"$http_user_agent" "$http_x_forwarded_for"';
 #access_log  logs/access.log  main;
 sendfile        on;
 #tcp_nopush     on;
 #keepalive_timeout  0;
 keepalive_timeout  65;
 gzip  on;
 
 upstream mogcluster {                #定义upstream,做负载均衡轮调
  server  172.16.7.200:7001;
  server  172.16.7.201:7001;
  server  172.16.7.202:7001;
 }
 server {
  listen       80;
  server_name  localhost;
  #charset koi8-r;
  #access_log  logs/host.access.log  main;
  location / {
   root   html;
   index  index.html index.htm;
  }
  location /images/ {                    #增加此location
   mogilefs_tracker mogcluster;
   mogilefs_domain images;
   mogilefs_methods GET PUT DELETE;
   mogilefs_pass {
    proxy_pass $mogilefs_path;
    proxy_hide_header Content-Type;
    proxy_buffering off;
   }
  }
  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
   root   html;
  }
 }
}

 


五、基于key做访问测试

浏览器中访问地址 http://localhost:8080/images/linux.jpg



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值