博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FastDFS蛋疼的集群和负载均衡(七)之Nginx高可用集群应用到FastDFS集群
阅读量:6978 次
发布时间:2019-06-27

本文共 4447 字,大约阅读时间需要 14 分钟。

###Interesting things

这将会是关于FastDFS蛋疼的集群和负载均衡系列收官之篇,不排除有总结篇!这篇就是将keepalived实现的nginx集群高可用应用到我们的FastDFS集群中。 ###What did you do today

  • 我们需要修改192.168.12.77和192.168.12.88设备上的nginx.conf,配置如下所示:
#user  nobody;worker_processes  1;error_log  logs/error.log;error_log  logs/error.log  notice;error_log  logs/error.log  info;pid        logs/nginx.pid;events {   # cmazxiaoma is handsome    worker_connections  1024;}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 fastdfs_tracker {                server  192.168.12.11:8000 weight=1 max_fails=2 fail_timeout=30s;                server  192.168.12.22:8000 weight=1 max_fails=2 fail_timeout=30s;        }    server {        listen       80;        server_name  localhost;        #charset koi8-r;        access_log  logs/host.access.log  main;        location /fastdfs {                root html;                index index.html index.htm;                proxy_pass http://fastdfs_tracker/;                proxy_set_header Host $http_host;                proxy_set_header Cookie $http_cookie;                proxy_set_header X-Real-IP $remote_addr;                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                proxy_set_header X-Forwarded-Proto $scheme;                client_max_body_size 300m;        }        location / {            root   html;            index  index.html index.htm;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {
# proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {
# root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht {
# deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server {
# listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / {
# root html; # index index.html index.htm; # } #} # HTTPS server # #server {
# listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / {
# root html; # index index.html index.htm; # } #}}复制代码
  • 我们对配置做了一些修改。
  • 一处是添加了负载均衡upstream fastdfs_tracker.把192.168.12.11和192.168.12.22两台设备作为tracker,现在我们集群了一层nginx来代理2台tracker
upstream fastdfs_tracker {                server  192.168.12.11:8000 weight=1 max_fails=2 fail_timeout=30s;                server  192.168.12.22:8000 weight=1 max_fails=2 fail_timeout=30s;        }复制代码
  • 另一处修改是添加了一个location,匹配路径中含有fastdfs。

  • 我们再上传一张图片。上传成功返回group1/M00/00/00/wKgMIVpE8IKAWxlrAADRd6mMX3g207.jpg

  • 我们试着访问http://192.168.12.111/fastdfs/group1/M00/00/00/wKgMIVpE8IKAWxlrAADRd6mMX3g207.jpg,完美!

###Summary

FastDFS负载均衡和集群终于搞定了。 1.虚拟ip 192.168.12.111提供入口 2.一层Nginx集群负载均衡(192.168.12.77、192.168.12.88) 3.Tracker+Nginx负载均衡(192.168.12.11) 4.Tracker + Nginx负债均衡(192.168.12.22) 5.Group1包含Stroage+Nginx(192.168.12.33), Storage+Nginx(192.168.12.44) 6.Group2包含Stroage+Nginx(192.168.12.55), Storage+Nginx(192.168.12.66) 一共2台tracker、4台storage、8台nginx。

###What to do tomorrow

写一篇关于FastDFS集群和负载均衡的总结。这个星期把Spring Security和二叉树两篇博客搞定,预习Zookeeper。下一个星期把Zookeeper撸一遍。

转载地址:http://wwypl.baihongyu.com/

你可能感兴趣的文章
Python 代码规范
查看>>
Python 之 pip拒绝访问
查看>>
cglib代理的使用
查看>>
Format specifies type 'id' but the argument has type 'NSError *__autoreleasing *
查看>>
[译] JWT 与 Spring Cloud 微服务
查看>>
Android NDK开发之旅31 FFmpeg音频解码
查看>>
关于Android开源库分享平台,(GitClub)微信小程序的开发体验
查看>>
Thrift RPC 系列教程(4)——源码目录结构组织
查看>>
CentOS 部署 flask项目
查看>>
Kotlin学习笔记-基础语法
查看>>
Mybatis中Oracle和Mysql的Count字段问题
查看>>
[Java实现] 图片择优(选择最清楚的图片)
查看>>
【译】使用Kotlin和RxJava测试MVP架构的完整示例 - 第1部分
查看>>
前端项目如何管理
查看>>
优秀Java程序员应该知道的20个实用开源库
查看>>
极限编程 (Extreme Programming) - 迭代计划 (Iterative Planning)
查看>>
这些资源网站为什么能获得5万知乎大佬推荐,而我错失了什么吗?
查看>>
PHP面试常考内容之Memcache和Redis(2)
查看>>
GDB 调试 Mysql 实战(二)GDB 调试打印
查看>>
Work with Alexa :Echo匹配连接到Alexa
查看>>