FastDFS高可用集群架构配置搭建
一、基本模块及高可用架构
FastDFS 是余庆老师开发的一个开源的高性能分布式文件系统(DFS)。 它的主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载平衡。
FastDFS 系统有三个角色:跟踪服务器(Tracker Server)、存储服务器(Storage Server)和客户端(Client)。
- Tracker Server: 跟踪服务器,主要做调度工作,起到均衡的作用;负责管理所有的storage server和group,每个storage在启动后会连接 Tracker,告知自己所属 group 等信息,并保持周期性心跳。多个Tracker之间是对等关系,不存在单点故障。
- Storage Server: 存储服务器,主要提供容量和备份服务;以 group 为单位,每个 group 内可以有多台 storage server,组内的storage server上的数据互为备份。
- Client:客户端,上传下载数据的服务器
模块之间的主要关系如下:

下图是实现统一的对外下载访问入口的高可用架构,其中所有的Nginx只做下载用途,上传通过tracker进行上传。

二、环境准备工作
系统软件说明:
| 名称 | 说明 |
| CentOS | 7.x(安装系统) |
| libfastcommon | FastDFS分离出的一些公用函数包 |
| FastDFS | FastDFS本体 |
| fastdfs-nginx-module | FastDFS和nginx的关联模块,解决组内同步延迟问题 |
| nginx | nginx 1.12.2(CentOS 7 下YUM可以安装的最新版本) |
整个搭建所需环境资源及用途如下表:
| 名称 | IP地址 | 应用 |
| tracker01 | 192.168.0.1 | FastDFS,libfastcommon |
| tracker02 | 192.168.0.2 | FastDFS,libfastcommon |
| storage01 | 192.168.0.10 | FastDFS,libfastcommon,nginx,fastdfs-nginx-module |
| storage02 | 192.168.0.11 | FastDFS,libfastcommon,nginx,fastdfs-nginx-module |
| nginx01 | 192.168.0.100 | nginx,keepalived |
| nginx02 | 192.168.0.101 | nginx,keepalived |
| VIP | 192.168.0.200 | - |
三、安装过程
1、编译环境准备
| 说明 | 位置 |
| 所有安装包 | /opt/fastdfs |
| 数据存储位置 | /data/fastdfs |
$ tar -zxvf libfastcommon-1.0..tar.gz
#安装编译环境
$ yum groups install Development Tools -y
$ yum install perl -y
$ mkdir -p /opt/fastdfs /data/fastdfs
$ cd /opt/fastdfs #为下一步下载源码做准备
2、安装libfastcommon
#下载文件
$ wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz
$ tar -zxvf libfastcommon-1.0..tar.gz
$ cd libfastcommon-1.0./
$ ./make.sh
$ ./make.sh install
3、安装FastDFS
$ wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
$ tar -zxvf fastdfs-5.11.tar.gz
$ cd fastdfs-5.11/
$ ./make.sh
$ ./make.sh install
#配置文件准备
$ cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf #tracker节点
$ cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf #storage节点
$ cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用
$ cp /opt/fastdfs/fastdfs-5.11/conf/http.conf /etc/fdfs/ #供nginx访问使用
$ cp /opt/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs/ #供nginx访问使用
tracker server配置:
$ vim /etc/fdfs/tracker.conf
#需要修改的内容如下
port= # tracker服务器端口(默认22122,一般不修改)
base_path=/data/fastdfs # 存储日志和数据的根目录
#编辑启动文件
$ vim /usr/lib/systemd/system/fastdfs-tracker.service
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target [Service]
Type=forking
ExecStart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
ExecStop=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
ExecRestart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart [Install]
WantedBy=multi-user.target $ systemctl daemon-reload
$ systemctl enable fastdfs-tracker.service
$ systemctl start fastdfs-tracker.service
$ netstat -tulnp #查看服务是否启动,端口是否打开
storage server配置
$ vim /etc/fdfs/storage.conf
#需要修改的内容如下
port= # storage服务端口(默认23000,一般不修改)
base_path=/data/fastdfs # 数据和日志文件存储根目录
store_path0=/data/fastdfs # 第一个存储目录
tracker_server=192.168.0.1: # tracker服务器IP和端口
tracker_server=192.168.0.2: # tracker服务器IP和端口
http.server_port= # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
#编辑启动文件
$ vim /usr/lib/systemd/system/fastdfs-storage.service [Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target [Service]
Type=forking
ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
ExecStop=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
ExecRestart=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart [Install]
WantedBy=multi-user.target $ systemctl daemon-reload
$ systemctl enable fastdfs-storage.service
$ systemctl start fastdfs-storage.service
$ netstat -tulnp #查看服务是否启动,端口是否打开
#查看集群状态
$ fdfs_monitor /etc/fdfs/storage.conf list
[-- ::] DEBUG - base_path=/data/fastdfs/storage, connect_timeout=, network_timeout=, tracker_server_count=, anti_steal_token=, anti_steal_secret_key length=, use_connection_pool=, g_connection_pool_max_idle_time=3600s, use_storage_id=, storage server id count:
server_count=, server_index=
tracker server is 192.168.0.1:
group count:
Group :
...
Client配置
$ vim /etc/fdfs/client.conf
#需要修改的内容如下
base_path=/data/fastdfs
tracker_server=192.168.0.1: # tracker服务器IP和端口
tracker_server=192.168.0.2: # tracker服务器IP和端口 #保存后测试,返回ID表示成功 如:group1/M00///xx.tar.gz
$ fdfs_upload_file /etc/fdfs/client.conf testfile
4、安装nginx和fastdfs-nginx-module
下载nginx module
$ wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
$ cp /opt/fastdfs/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs
安装nginx
$ yum install nginx -y
# 查看版本及编译参数
$ nginx -v
$ nginx -V
添加nginx module
wget http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -zxvf nginx-1.12..tar.gz
$ cd nginx-1.12./
$ ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=/opt/fastdfs/fastdfs-nginx-module-1.20/src/
$ make
$ cp objs/nginx /usr/sbin/nginx
$ systemctl enable nginx
$ systemctl restart nginx
查看插件是否安装成功:
$ nginx -V
配置nginx访问
$ vim /etc/fdfs/mod_fastdfs.conf
#需要修改的内容如下
tracker_server=192.168.0.1: # tracker服务器IP和端口
tracker_server=192.168.0.2: # tracker服务器IP和端口
url_have_group_name=true
base_path=/data/fastdfs
store_path0=/data/fastdfs
#配置nginx.config
$ vim /etc/nginx/nginx.conf
#增加如下内容
server {
listen ; ## 该端口为storage.conf中的http.server_port相同
server_name localhost;
location ~/group[-]/ {
root /data/fastdfs;
ngx_fastdfs_module;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}
#测试下载,用外部浏览器访问刚才已传过的文件,引用返回的ID
http://192.168.0.10:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
#弹出下载则目前nginx已经OK
注:
在nginx的构建中会遇到不少的报错,具体如下:
- ./configure: error: the Google perftools module requires the Google perftools library. You can either do not enable the module or install the library.
解决方法如下:
$ yum install gperftools -y
- /configure: error: the HTTP rewrite module requires the PCRE library.
解决方法如下:
$ yum -y install pcre pcre-devel
- ./configure: error: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl= options.
解决方法如下:
$ yum -y install openssl openssl-devel
- ./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib= option.
解决方法如下:
$ yum install -y zlib-devel
- ./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.
解决方法如下:
$ yum -y install libxml2 libxml2-dev
$ yum -y install libxslt-devel
- ./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.
解决方法如下:
$ yum -y install gd-devel
- ./configure: error: perl module ExtUtils::Embed is required
解决方法如下:
$ yum -y install perl-devel perl-ExtUtils-Embed
- ./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library.
解决方法如下:
$ yum -y install GeoIP GeoIP-devel GeoIP-data
- 在make过程中会出现一个报错:/usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or directory
解决方法如下:
修改fastdfs-nginx-module-1.20/src/config文件,修改如下:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
然后重新./configure && make,就可以了
5、配置文件访问的负载均衡和高可用
在192.168.0.100和101上安装nginx、keepalived
yum install -y nginx keepalived
nginx的配置文件如下:
upstream fdfs_group01 {
server 192.168.0.10: weight= max_fails= fail_timeout=30s;
server 192.168.0.11: weight= max_fails= fail_timeout=30s;
}
server {
listen ;
server_name localhost;
location /group01{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group01;
expires 30d;
}
}
keepalived配置文件如下:
global_defs {
router_id LVS_DEVEL
}
vrrp_script chk_ngx {
script "/etc/keepalived/check_nginx.sh"
interval
weight -
fall
rise
}
vrrp_instance VI_1 {
interface eno16777984
state MASTER
priority
virtual_router_id
advert_int
authentication {
auth_type PASS
auth_pass
}
unicast_src_ip 192.168.0.100
unicast_peer {
192.168.0.101
}
virtual_ipaddress {
192.168.0.200
}
track_script {
chk_ngx
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
check_nginx.sh
#!/bin/bash counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "" ]; then
exit
else
exit
fi
OK,以上就是所有的安装步骤及相关配置。
文章中有什么疑问或者错误,欢迎大家提出指正。
注:借鉴文章URL如下:
注:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
FastDFS高可用集群架构配置搭建的更多相关文章
- FastDFS高可用集群架构配置搭建及使用
一,概述FastDFS 是一个开源的高性能分布式文件系统(DFS). 它的主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载平衡.FastDFS 系统有三个角色:跟踪服务器(Tracker ...
- (二)FastDFS 高可用集群架构学习---搭建
一.单group 单磁盘 的 FastDFS 集群 a.前期准备 1.系统软件说明: 名称 说明 CentOS 7.x(安装系统) libfastcommon FastDFS分离出的一些公用函数包 F ...
- (一)FastDFS 高可用集群架构学习---简介
1.什么是FastDFS FastDFS 是余庆老师用c语言编写的一筐开源的分布式文件系统,充分考虑了冗余备份,负载均衡,线性扩容等机制,并注重高可用.高性能等指标,使用FastDFS可以很容易搭建一 ...
- (三)FastDFS 高可用集群架构学习---Client 接口开发
一.Python3 与 FastDFS 交互 1.安装 py3fdfs模块 # pip3 install py3Fdfs 2.测试使用 py3Fdfs 与 Fastdfs 集群交互(上传文件) fro ...
- (四)FastDFS 高可用集群架构学习---后期运维--基础知识及常用命令
1.fastdfs 七种状态 FDFS_STORAGE_STATUS:INIT :初始化,尚未得到同步已有数据的源服务器 FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到 ...
- MongoDB 高可用集群架构简介
在大数据的时代,传统的关系型数据库要能更高的服务必须要解决高并发读写.海量数据高效存储.高可扩展性和高可用性这些难题.不过就是因为这些问题Nosql诞生了. 转载自严澜的博文——<如何搭建高效的 ...
- Java高可用集群架构与微服务架构简单分析
序 可能大部分读者都在想,为什么在这以 dubbo.spring cloud 为代表的微服务时代,我要还要整理这种已经"过时"高可用集群架构? 本人工作上大部分团队都是7-15人编 ...
- hadoop+yarn+hbase+storm+kafka+spark+zookeeper)高可用集群详细配置
配置 hadoop+yarn+hbase+storm+kafka+spark+zookeeper 高可用集群,同时安装相关组建:JDK,MySQL,Hive,Flume 文章目录 环境介绍 节点介绍 ...
- activemq+Zookeper高可用集群方案配置
在高并发.对稳定性要求极高的系统中,高可用的是必不可少的,当然ActiveMQ也有自己的集群方案.从ActiveMQ 5.9开始,ActiveMQ的集群实现方式取消了传统的Master-Slave方式 ...
随机推荐
- 2018.06.27The Windy's(费用流)
The Windy's Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 6003 Accepted: 2484 Descripti ...
- Vbs脚本简单使用
之前在做项目时用到了一点vbs脚本,记录下. C++程序调用vbs脚本 System(vbs路径 参数); //空格隔开 Vbs脚本 '''''Vbs脚本解析参数 Set objArgs = Wscr ...
- vue的子传父
子组件传值给父组件,需要触发一个事件. 在这个事件里,使用this.$emit("父组件使用的名称","子组件的数据") 在父组件中引用的子组件,在子组件的标签 ...
- 创建Java程序并设置快捷提示
1.new Java project 创建项目 2.new package 创建包,cn.com.test 3.创建Java文件 4.Java智能提示的设置 window/preference 在Au ...
- hibernate添加数据报错:Could not execute JDBC batch update
报错如下图所示: 报错原因:在配置文件或注解里设置了字段关联,但数据却没有关联. 解决方法:我的错误是向一个多对多的关联表里插入数据,由于表中一个字段的数据是从另一张表里get到的,通过调试发现,从以 ...
- Andrew机器学习第一课
批梯度下降算法: 训练样本为一个时:更新Θi 让代价函数最小,利用沿梯度下降方向函数会变得越来越小.这个函数是代价函数J关于(Θi )的.这里并没有在讨论x,y. 关于为什么式子(图是复制的 ...
- 笔记:CSS hack的学习与了解…
更新时间:2015.05.12 兼容范围: IE:6.0+,FireFox:2.0+,Opera 10.0+,Sarari 3.0+,Chrome 参考资料: 各游览器常用兼容标记一览表: 标记 I ...
- 1105 Spiral Matrix
This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasi ...
- 模块import,from ..import...
首次导入模块发生3件事 1.创建一个模块的名称空间 2.执行文件spam.py,将执行过程中产生的名字都放到模块的名称空间中 3.在当前执行文件中直接拿到一个名字,该名字就是执行模块中相对应的名字 f ...
- Java Map释放内存置null以及调用clear()的区别
今天自己在总结map的时候,想到了在释放Map对象空间的时候就有使用过将Map对象置null,也有时候会调用clear()将Map中的数据清除,那么它们都有什么区别呢? Map<Integer, ...