Build FastDFS distributed cluster

Preface

FastDFS is an open source lightweight distributed file system written in C language. It manages file processes. Its functions include: file storage, file synchronization, file access (file upload, file download), etc., which solves the problem of large-capacity storage and The problem of load balancing is particularly suitable for online services that use files as the carrier, such as photo album websites, video websites, etc. FastDFS is tailored for the Internet, taking full account of redundant backup, load balancing, current expansion, etc., and focusing on high availability. With high performance and other indicators, it is easy to build a high-performance file server cluster with FastDFS to provide file upload and download services.

1. The principle and structure of FastDFS

1. FastDFS architecture The
FastDFS architecture includes Tracker server and Storage server. The client requests the Tracker server to upload and download files, and the Storage server completes the file upload and download through the Tracker server scheduling.


* Tracker server:负责调度及负载均衡,通过Tracker server,在文件上传时可以根据一些策略找到Storage server来提供
 上传服务,可以将tracker称为追踪服务器或调度服务器;
* Storage server:负责文件最终存储,客户端上传的文件最终存储在storage服务器上,Storage server没有实现自己的文
  件系统,而是利用操作系统的文件系统来管理文件,可以将storage称为存储服务器。

Two, deploy FastDFS cluster,

1. The required environment is as follows:

* Tracker Server跟踪服务器:10.10.1.7
* Tracker Server跟踪服务器:10.10.1.6

* Storage Server存储服务器:10.10.1.5
* Storage Server存储服务器:10.10.1.6
* Storage Server存储服务器:10.10.1.7

2. All tracker and storage nodes perform the following operations

[root@master ~]# yum -y install make cmake gcc gcc-c++    //安装所需依赖
[root@master ~]# cd /usr/local/src/ 
[root@master src]# unzip libfastcommon-master   //安装libfatscommon
[root@master src]# cd libfastcommon-master 
[root@master libfastcommon-master]# ./make.sh   //编译安装
[root@master libfastcommon-master]# ./make.sh   install

[root@master libfastcommon-master]# cd ..
[root@master src]# tar -zxvf FastDFS_v5.08.tar.gz   //安装FastDFS
[root@master src]# cd FastDFS
[root@master FastDFS]# ./make.sh             //编译安装
[root@master FastDFS]# ./make.sh    install

采用默认安装方式,相应的文件与目录检查如下:
    /etc/init.d/fdfs_storaged
   /etc/init.d/fdfs_trackerd
[root@master FastDFS]# ll /etc/fdfs/ 
总用量 40
-rw-r--r-- 1 root root 1461 12月 17 16:10 client.conf.sample
-rw-r--r-- 1 root root 7927 12月 17 16:10 storage.conf.sample
-rw-r--r-- 1 root root 7200 12月 17 16:10 tracker.conf.sample

//如上在所有节点上执行,安装相关依赖

3. Configure tracker server and storaged server

[root@tracker ~]# cd /etc/fdfs/
[root@tracker fdfs]# cp /etc/fdfs/tracker.conf.sample  /etc/fdfs/tracker.conf   //重新命名
[root@tracker fdfs]# vim tracker.conf 
#修改内容如下:
disabled=false              #启用配置文件
port=22122                  #tracker服务器端口(默认22122)
base_path=/fastdfs/tracker    #存储日志和数据的根目录
store_group=group1,group2,group3       #分别代表三台主机
[root@tracker fdfs]# mkdir -p /fastdfs/tracker/   #创建存储日志和数据的根目录
[root@tracker fdfs]# /etc/init.d/fdfs_trackerd  start   #启动tracker服务

配置storage服务器
[root@tracker fdfs]# cp storage.conf.sample  storage.conf    #重新命名 
[root@tracker fdfs]# vim storage.conf 
# 修改的内容如下:
disabled=false                      # 启用配置文件
group_name=group2           #代表当前主机是那个组
port=23000                          # storage服务端口
base_path=/fastdfs/storage          # 数据和日志文件存储根目录
store_path0=/fastdfs/storage        # 第一个存储目录
tracker_server=10.10.1.7:22122  # tracker服务器IP和端口
tracker_server=10.10.1.6:22122  #tracker服务器IP2和端口
http.server_port=8888               # http访问文件的端口
[root@tracker fdfs]# mkdir -p  /fastdfs/storage/ 
[root@tracker fdfs]# /etc/init.d/fdfs_storaged  start    #启动storaged

4. Modify the Tracker server client configuration file

[root@master fdfs]# cp client.conf.sample  client.conf
[root@master fdfs]# vim client.conf
修改配置如下:
base_path=/fastdfs/tracker
tracker_server=10.10.1.7:22122  # tracker服务器IP和端口
tracker_server=10.10.1.6:22122  #tracker服务器IP2和端口

5. The following simple test to verify success

[root@tracker src]# ls
FastDFS  FastDFS_v5.08.tar.gz  libfastcommon-master  libfastcommon-master.zip  test2.png
#随机找一张图片上传到/usr/local/src/下
#以下存图会随机存储到三台主机不同group
[root@tracker src]# /usr/bin/fdfs_upload_file  /etc/fdfs/client.conf /usr/local/src/test2.png 
group2/M00/4B/55/CgoBB1_kTMKAdHgCACM5jnZmB2c673.png
[root@tracker src]# /usr/bin/fdfs_upload_file  /etc/fdfs/client.conf /usr/local/src/test2.png 
group1/M00/00/6A/CgoBBl_kTMOAFG1PACM5jnZmB2c579.png
[root@tracker src]# /usr/bin/fdfs_upload_file  /etc/fdfs/client.conf /usr/local/src/test2.png 
group2/M00/4B/55/CgoBB1_kTMSAYSvOACM5jnZmB2c978.png
#本地图片上传到Fastdfs
#查看是否存储成功如下:
[root@tracker 55]# pwd
/fastdfs/storage/data/4B/55
[root@tracker 55]# ls

Build FastDFS distributed cluster

Guess you like

Origin blog.51cto.com/14306186/2572283