• 基于【 centos7】四 || FastDFS集群+Nginx负载均衡


    1. 架构设计

    1.1 架构图

    FastDFS是用c语言编写的一款开源的分布式文件系统。FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

     

    1.2 服务器配置

    192.168.22.173  tracker-group1

    192.168.22.174  tracker-group2

    192.168.22.175  storage-group1-1

    192.168.22.176  storage-group1-2

    192.168.22.177  storage-group2-1

    192.168.22.178  storage-group2-2

    2. FastDFS安装和配置

    2.1. 安装libfastcommon

      上述所有服务器均进行安装。

      参照《fastDFS分布式文件系统安装教程》

    2.2. 安装FastDFS

    上述所有服务器均进行安装。

      参照《fastDFS分布式文件系统安装教程》

    2.3. 配置跟踪器

    2.3.1. 配置(192.168.22.173  tracker-group1tracker.conf

    disabled=false #启用配置文件

    base_path=/home/fastdfs/tracker #设置tracker的数据文件和日记目录(预先创建)

    store_lookup=0 #0:轮询,1:指定组,2:负载均衡(测试效果,改为0)

    port=22122 #设置tracker的端口号,一般使用默认的

    2.3.2. 配置(192.168.22.174  tracker-group2tracker.conf

    disabled=false #启用配置文件

    base_path=/home/fastdfs/tracker #设置tracker的数据文件和日记目录(预先创建)

    store_lookup=0 #0:轮询,1:指定组,2:负载均衡(测试效果,改为0)

    port=22122 #设置tracker的端口号,一般使用默认的

    2.4. 配置存储器

    2.4.1. 配置(192.168.22.175  storage-group1-1storage.conf

    disabled=false #启用配置文件

    base_path=/home/fastdfs/storage#设置storage的数据文件和日记目录(预先创建):

    port=23000 #设置端口号,默认值23000,同一组的的storage端口号必须相同

    group_name=group1 #组名,第一组group1,第二组group2

    store_path0=/home/fastdfs/storage #存储路径

    store_path_count=1 #存储路径个数,需要和store_path个数匹配

    tracker_server=192.168.22.173:22122 #tracker服务器的ip地址和端口号

    tracker_server=192.168.22.174:22122 #多个tracker添加多条配置

    Http_server_port=8888 #设置http端口号

    2.4.2. 配置(192.168.22.176  storage-group1-2storage.conf

    disabled=false #启用配置文件

    base_path=/home/fastdfs/storage#设置storage的数据文件和日记目录(预先创建):

    port=23000 #设置端口号,默认值23000,同一组的的storage端口号必须相同

    group_name=group1 #组名,第一组group1,第二组group2

    store_path0=/home/fastdfs/storage #存储路径

    store_path_count=1 #存储路径个数,需要和store_path个数匹配

    tracker_server=192.168.22.173:22122 #tracker服务器的ip地址和端口号

    tracker_server=192.168.22.174:22122 #多个tracker添加多条配置

    Http_server_port=8888 #设置http端口号

    2.4.3. 配置(192.168.22.177  storage-group2-1storage.conf

    disabled=false #启用配置文件

    base_path=/home/fastdfs/storage#设置storage的数据文件和日记目录(预先创建):

    port=23000 #设置端口号,默认值23000,同一组的的storage端口号必须相同

    group_name=group2 #组名,第一组group1,第二组group2

    store_path0=/home/fastdfs/storage #存储路径

    store_path_count=1 #存储路径个数,需要和store_path个数匹配

    tracker_server=192.168.22.173:22122 #tracker服务器的ip地址和端口号

    tracker_server=192.168.22.174:22122 #多个tracker添加多条配置

    Http_server_port=8888 #设置http端口号

     

    2.4.4. 配置(192.168.22.178  storage-group2-2storage.conf

    disabled=false #启用配置文件

    base_path=/home/fastdfs/storage#设置storage的数据文件和日记目录(预先创建):

    port=23000 #设置端口号,默认值23000,同一组的的storage端口号必须相同

    group_name=group2 #组名,第一组group1,第二组group2

    store_path0=/home/fastdfs/storage #存储路径

    store_path_count=1 #存储路径个数,需要和store_path个数匹配

    tracker_server=192.168.22.173:22122 #tracker服务器的ip地址和端口号

    tracker_server=192.168.22.174:22122 #多个tracker添加多条配置

    Http_server_port=8888 #设置http端口号

    2.5. 测试

    2.5.1. 主从自动切换

    先启动tracker,在启动storage

    查看日志信息:

    tail -f /home/fastdfs/storage/logs/storaged.log

    自动选举一个leader(tracker节点),同一组是互通的

    关闭一个tracker,验证是否自动切换主从leader

    2.5.2. 集群信息查看

    查看命令:cd /usr/bin/ && ll | grep fdfs

    查看存储集群信息:/usr/bin/fdfs_monitor /etc/fdfs/storage.conf

    2.5.3. 上传文件

    修改tracker节点的client.conf配置信息

    base_path=/home/fastdfs/tracker #存放路径

    tracker_server=192.168.22.173:22122  #tracker服务器ip地址和端口

    tracker_server=192.168.22.174:22122  #tracker服务器ip地址和端口

    上传:/usr/bin/fdfs_upload_file  /etc/fdfs/client.conf  /usr/local/1.img

    storage服务器查看/home/fastdfs/storage/data中的数据

    75和76服务器数据一致

    75.76和77.78根据之前设置的轮询进行数据存储

    3. Nginx安装(storage)

    3.1. 安装fastdfs-nginx-module包进行整合

    上述四个存储节点都进行安装。

    参照《fastDFS分布式文件系统安装教程》

    3.2. Fastdfs与Nginx进行集成

    上述四个存储节点都进行安装。

    参照《fastDFS分布式文件系统安装教程》

    3.3. nginx-module.conf配置

    3.3.1. 配置(192.168.22.175  storage-group1-1

    connect_timeout=10 #连接超时时间

    tracker_server=192.168.22.173:22122 #跟踪ip

    tracker_server=192.168.22.174:22122 #跟踪ip

    storage_server_port=23000

    url_have_group_name=true #启用url访问

    store_path0=/home/fastdfs/storage #与之前一致

    group_name=group1 #第一组

    group_count=2 #有多少个组

    [group1]

    group_name=group1

    storage_server_port=23000

    store_path_count=1

    store_path0=/home/fastdfs/storage 

    [group2]

    group_name=group2

    storage_server_port=23000

    store_path_count=1

    store_path0=/home/fastdfs/storage 

     

    3.3.2. 配置(192.168.22.176  storage-group1-2

    connect_timeout=10 #连接超时时间

    tracker_server=192.168.22.173:22122 #跟踪ip

    tracker_server=192.168.22.174:22122 #跟踪ip

    storage_server_port=23000

    url_have_group_name=true #启用url访问

    store_path0=/home/fastdfs/storage #与之前一致

    group_name=group1 #第一组

    group_count=2 #有多少个组

    [group1]

    group_name=group1

    storage_server_port=23000

    store_path_count=1

    store_path0=/home/fastdfs/storage 

    [group2]

    group_name=group2

    storage_server_port=23000

    store_path_count=1

    store_path0=/home/fastdfs/storage

    3.3.3. 配置(192.168.22.177  storage-group2-1

    connect_timeout=10 #连接超时时间

    tracker_server=192.168.22.173:22122 #跟踪ip

    tracker_server=192.168.22.174:22122 #跟踪ip

    storage_server_port=23000

    url_have_group_name=true #启用url访问

    store_path0=/home/fastdfs/storage #与之前一致

    group_name=group2 #第二组

    group_count=2 #有多少个组

    [group1]

    group_name=group1

    storage_server_port=23000

    store_path_count=1

    store_path0=/home/fastdfs/storage 

    [group2]

    group_name=group2

    storage_server_port=23000

    store_path_count=1

    store_path0=/home/fastdfs/storage

    3.3.4. 配置(192.168.22.178  storage-group2-2

    connect_timeout=10 #连接超时时间

    tracker_server=192.168.22.173:22122 #跟踪ip

    tracker_server=192.168.22.174:22122 #跟踪ip

    storage_server_port=23000

    url_have_group_name=true #启用url访问

    store_path0=/home/fastdfs/storage #与之前一致

    group_name=group2 #第二组

    group_count=2 #有多少个组

    [group1]

    group_name=group1

    storage_server_port=23000

    store_path_count=1

    store_path0=/home/fastdfs/storage 

    [group2]

    group_name=group2

    storage_server_port=23000

    store_path_count=1

    store_path0=/home/fastdfs/storage

    3.4. 安装nginx缓存模块

    需要在所有跟踪器上安装nginx,以提供反向代理服务,目的是使用统一的一个ip地址对外提供服务。

    3.4.1. 安装nginx缓存模块

    上传并解压Nginx缓存模块,ngx_cache_purge

    安装依赖库文件

    yum install pcre

    yum install pcre-deve

    yum install zlib

    yum install zlib-devel

    安装Nginx,并加入缓存模块

    加入模块:./configure  --add-module=/usr/local/fastdfs/ngx_cache_purge

    编译:make && make install

    3.4.2. 配置nginx负载均衡和缓存(192.168.22.173  tracker-group1

    编辑nginx.conf

    # 缓存配置start

    server_names_hash_bucker_size 128;

    client_header_buffer_size 32k;

    large_client_header_buffers 4 32k;

    client_max_body_size 300m;

    proxy_redirect off;

    proxy_set_header Host $http_host;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarder_for;

    proxy_connect_timeout 90;

    proxy_send_timeout 90;

    proxy_read_timeout 90;

    proxy_buffer_size 16k;

    proxy_buffers 4 64k;

    proxy_busy_buffers_size 128k;

    proxy_temp_file_write_size 128k;

    # 缓存文件夹

    proxy_cacher_path /home/fastdfs/cache/nginx/proxy_cache levels=1:2

    keys_zone=http-cache:200m max_size=1g inactive=30d;

    proxy_temp_path /home/fastdfd/cache/nginx/proxy_cache/tmp;

    # group的服务设置

    upstream fdfs_group1{

    server 192.168.22.175:8888 weight=1 max_fails=2 fail_timeout=30s;

    server 192.168.22.176:8888 weight=1 max_fails=2 fail_timeout=30s;

    }

    upstream fdfs_group2{

    server 192.168.22.177:8888 weight=1 max_fails=2 fail_timeout=30s;

    server 192.168.22.178:8888 weight=1 max_fails=2 fail_timeout=30s;

    }

    # 缓存配置end

        server {

            listen       8000;

            server_name  localhost;

            #charset koi8-r;

            #access_log  logs/host.access.log  main;

            location /group1/M00 {

    proxy_next_upstream http_502 http_504 error timeout invalid_header;

    proxy_cache http-cache;

    proxy_cache_valid 200 304 12h;

    proxy_cache_key $uri$is_args$args;

                proxy_pass   http://fdfs_group1;

                expires 30d;

            }

            location /group2/M00 {

             proxy_next_upstream http_502 http_504 error timeout invalid_header;

             proxy_cache http-cache;

             proxy_cache_valid 200 304 12h;

             proxy_cache_key $uri$is_args$args;

            

                proxy_pass   http://fdfs_group2;

                expires 30d;

            }

    #缓存清空权限设置

    location ~purge(/.*) {

    allow 127.0.0.1;

    allow 127.0.0.1;

    deny all;

    proxy_cache_purge http-cache $1$si_args$args;

    }

    3.4.3. 配置nginx负载均衡和缓存(192.168.22.174  tracker-group2

    /fastdfs/storage文件存储目录下创建软连接,将其链接到实际存放数据的目录:

    # 缓存配置start

    server_names_hash_bucker_size 128;

    client_header_buffer_size 32k;

    large_client_header_buffers 4 32k;

    client_max_body_size 300m;

    proxy_redirect off;

    proxy_set_header Host $http_host;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarder_for;

    proxy_connect_timeout 90;

    proxy_send_timeout 90;

    proxy_read_timeout 90;

    proxy_buffer_size 16k;

    proxy_buffers 4 64k;

    proxy_busy_buffers_size 128k;

    proxy_temp_file_write_size 128k;

    # 缓存文件夹

    proxy_cacher_path /home/fastdfs/cache/nginx/proxy_cache levels=1:2

    keys_zone=http-cache:200m max_size=1g inactive=30d;

    proxy_temp_path /home/fastdfd/cache/nginx/proxy_cache/tmp;

    # group的服务设置

    upstream fdfs_group1{

    server 192.168.22.175:8888 weight=1 max_fails=2 fail_timeout=30s;

    server 192.168.22.176:8888 weight=1 max_fails=2 fail_timeout=30s;

    }

    upstream fdfs_group2{

    server 192.168.22.177:8888 weight=1 max_fails=2 fail_timeout=30s;

    server 192.168.22.178:8888 weight=1 max_fails=2 fail_timeout=30s;

    }

    # 缓存配置end

        server {

            listen       8000;

            server_name  localhost;

            #charset koi8-r;

            #access_log  logs/host.access.log  main;

            location /group1/M00 {

    proxy_next_upstream http_502 http_504 error timeout invalid_header;

    proxy_cache http-cache;

    proxy_cache_valid 200 304 12h;

    proxy_cache_key $uri$is_args$args;

                proxy_pass   http://fdfs_group1;

                expires 30d;

            }

            location /group2/M00 {

             proxy_next_upstream http_502 http_504 error timeout invalid_header;

             proxy_cache http-cache;

             proxy_cache_valid 200 304 12h;

             proxy_cache_key $uri$is_args$args;

            

                proxy_pass   http://fdfs_group2;

                expires 30d;

            }

    #缓存清空权限设置

    location ~purge(/.*) {

    allow 127.0.0.1;

    allow 127.0.0.1;

    deny all;

    proxy_cache_purge http-cache $1$si_args$args;

    }

    3.4.4. 创建缓存文件夹

    命令:mkidr -p /home/fastdfs/cache/nginx/proxy_cache

    命令:mkidr -p /home/fastdfd/cache/nginx/proxy_cache/tmp

    3.4.5. 启动nginx进行测试

    命令: /usr/local/nginx/sbin/nginx

    3.4.6. 使用keepalive虚拟ip地址(可在173174上代理)

    upstream fastdfs_tracker{

    server 192.168.22.173:8000 weight=1 max_fails=2 fail_timeout=30s;

    server 192.168.22.174: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_forwarder_for;

    proxy_set_header X-Forwarded-Proto $scheme;

    client_max_body_size 300m;

            }

  • 相关阅读:
    Qt高级编码约定
    QTextCodec::codecForLocale
    无边框窗口拖动代码
    QString QByteArray char 之间的转换
    Qt 程序发布指南
    qt demo pro
    snort vtun performance on vm
    xhEditor用法
    MVC控制器使用总结
    第七章 模态框
  • 原文地址:https://www.cnblogs.com/kevin-ying/p/11192916.html
Copyright © 2020-2023  润新知