FastDFS6.0.6搭建集群

前面一篇文章在搭建FastDFS集群的时候因为采用的是5.11版本,在ECS上部署一直无法实现文件的同步,还会一直在选举:INFO - file: tracker_relationship.c, line: 389, selecting leader…。
看到官网更新了6.0.6版本的双ip特性可以解决这个外网和跨云的问题,所以马上更换到了最新版本,相匹配的软件也需要更新不同版本。
创建目录的步骤就不记录了,和前面一篇FastDFS一样的路径,所以没有重新建路径。里面ip为随意修改的,注意更改。因为外网环境不安全,所以需要做一些安全方面的工作,比如防盗链,以及端口限制访问,不要全部暴露在外网环境中,可通过程序来中转访问。

Fastdfs6.0.6最新版搭建:
https://github.com/happyfish100/fastdfs-nginx-module/releases
https://github.com/happyfish100/libfastcommon/releases
https://github.com/happyfish100/fastdfs/releases
http://nginx.org/en/download.html
解压文件

tar -zxvf fastdfs-6.06.tar.gz
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
tar -zxvf libfastcommon-1.0.43.tar.gz
tar -zxvf nginx-1.17.7.tar.gz

cd libfastcommon-1.0.43
# 编译安装
./make.sh && ./make.sh install 

检查

ls /usr/lib64|grep libfastcommon
ls /usr/lib|grep libfastcommon

出现libfastcommon.so即成功

编译安装 fastdfs
进入fastdfs-6.0.6目录下

cd  fastdfs-6.06

./make.sh && ./make.sh install

检查

ls /usr/bin|grep fdfs
cd /etc/fdfs/

cp storage.conf.sample storage.conf

cp client.conf.sample client.conf

cp tracker.conf.sample tracker.conf

配置 tracker

vim /etc/fdfs/tracker.conf
# 需要修改的内容如下
 
# 注意服务器是 NAT 方式所以此处绑定的是内网 IP 可以在阿里云后台看到
# 可以使用命令查看 ifconfig -a 没有公网的IP
bind_addr = 172.xxx.xxx.xxx
 
# tracker 服务器端口(默认22122,一般不修改)
port=22122
 
# 存储日志和数据的根目录 
base_path=/home/dfs 
 
# use_storage_id 设置为 true 后需要在 storage_ids.conf 设置双 IP 
# 原注释如下:
# if use storage server ID instead of IP address
# if you want to use dual IPs for storage server, you MUST set
# this parameter to true, and configure the dual IPs in the file
# configured by following item "storage_ids_filename", such as storage_ids.conf
# default value is false
# since V4.00
use_storage_id = true

配置 storage_ids.conf

# <id>  <group_name>  <ip_or_hostname[:port]>
#
# id is a natural number (1, 2, 3 etc.),
# 6 bits of the id length is enough, such as 100001
#
# storage ip or hostname can be dual IPs seperated by comma,
# one is an inner (intranet) IP and another is an outer (extranet) IP,
# or two different types of inner (intranet) IPs
# for example: 192.168.2.100,122.244.141.46
# another eg.: 192.168.1.10,172.17.4.21
#
# the port is optional. if you run more than one storaged instances
# in a server, you must specified the port to distinguish different instances.
# 一个内网 IP 一个公网 IP
100001   group1  172.XXX.XXX.XXX,123.XXX.XXX.XXX
100002   group1  172.XXX.XXX.XXX,123.XXX.XXX.XXX

配置 storage

vim /etc/fdfs/storage.conf
# 需要修改的内容如下
 
# storage服务端口(默认23000,一般不修改)
port=23000
 
# 数据和日志文件存储根目录  
base_path=/home/dfs
 
# 第一个存储目录  
store_path0=/home/dfs  
 
# 重点是这个,一定注意格式     内网,外网:端口号
# 重点是这个,一定注意格式     内网,外网:端口号
# 重点是这个,一定注意格式     内网,外网:端口号
# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
#   the HOST can be hostname or ip address,
#   and the HOST can be dual IPs or hostnames seperated by comma,
#   the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
#   or two different types of inner (intranet) IPs.
#   for example: 192.168.2.100,122.244.141.46:22122
#   another eg.: 192.168.1.10,172.17.4.21:22122
tracker_server = 192.168.2.100,122.244.111.111:22122
tracker_server = 192.158.2.100,123.244.222.222:22122
 
# http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
http.server_port=8888

fastdfs-nginx-module模块解压出来供nginx编译即可:需要修改文件

cd fastdfs-nginx-module-1.20/src/

编辑fastdfs-nginx-module-1.22/src/目录下的config文件(没前缀,没后缀,就叫config),主要修改以下两处地方,否则会有报错,而且报错是不可预料的,不要问为什么,反正就是干。

ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

拷贝fastdfs-nginx-module模块的配置文件mod_fastdfs.conf到/etc/fdfs目录中并编辑

cp /usr/local/bak/nginx/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
cd /etc/fdfs/

修改内容如下,,此处的store_path0应该与storage.conf中的store_path0一致,这样nginx才能够找到资源的正确路径:

base_path=/data/fastdfs/nginx
store_path0=/data/fastdfs/storage
tracker_server=47.103.111.111:22122 	# 公网 IP
storage_server_port=23000(默认配置为23000)
url_have_group_name = true
group_name=group1(默认配置为group1)

进入到nginx解压后的文件中,

cd nginx-1.18.0

./configure --prefix=/usr/local/nginx18   --conf-path=/usr/local/nginx18/conf/nginx.conf --sbin-path=/usr/local/nginx18/sbin --add-module=/usr/local/bak/nginx/fastdfs-nginx-module-1.22/src
进入到nginx解压后的文件中:
make && make install

配置 nginx

vim /etc/fdfs/mod_fastdfs.conf

#需要修改的内容如下

tracker_server=123.XXX.XXX.XXX:22122  # 公网 IP
url_have_group_name=true
store_path0=/home/dfs

#配置nginx.config

vim /usr/local/nginx/conf/nginx.conf

#添加如下配置

server {
    listen       8888;    #该端口为storage.conf中的http.server_port相同
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
    }
}

进入fastdfd源码conf目录

cd /root/download/fastdfs-6.06/conf/

将http.conf,mime.types两个文件拷贝到/etc/fdfs/目录下

cp http.conf mime.types /etc/fdfs/

再启动nginx
使用client上传文件,在nginx里可以访问到,即成功。

添加一段nginx配置集群的信息

#group1的服务设置
    upstream fdfs_group1 {
         server 111.111.111.37:8888 weight=1 max_fails=2 fail_timeout=30s;
         server 222.222.22.78:8888 weight=1 max_fails=2 fail_timeout=30s;
    }
    #group2的服务设置
    upstream fdfs_group2 {
         server 111.111.111.37:8888 weight=1 max_fails=2 fail_timeout=30s;
         server 222.222.22.78:8888 weight=1 max_fails=2 fail_timeout=30s;
    }

client_max_body_size 600m;


#group1的负载均衡配置
        location /group1/M00 {
            proxy_next_upstream http_502 http_504 error timeout invalid_header;
            #对应group1的服务设置
            proxy_pass http://fdfs_group1;
            expires 30d;
        }

        location /group2/M00 {
            proxy_next_upstream http_502 http_504 error timeout invalid_header;
            #对应group2的服务设置
            proxy_pass http://fdfs_group2;
            expires 30d;
         }
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值