分布式存储服务器FastDFS

2018-11-22  本文已影响0人  程序猿TT

分布式存储服务器FastDFS - 入门介绍与部署搭建

1,简介

FastDFS是一款类GoogleFS的开源分布式文件系统,它用纯C语言实现,支持Linux、FreeBSD、AIX等UNIX系统。它只能通过专有API对文件进行存取访问,不支持POSIX接口方式,不能mount使用。准确地讲,GoogleFS以及FastDFS、mogileFS、HDFS、TFS等类GoogleFS都不是系统级的分布式文件系统,而是应用级的分布式文件存储服务。

FastDFS是为互联网应用量身定做的分布式文件系统,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标。和现有的类Google FS分布式文件系统相比,FastDFS的架构和设计理念有其独到之处,主要体现在轻量级、分组方式和对等结构三个方面。

FastDFS是由国人余庆所开发,其项目地址:https://github.com/happyfish100

2,架构

2.1,架构图

FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。


image.png

2.2,模块介绍

3,部署安装

3.1,安装包准备

执行下面的shell,下载安装包,分别是libfastcommon基础组件、fastdfs、nginx、fastdfs-nginx-module。

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
wget http://nginx.org/download/nginx-1.14.0.tar.gz
wget http://jaist.dl.sourceforge.NET/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz

3.2,gcc gcc-c++等环境准备

yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

3.3,安装libfastcommon基础组件

3.4,安装fastdfs

安装

配置文件

# the base path to store data and log files
base_path=/home/fastdfs/tracker/data-and-log
mkdir -p /home/fastdfs/tracker/data-and-log
# the base path to store data and log files
base_path=/home/fastdfs/storage

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/fastdfs/storage/images-data0
store_path1=/home/fastdfs/storage/images-data1
store_path2=/home/fastdfs/storage/images-data2

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=192.168.80.82:22122
mkdir -p  \
/home/fastdfs/storage/images-data0 \
/home/fastdfs/storage/images-data1 \
/home/fastdfs/storage/images-data2

启动测试

tracker server

storage server

3.4,client测试

# the base path to store log files
base_path=/home/fastdfs/client/data-and-log

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=192.168.80.82:22122

kevin@orange:~/fastdfs/temp$ wget http://img.tuku.cn/file_thumb/201504/m2015042221045424.jpg
kevin@orange:~/fastdfs/temp$ /usr/bin/fdfs_test /etc/fdfs/client.conf upload ./m2015042221045424.jpg
kevin@orange:~/fastdfs/storage/images-data0$ find . -name "*.jpg"
./data/00/00/wKgBIFmemtyAGcebAAAdgkSCZh4105.jpg
./data/00/00/wKgBIFmemtyAGcebAAAdgkSCZh4105_big.jpg

kevin@orange:~/fastdfs/temp$ /usr/bin/fdfs_upload_file /etc/fdfs/client.conf m2015042221045424.jpg
group1/M00/00/00/wKgBIFmenECAAOdbAAAdgkSCZh4066.jpg
kevin@orange:~/fastdfs/storage/images-data0$ find . -name "*.jpg" | xargs ls -l
-rw-r--r-- 1 root root 7554  8月 24 17:22 ./data/00/00/wKgBIFmemtyAGcebAAAdgkSCZh4105_big.jpg
-rw-r--r-- 1 root root 7554  8月 24 17:22 ./data/00/00/wKgBIFmemtyAGcebAAAdgkSCZh4105.jpg
-rw-r--r-- 1 root root 7554  8月 24 17:28 ./data/00/00/wKgBIFmenECAAOdbAAAdgkSCZh4066.jpg

3.5,安装nginx及其插件

安装

# 解压nginx的fastdfs插件文件
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

# 修改配置文件中的无效路径,把local去掉
vim fastdfs-nginx-module/src/config

CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
修改为
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

复制文件:cp fastdfs-5.05/conf/http.conf /etc/fdfs
复制文件:cp fastdfs-5.05/conf/mime.types /etc/fdfs

sudo apt-get install openssl libssl-dev
sudo apt-get install libpcre3 libpcre3-dev  
sudo apt-get install zlib1g-dev 

tar -zxvf nginx-1.11.8.tar.gz
cd nginx-1.11.8
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/local/nginx/nginx.pid \
--lock-path=/var/lock/nginx/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-ipv6 \
--add-module=/root/tools/fastDFS_tools/fastdfs-nginx-module/src

root@orange:/usr/local/nginx/conf# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.11.8
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) 
configure arguments: --prefix=/usr/local/nginx --pid-path=/var/local/nginx/nginx.pid --lock-path=/var/lock/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --add-module=/home/kevin/fastdfs/install/soft/fastdfs-nginx-module/src

配置文件

# the base path to store log files
base_path=/home/kevin/fastdfs/fastdfs-nginx-module/data-and-log/

# FastDFS tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=192.168.80.82:22122

# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/home/fastdfs/storage/images-data0
store_path1=/home/fastdfs/storage/images-data1
store_path2=/home/fastdfs/storage/images-data2

# 在http添加对其他配置文件的引用
include /usr/local/nginx/conf/conf.d/*.conf;

server {
            listen       8888;
            listen       [::]:8888;
            server_name  localhost;
            location ~/group[0-9]/ {
                ngx_fastdfs_module;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
            root   html;
            }
        }

4,测试

kevin@orange:~/fastdfs/temp$ fdfs_upload_file /etc/fdfs/client.conf meixi.jpg
group1/M00/00/00/wKgBIFmeyGWAJHacAACiyMy3SR8400.jpg
kevin@orange:~/fastdfs/temp$ fdfs_upload_file /etc/fdfs/client.conf  gnuplot.pdf 
group1/M00/00/00/wKgBIFmeyJiAFBM2ABhOlsdTgP0787.pdf
kevin@orange:~/fastdfs/temp$ fdfs_upload_file /etc/fdfs/client.conf my_multi.cnf 
group1/M00/00/00/wKgBIFmeyLeARRxPAAAHX_E2eqU506.cnf
kevin@orange:~/fastdfs/temp$ fdfs_upload_file /etc/fdfs/client.conf tiger.txt 
group1/M00/00/00/wKgBIFmeyLyAEhFzAAAFTfDtQ9M236.txt

wget http://192.168.1.32:8888/group1/M00/00/00/wKgBIFmeyGWAJHacAACiyMy3SR8400.jpg
wget http://192.168.1.32:8888/group1/M00/00/00/wKgBIFmeyJiAFBM2ABhOlsdTgP0787.pdf
wget http://192.168.1.32:8888/group1/M00/00/00/wKgBIFmeyLeARRxPAAAHX_E2eqU506.cnf
wget http://192.168.1.32:8888/group1/M00/00/00/wKgBIFmeyLyAEhFzAAAFTfDtQ9M236.txt

5,参考网址

上一篇下一篇

猜你喜欢

热点阅读