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
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 遍历一次,得到最大和次大
- 下一篇: 从数组中获取最大的两个值
copyright © 2008-2019 亿联网络 版权所有 备案号:粤ICP备14031511号-2