Fdfs 配置分布式文件系统

FastDFS的简介

FastDFS是一款开源的轻量级分布式文件系统纯C实现,支持Linux、FreeBSD等UNIX系统类google FS,不是通用的文件系统,只能通过专有API访问,目前提供了C、Java和PHP API为互联网应用量身定做,解决大容量文件存储问题,追求高性能和高扩展性FastDFS可以看做是基于文件的key value pair存储系统,称作分布式文件存储服务更为合适。

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

存储节点存储文件,完成文件管理的所有功能,就是这样的存储、同步和提供存取接口,FastDFS同时对文件的metadata进行管理。所谓文件的meta data就是文件的相关属性,以键值对(key valuepair)方式表示,如:width=1024,其中的key为width,value为1024。文件metadata是文件属性列表,可以包含多个键值对。

FastDFS的特性

  1. 分组存储,灵活简洁、对等结构,不存在单点
  2. 文件ID由FastDFS生成,作为文件访问凭证,FastDFS不需要传统的name server
  3. 和流行的web server无缝衔接,FastDFS已提供apache和nginx扩展模块
  4. 大、中、小文件均可以很好支持,支持海量小文件存储
  5. 支持多块磁盘,支持单盘数据恢复
  6. 支持相同文件内容只保存一份,节省存储空间
  7. 存储服务器上可以保存文件附加属性
  8. 下载文件支持多线程方式,支持断点续传

CentOS 7.0

配置虚拟机上网
yum -y install wget
yum -y install gcc
yum -y install perl

查看IP地址
ip addr
启动关闭服务
systemctl start/stop/restart <服务名>

配置网卡
TYPE=Ethernet
BOOTPROTO=no
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=04d204f1-8831-42b4-8d64-c4fc7af133d9
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.2.138
GATEWAY=192.168.2.2
DNS1=114.114.114.114

下载libfastcommon

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.35.tar.gz
tar -zxvf V1.0.35.tar.gz
cd libfastcommon-1.0.35
./make.sh
./make.sh install

安装FastDFS

wget https://github.com/happyfish100/fastdfs/archive/V5.10.tar.gz

tar xvf V5.10.tar.gz

cd fastdfs-5.10

./make.sh

./make.sh install

如果出现编译错误
fastdfs-5.10/storage/fdfs_storaged.c:130: undefined reference to `g_exe_name

请重新./make.sh clean后再次编译

配置跟踪服务器(tracker server)

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
  1. 编辑tracker server配置文件tracker.conf
    disabled=false
    port=22122
    base_path=/u01/data/fastdfs/tracker

  2. 编辑client端的配置文件client.conf
    base_path=/u01/data/fastdfs/tracker
    tracker_server=192.168.2.138:22122

  3. 创建tracker server数据目录
    mkdir -p /u01/data/fastdfs/tracker

  4. 启动tracker server
    /etc/init.d/fdfs_trackerd start
    tracker server自动在/u01/data/fastdfs/tracker目录新建data和logs目录

配置存储服务器(storage server)

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
  1. 编辑storage server配置文件storage.conf
    disabled=false
    port=23000
    base_path=/u01/data/fastdfs/storage
    tracker_server=192.168.25.100:22122
    store_path0=/u01/data/fastdfs/storage
    http.server_port=81

  2. 创建storage server数据目录
    mkdir -p /u01/data/fastdfs/storage

  3. 启动storage server
    /etc/init.d/fdfs_storaged start

  4. 文件上传测试
    [root@localhost conf.d]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf ./default.conf
    group1/M00/00/00/wKgZZFxD2EqABE-RAAAFc0mlLyw60.conf
    [root@localhost conf.d]#

  5. 文件下载测试
    [root@localhost conf.d]# /usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgZZFxD2EqABE-RAAAFc0mlLyw60.conf

安装nginx

  1. 更新nginx安装库
    rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release- centos-7-0.el7.ngx.noarch.rpm

    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    yum makecache

    yum update

  2. 安装nginx
    yum info nginx
    yum install nginx

存储服务器(storage server)安装并配置nginx

1、安装fastdfs-nginx-module
fastdfs-nginx-module解决同组存储服务器之间文件复制不一致情况下,为客户端正确访问到文件提供支持。

wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS Nginx Module Source Code/fastdfs-nginx-module_v1.16.tar.gz

注意:可能会下载不下来,建议直接复制链接下载后,再传到Linux上

tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

cd fastdfs-nginx-module/src/

vi config

编辑config文件,执行如下命令进行批量替换并保存退出,修改/user/local为/user
:%s+/usr/local/+/usr/+g

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

修改文件mod_fastdfs.conf
vi /etc/fdfs/mod_fastdfs.conf

connect_timeout=10
base_path=/tmp
tracker_server=192.168.2.138:22122
storage_server_port=23000
url_have_group_name = true
store_path0=/u01/data/fastdfs/storage
group_name=group1
#[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/u01/data/fastdfs/storage

3、nginx添加fastdfs-nginx-module模块
查看nginx版本
nginx -V

wget http://nginx.org/download/nginx-1.14.2.tar.gz

tar -zvxf nginx-1.12.1.tar.gz

yum -y install pcre

yum -y install openssl-devel

执行configure脚本

./configure  --prefix=/etc/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 --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock 
--http-client-body-temp-path=/var/cache/nginx/client_temp --http
-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-
temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=
/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/ngin
x/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio 
--with-threads --with-http_addition_module --with-http_auth_request_
module --with-http_dav_module --with-http_flv_module --with-http_
gunzip_module --with-http_gzip_static_module --with-http_mp4_
module --with-http_random_index_module --with-http_realip_module
 --with-http_secure_link_module --with-http_slice_module --with-http_
 ssl_module --with-http_stub_status_module --with-http_sub_module 
 --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_
 ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_
 SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=
 4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,
 -z,now -pie' --add-module=/u01/fastdfs-nginx-module/src

最后一行:–add-module=/u01/fastdfs-nginx-module/src

make
make install

4、拷贝FastDFS中的部分配置文件到/etc/fdfs目录中
cp /u01/fastdfs/fastdfs-5.10/conf/http.conf /etc/fdfs/
cp /u01/fastdfs/fastdfs-5.10/conf/mime.types /etc/fdfs/

5、修改Nginx配置文件
vi /etc/nginx/conf.d/default.conf,
如果你安装的Nginx不存在conf.d目录,直接在nginx.conf中修改如下内容
添加如下内容:


server {
	listen 81;
	server_name localhost;
	location ~ /group1/M00 {
		root /u01/data/fastdfs/storage;
		ngx_fastdfs_module;
	}
	error_page 500 502 503 504 /50x.html;
	location = /50x.html {
		root html;
	}
}
  1. 关闭防火墙并启动Nginx
    systemctl stop firewalld.service
    systemctl start firewalld.service

  2. 通过Nginx代理下载文件
    http://192.168.25.100:81/group1/M00/00/00/wKgZZFxD3VKABeg-AAAFc0mlLyw93.conf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值