CentOS7 build FastDFS V5.11 distributed file system and Java integration process in detail

1.1 FastDFS application scenarios

FastDFS is tailor-made for the Internet applications of a distributed file storage system, ideally suited for storing user pictures, videos, documents, and other documents. For Internet applications, and other distributed file systems, compared advantage is obvious. There are several companies that make network disk. Where the storage group number stored in the largest one, the cluster has 400, more than 800 storage server, storage capacity up to 6PB, file number over 100 million, Group sustained growth.
The following is a list of users using FastDFS:
UC (http://www.uc.cn/, storage capacity of more than 10TB)
Alipay (http://www.alipay.com/)
Jingdong Mall (http: //www.360buy. com /)
Tao Tao search (http://www.taotaosou.com/)
fetion (http://feixin.1008.cn/)
go to the market (http://www.ganji.com/)
wash rice (http : //www.61.com/)
Thunder (http://www.xunlei.com/)
ant cellular (http://www.mafengwo.cn/)
Ya-Ya network (http://www.iyaya.com /)
rainbow network (http://3g.ahong.com)
5173 (http://www.5173.com/)
China original network (http://www.yuanchuang.com/)
China division in Beijing Education cloud platform (http : //www.hsjdy.com.cn/)
as the Friends network (http://www.cuctv.com/)
Search Road Network (http://www.sodao.com/)
58 city (http://www.58.com/)
Business Alliance Network (http://www.biz72.com/)
Youth Net (http: //www.youth.cn/)
Bin Li network (http://www.binliy.com/)
fly depending on cloud video (http://www.freeovp.com/)
dream Bazaar (http: //www.moonbasa. com /)
activity help (http://www.eventsboom.com)
51CTO (http://www.51cto.com/)
SouFun (http://www.soufun.com/)

Details of 2.1 FastDFS

FastDFS is an open source distributed file system, she manages files, features include: file storage, file synchronization, file access (file upload, file download), etc., to solve the high-capacity storage and load balancing issues. Particularly suitable for the carrier to file online services, such as photo album sites, video sites, and more.

FastDFS server has two roles: tracker (tracker) and the storage node (storage). Tracker main job scheduling work, since load balancing role in access.

File storage node, all complete file management functions: storage, synchronization, and provide access to interfaces, while FastDFS meta data file management. related meta data is called file attribute of the file to the key-value pair (key value pair) represented manner, such as: width = 1024, which is the key width, value 1024. File meta data is a property list file can contain multiple pairs.

                System Architecture

 

Tracking and storage nodes may be formed by a single multiple servers. Tracker server and storage node can be increased at any time without affecting the online or offline service. Wherein the tracker servers are all equal, the pressure may be increased or decreased according to the server at any time.

In order to support a large capacity, the storage node (server) using the sub-volume (or packet) is organized. Storage system consists of one or more volumes that, between the volume with the volume file are independent, the file capacity of all volumes is the file accumulation capacity of the overall storage system. A volume may be formed from one or more storage servers, the storage server under a file volume is the same, the volume of the multiple storage servers played redundancy and load balancing effect.

Increase in the volume server, the existing file synchronization is completed automatically by the system, after synchronization is complete, the system automatically switches to the new server online service.

When memory is low or about to run out, you can dynamically add volume. Only need to add one or more servers, and configure them for a new roll, so that the expansion of the capacity of the storage system.
FastDFS document identification is divided into two parts: the volume name and file name are indispensable.

3.1 file upload interactive process:

  1. client to upload inquiry tracker storage, no additional parameters;
  2. Returns a tracker storage available;
  3. direct client communication and storage complete the file upload.

3.2 Download file interaction:

  1. client inquiries storage tracker download a file, the file parameter identification (the volume name and file name);
  2. Returns a tracker storage available;
  3. direct client communication and storage complete the file download.

4.FastDFS build tool download

Download link, Baidu Cloud

local/fastdfs-nginx-module/src/common.c:1245: 错误:‘FDFSHTTPParams’没有名为‘support_multi_range’的成员
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] 错误 1
make[1]: Leaving directory `/usr/local/nginx-1.10.1'

整合的时候,fastdfs-nginx-module中的support_multi_range在Version 5.10中找不到。

Version 5.11对应的fastdfs-nginx-module的Version 1.20
Version 5.10对应的fastdfs-nginx-module的Version 1.19

之所以在安装前写了这么一段话,是因为这个很重要,版本不对应会给接下来的安装带来各种问题。

4.1 下载工具:

把源码下载下来4个zip包,再去下个nginx:

4.2 上传到CentOS

上传文件到liunx系统的方法很多。我个人比较喜欢用vsftp上传。 
感兴趣的同学可以参考我一另一篇博文:

CentOS7 搭建vsftpd详细教程

在windows上直接输入ftp地址,把刚刚下载好的文件拖到ftp上即可。 

5.CentOS7FastDFS搭建

 

前面已下载好了要用到的工具集,下面就可以开始安装了:
如果安装过程中出现问题,可以下载我提供的,当前测试可以通过的工具包:

fastdfs-5.11下载
fastdfs-client-java-1.26下载
fastdfs-nginx-module-1.20下载
libfastcommon-1.36下载
nginx-1.12.0下载

5.1 安装libfastcommon

直接进入

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

创建软连接

ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

5.2安装FastDFS

直接进入

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

进入etc/fdfs下,将client,storage,tracker的文件都复制一份

5.3安装tracker

 创建目录,存放tracker的data

/var/fastdfs-data/fastdfs-tracker

修改/etc/fdfs/tracker.conf的内容

1.disabled=false #默认开启 
2.port=22122 #默认端口号 
3.base_path=/var/fastdfs-data/fastdfs-tracker #我刚刚创建的目录 
4.http.server_port=6666 #默认端口是8080

启动

service fdfs_trackerd start

5.4 安装storage

创建目录

/var/fastdfs-data/fastdfs-storage

存放storage角色

/var/fastdfs-data/fastdfs-storage-data

存放data

 

修改/etc/fdfs/storage.conf文件

1.disabled=false 
2.group_name=group1 #组名,根据实际情况修改 
3.port=23000 #设置storage的端口号,默认是23000,同一个组的storage端口号必须一致 
4.base_path=/var/fastdfs-data/fastdfs-storage #设置storage数据文件和日志目录 
5.store_path_count=1 #存储路径个数,需要和store_path个数匹配
6.base_path0=/var/fastdfs-data/fastdfs-storage-data#实际文件存储路径
7.tracker_server=192.168.128.131:22122 #我CentOS7的ip地址
8.http.server_port=8888 #设置 http 端口号

 

创建软引用

ln -s /usr/bin/fdfs_storaged /usr/local/bin

启动storage

service fdfs_storaged start

 

5.5 设置开机启动

vim /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
service fdfs_trackerd start
service fdfs_storaged start

检查服务是否启动

[root@localhost fastdfs]# netstat -unltp | grep fdfs
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      2231/fdfs_trackerd
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      2323/fdfs_storaged

使用monitor查看storage的状态

fdfs_monitor /etc/fdfs/storage.conf

 

5.6 配置客户端

vim /etc/fdfs/client.conf
base_path=/var/fastdfs-data/fastdfs-tracker #tracker服务器文件路径 
tracker_server
=node02:22122 #tracker服务器IP地址和端口号
http.tracker_server_port
=6666 # tracker 服务器的 http端口号,必须和tracker的设置对应起来

5.7模拟上传

[root@node02 ~]# fdfs_upload_file /etc/fdfs/client.conf a.jpg 
group1/M00/00/00/wKh2DF02Bi2AIMTcAADYBNQz0O8898.jpg
组名:group1 
磁盘:M00 
目录:00/00 
文件名称:wKh2DF02Bi2AIMTcAADYBNQz0O8898.jpg

我们仔细看一下,实际文件存储路径下有创建好的多级目录。data下有256个1级目录,每级目录下又有256个2级子目录,总共65536个文件,新写的文件会以hash的方式被路由到其中某个子目录下,然后将文件数据直接作为一个本地文件存储到该目录中。

 

6.1 HTTP访问文件

我们去浏览器用http请求访问一下刚刚的图片: 

我们发现,http不能直接访问到图片。这是为什么呢。
我去官网看了一原码,在HISTORY中发现,原来早在4.05的时候,就remove embed HTTP support

Version 4.05 2012-12-30
* client/fdfs_upload_file.c can specify storage ip port and store path index
* add connection pool
* client load storage ids config
* common/ini_file_reader.c does NOT call chdir
* keep the mtime of file same
* use g_current_time instead of call time function
* remove embed HTTP support

6.2 HTTP请求不能访问文件的原因

我们在使用FastDFS部署一个分布式文件系统的时候,通过FastDFS的客户端API来进行文件的上传、下载、删除等操作。同时通过FastDFS的HTTP服务器来提供HTTP服务。但是FastDFS的HTTP服务较为简单,无法提供负载均衡等高性能的服务,所以FastDFS的开发者——淘宝的架构师余庆同学,为我们提供了Nginx上使用的FastDFS模块(也可以叫FastDFS的Nginx模块)。 FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组之间的服务器需要复制文件,有延迟的问题.假设Tracker服务器将文件上传到了192.168.128.131,文件ID已经返回客户端,这时,后台会将这个文件复制到192.168.128.131,如果复制没有完成,客户端就用这个ID在192.168.128.131取文件,肯定会出现错误。这个fastdfs-nginx-module可以重定向连接到源服务器取文件,避免客户端由于复制延迟的问题,出现错误。
正是这样,FastDFS需要结合nginx,所以取消原来对HTTP的直接支持。

 

7. 安装nginx并添加fastdfs-nginx-module

解压后进入nginx目录编译安装nginx,并添加fastdfs-nginx-module:

./configure --prefix=/usr/local/nginx --add-module=/usr/yong.cao/dev/nginx/fastdfs-nginx-module/src    
#解压后fastdfs-nginx-module所在的位置

执行安装

make && make install

8. 配置storage nginx

修改nginx.conf

        location ~/group1/M00 {
            root /var/fastdfs-data/fastdfs-storage-data;
            ngx_fastdfs_module;
        }

然后进入FastDFS安装时的解压过的目录,将http.conf和mime.types拷贝到/etc/fdfs目录下:

另外还需要把fastdfs-nginx-module安装目录中src目录下的mod_fastdfs.conf也拷贝到/etc/fdfs目录下:

[root@localhost fastdfs-5.11]# cd /usr/yong.cao/ftp/fastdfs-5.11/conf/
[root@localhost conf]# ls
anti-steal.jpg  http.conf   storage.conf      tracker.conf
client.conf     mime.types  storage_ids.conf
cp http.conf /etc/fdfs/
cp mime.types /etc/fdfs/
cp /usr/yong.cao/dev/nginx/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/

对mod_fastdfs.conf进行修改

base_path=/var/fastdfs-data/fastdfs-storage  #保存日志目录
 tracker_server=node02:22122 #tracker服务器的IP地址以及端口号
 storage_server_port=23000 #storage服务器的端口号
 url_have_group_name = true #文件 url 中是否有 group 名
 store_path0=/var/fastdfs-data/fastdfs-storage-data  #存储路径
 group_count = 3 #设置组的个数,事实上这次只使用了group1

文件最后设置一个group

[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/var/fastdfs-data/fastdfs-storage-data

[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/var/fastdfs-data/fastdfs-storage-data

[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/var/fastdfs-data/fastdfs-storage-data

创建软链接

ln -s /var/fastdfs-data/fastdfs-storage-data/data/ /var/fastdfs-data/fastdfs-storage-data/data/M00

启动nginx

 

访问图片,显示

 

 ok,fastDFS搭建成功

参考博客https://blog.csdn.net/m0_37797991/article/details/73381648

Guess you like

Origin www.cnblogs.com/littlepage/p/11229445.html