前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >FastDFS蛋疼的集群和负载均衡(七)之Nginx高可用集群应用到FastDFS集群

FastDFS蛋疼的集群和负载均衡(七)之Nginx高可用集群应用到FastDFS集群

作者头像
用户2032165
发布2018-06-05 18:24:57
4160
发布2018-06-05 18:24:57
举报

diary_report.jpg

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

上传图片

我爱五月天


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撸一遍。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.12.28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Interesting things
  • What did you do today
  • Summary
  • What to do tomorrow
相关产品与服务
负载均衡
负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档