前言

  FastDFS是一个开源的轻量级分布式文件系统,由跟踪服务器(tracker server)、存储服务器(storage server)和客户端(client)三个部分组成,主要解决了海量数据存储问题,特别适合以中小文件(建议范围:4KB < file_size <500MB)为载体的在线服务。

(1)每次上传文件后都会返回一个地址,用户需要自己保存此地址。
(2)为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式。存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起到了冗余备份和负载均衡的作用。

配置环境:Centos7

tracker server:192.168.8.20

storage server:192.168.8.10

安装

一、安装tracker 服务

1.安装libfastcommon:公共函数库,基础环境

# 安装c的编译环境
yum -y install gcc-c++ libevent
cd /home
# 下载libfastcommon包
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon/
# 编译
./make.sh
# 安装
./make.sh install

安装完成

 [root@localhost libfastcommon]# ./make.sh install
mkdir -p /usr/lib64
mkdir -p /usr/lib
mkdir -p /usr/include/fastcommon
install -m 755 libfastcommon.so /usr/lib64
install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_define.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h fast_mpool.h fast_allocator.h fast_buffer.h skiplist.h multi_skiplist.h flat_skiplist.h skiplist_common.h system_info.h fast_blocked_queue.h php7_ext_wrapper.h id_generator.h char_converter.h char_convert_loader.h common_blocked_queue.h multi_socket_client.h skiplist_set.h fc_list.h json_parser.h /usr/include/fastcommon
if [ ! -e /usr/lib/libfastcommon.so ]; then ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so; fi

2.安装fastdfs

cd /home
# 下载fastdfs包
git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs
# 编译
./make.sh
# 安装
./make.sh install

安装完成

 [root@localhost fastdfs]# ./make.sh install
mkdir -p /usr/bin
mkdir -p /etc/fdfs
cp -f fdfs_trackerd /usr/bin
if [ ! -f /etc/fdfs/tracker.conf.sample ]; then cp -f ../conf/tracker.conf /etc/fdfs/tracker.conf.sample; fi
if [ ! -f /etc/fdfs/storage_ids.conf.sample ]; then cp -f ../conf/storage_ids.conf /etc/fdfs/storage_ids.conf.sample; fi
mkdir -p /usr/bin
mkdir -p /etc/fdfs
cp -f fdfs_storaged /usr/bin
if [ ! -f /etc/fdfs/storage.conf.sample ]; then cp -f ../conf/storage.conf /etc/fdfs/storage.conf.sample; fi
mkdir -p /usr/bin
mkdir -p /etc/fdfs
mkdir -p /usr/lib64
mkdir -p /usr/lib
cp -f fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file fdfs_download_file fdfs_delete_file fdfs_file_info fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_upload_appender /usr/bin
if [ 0 -eq 1 ]; then cp -f libfdfsclient.a /usr/lib64; cp -f libfdfsclient.a /usr/lib/;fi
if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; cp -f libfdfsclient.so /usr/lib/;fi
mkdir -p /usr/include/fastdfs
cp -f ../common/fdfs_define.h ../common/fdfs_global.h ../common/mime_file_parser.h ../common/fdfs_http_shared.h ../tracker/tracker_types.h ../tracker/tracker_proto.h ../tracker/fdfs_shared_func.h ../storage/trunk_mgr/trunk_shared.h tracker_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h /usr/include/fastdfs
if [ ! -f /etc/fdfs/client.conf.sample ]; then cp -f ../conf/client.conf /etc/fdfs/client.conf.sample; fi

3.修改tracker server的配置文件

 [root@localhost fastdfs]# cd /etc/fdfs/
[root@localhost fdfs]# ls -l
总用量 32
-rw-r--r--. 1 root root 1461 9月 20 12:55 client.conf.sample #客户端上传配置文件
-rw-r--r--. 1 root root 7978 9月 20 12:55 storage.conf.sample #文件存储服务器配置文件
-rw-r--r--. 1 root root 105 9月 20 12:55 storage_ids.conf.sample
-rw-r--r--. 1 root root 7446 9月 20 13:00 tracker.conf #负载均衡调度服务器配置文件
-rw-r--r--. 1 root root 7443 9月 20 12:55 tracker.conf.sample

这里修改 tracker.conf

# 创建fastdfs的data数据文件
mkdir -p /data/fastdfs
# 修改tracker的配置文件
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vi /etc/fdfs/tracker.conf
# 将tracker ip改为本机tracker 本机ip
bind_addr= 改为 bind_addr=192.168.8.20
# fdfs的数据文件路径
base_path=/home/yuqing/fastdfs 改为 base_path=/data/fastdfs
# tracker 的端口
http.server_port=8080 改为 http.server_port=80

4.启动tracker server

  • /etc/init.d/fdfs_trackerd start
 # 启动tracker
[root@localhost fdfs]# /etc/init.d/fdfs_trackerd start
Starting fdfs_trackerd (via systemctl): [ 确定 ]
[root@localhost fdfs]# ps -ef | grep fdfs
root 28619 1 0 13:07 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 28627 27151 0 13:07 pts/3 00:00:00 grep --color=auto fdfs
[root@localhost fdfs]# netstat -tunlp | grep fdfs
8 tcp 0 0 192.168.8.20:22122 0.0.0.0:* LISTEN 28619/fdfs_trackerd

5.设置开机自启

/sbin/chkconfig --add fdfs_trackerd
/sbin/chkconfig --level 2345 fdfs_trackerd on

二、安装storage服务

1.安装gcc编译环境

yum -y install gcc-c++ libevent

2.安装libfastcommon

cd /home
# 下载libfastcommon包
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon/
# 编译
./make.sh
# 安装
./make.sh install

3.安装fastdfs

cd /home
# 下载fastdfs包
git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs
# 编译
./make.sh
# 安装
./make.sh install

4.修改storage server配置文件

# 创建数据目录
mkdir -p /data/fastdfs
#修改storage server的配置文件:
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vi /etc/fdfs/storage.conf
bind_addr= 改为 bind_addr=192.168.8.10
#base_path需要和tracker部分的base_path保持一致,如果有修改过tracker的
base_path=/home/yuqing/fastdfs 改为 base_path=/data/fastdfs
#修改storage的资源存放路径
store_path0=/home/yuqing/fastdfs 改为 store_path0=/data/fastdfs
#如果有多个挂载磁盘则定义多个store_path,如下
#store_path1=......
#store_path2=......
修改storage的对应的tracker_server的ip地址和端口
tracker_server=192.168.209.121:22122 改为 tracker_server=192.168.8.20:22122
#如果有多个则配置多个tracker_server
#tracker_server=......
#tracker_server=......
# 端口我这里就不改了
http.server_port=8888

5.启动storage server

  • /etc/init.d/fdfs_storaged start
 # 启动storage server
[root@localhost libfastcommon]# /etc/init.d/fdfs_storaged start
Reloading systemd: [ 确定 ]
Starting fdfs_storaged (via systemctl): [ 确定 ]
# 查看进程
[root@localhost libfastcommon]# netstat -tunlp | grep fdfs
7 tcp 0 0 192.168.8.10:23000 0.0.0.0:* LISTEN 26440/fdfs_storaged

6.设置开机自启

/sbin/chkconfig --add fdfs_storaged
/sbin/chkconfig --level 2345 fdfs_storaged on

三、在tracker server服务器配置客户端测试文件上传

在tracker server服务器查看tracker与storage连接情况

 [root@localhost home]# netstat -tnlpa|grep 22122
tcp 0 0 192.168.8.20:22122 0.0.0.0:* LISTEN 28619/fdfs_trackerd
tcp 0 0 192.168.8.20:22122 192.168.8.10:49982 ESTABLISHED 28619/fdfs_trackerd

配置客户端

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vi /etc/fdfs/client.conf
#base_path需要和tracker部分的base_path保持一致
base_path=/home/yuqing/fastdfs
改为 base_path=/data/fastdfs
tracker_server=192.168.0.197:22122
改为
tracker_server=192.168.8.20:22122

测试文件上传

 [root@localhost home]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/1
This is FastDFS client test program v5.12 Copyright (C) 2008, Happy Fish / YuQing FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail. [2019-09-20 13:39:11] DEBUG - base_path=/data/fastdfs, connect_timeout=10, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.8.10, port=23000 group_name=group1, ip_addr=192.168.8.10, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgICl2EZf-AXblfAAAAAAAAAAA6122370
source ip address: 192.168.8.10
file timestamp=2019-09-20 13:39:11
file size=0
file crc32=0
example file url: http://192.168.8.10/group1/M00/00/00/wKgICl2EZf-AXblfAAAAAAAAAAA6122370
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgICl2EZf-AXblfAAAAAAAAAAA6122370_big
source ip address: 192.168.8.10
file timestamp=2019-09-20 13:39:11
file size=0
file crc32=0
example file url: http://192.168.8.10/group1/M00/00/00/wKgICl2EZf-AXblfAAAAAAAAAAA6122370_big

四、在storage server服务器配置nginx

安装nginx关于fastdfs集合的扩展模块

cd /home
wget http://nginx.org/download/nginx-1.15.5.tar.gz
#jemalloc 优化nginx,内存管理
wget https://github.com/jemalloc/jemalloc/releases/download/5.1.0/jemalloc-5.1.0.tar.bz2
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
#nginx缓存清理模块
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
yum -y install openssl openssl-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel
tar -jxvf jemalloc-5.1.0.tar.bz2
cd jemalloc-5.1.0
./configure --prefix=/usr/local/jemalloc --libdir=/usr/local/lib
make;make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf
ldconfig
cd ../
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www -s /sbin/nologin
tar -zxvf pcre-8.42.tar.gz
tar -zxvf ngx_cache_purge-2.3.tar.gz
tar -zxvf nginx-1.15.5.tar.gz
cd nginx-1.15.5
./configure --prefix=/usr/local/nginx \
--with-pcre=/home/pcre-8.42 \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-ld-opt="-ljemalloc" \
--with-http_realip_module \
--add-module=/home/fastdfs-nginx-module/src \
--add-module=/home/ngx_cache_purge-2.3
make;make install

修改mod_fastdfs配置文件

cp /home/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
cd /home/fastdfs/conf/ #进入fastdfs安装包文件夹
cp anti-steal.jpg http.conf mime.types /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
base_path=/tmp 改为 base_path=/data/fastdfs
tracker_server=tracker:22122 改为 tracker_server=192.168.8.20:22122
store_path0=/home/yuqing/fastdfs 改为 store_path0=/data/fastdfs
url_have_group_name = false 改为 true
http.server_port=801 #此端口为上传文件返回url中的端口号

修改nginx配置文件

  • vi /usr/local/nginx/conf/nginx.conf
server {
listen 801;
server_name 192.168.8.10;
location /group1/M00 {
ngx_fastdfs_module;
add_header Content-Disposition "attachment;filename=$arg_attname";
}
}

智能判断是打开或者下载请参考:https://www.cnblogs.com/jxd283465/p/11506568.html

添加nginx的启动脚本

  • vi /etc/init.d/nginx
#! /bin/sh
ulimit -n 65535
# Description: Startup script for nginx
# chkconfig: 2345 55 25
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0

nginx添加到服务,开机自启

chmod 700 /etc/init.d/nginx
/sbin/chkconfig --add nginx
/sbin/chkconfig --level 2345 nginx on
#启动nginx
[root@storage72 opt]# /etc/init.d/nginx start
Starting nginx daemon: nginxngx_http_fastdfs_set pid=21702

五、在tracker server服务器上设置nginx反向代理

安装nginx

  • yum -y install nginx
  upstream fdfs_group1 {
    server 192.168.8.10:801 weight=1 max_fails=2 fail_timeout=30s;
  }
server {
listen 801;
server_name 192.168.8.20;
location /group1/M00 {
proxy_pass http://fdfs_group1;
}
}

注意:如果想修改生成url的端口号

修改tracker server服务器的客户端配置文件

vi /etc/fdfs/client.conf

【linux】【FastDFS】FastDFS安装的更多相关文章

  1. 分布式文件系统 FastDFS 5.0.5 & Linux CentOS 7 安装配置(单点安装)——第一篇

    分布式文件系统 FastDFS 5.0.5 & Linux CentOS 7 安装配置(单点安装)--第一篇 简介 首先简单了解一下基础概念,FastDFS是一个开源的轻量级分布式文件系统,由 ...

  2. Linux下离线安装docker与fastDFS

    一.Linux下离线安装Docker 基础环境 1.操作系统:CentOS 7 2.Docker版本:docker-19.03.9.tgz 官方下载地址(打不开可能需要科学-上网) 3.官方参考文档: ...

  3. Linux 下 FastDFS v5.08 分布式文件系统的安装

    一.系统安装目录 源代码包目录 /data/wwwroot libevent安装目录 /usr/local/libevent FastDFS安装目录 /data/fastdfs nginx安装目录 / ...

  4. FastDFS单机版安装

    FastDFS 分布式文件系统 1 目标 了解项目中使用FastDFS的原因和意义. 掌握FastDFS的架构组成部分,能说出tracker和storage的作用. 了解FastDFS+nginx上传 ...

  5. FastDFS部署安装全过程

    你好!欢迎阅读我的博文,你可以跳转到我的个人博客网站,会有更好的排版效果和功能. 此外,本篇博文为本人Pushy原创,如需转载请注明出处:https://pushy.site/posts/153205 ...

  6. FastDFS的安装(复制自己用)

    FastDFS 安装及使用 FastDFS 安装及使用 2012-11-17 13:10:31|  分类: Linux|举报|字号 订阅     Google了一下,流行的开源分布式文件系统有很多,介 ...

  7. FastDFS的安装及上传下载(二)

    百度云:所有附件的地址 一 安装前的检查 检查Linux上是否安装了 gcc.libevent.libevent-devel,执行如下yum命令检查: [root@node02 ~]# yum lis ...

  8. 01.FastDFS的安装部署

    1.FastDFS简介 (1)FastDFS的功能介绍 FastDFS是一个开源的分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负 ...

  9. FASTDFS 5X安装

    FASTDFS 5X安装 http://www.wingdevops.com/?p=603 流行的开源分布式文件系统有很多,FastDFS 是国人在mogileFS的基础上进行改进的key-value ...

  10. FastDFS + Nginx 安装

    1.安装FastDFS依赖lib包 cd /usr/local/src/ git clone https://github.com/happyfish100/libfastcommon.git cd  ...

随机推荐

  1. restapi(6)- do it the functional way, 重温函数式编程

    再次看了看上篇博客的源代码,发现连自己都看不懂了.想是为了赶时间交货不知不觉又回到OOP行令模式了,看看下面这段代码: (post & parameters('pid,'desc.?,'wid ...

  2. AVL树(二叉平衡树)详解与实现

    AVL树概念 前面学习二叉查找树和二叉树的各种遍历,但是其查找效率不稳定(斜树),而二叉平衡树的用途更多.查找相比稳定很多.(欢迎关注数据结构专栏) AVL树是带有平衡条件的二叉查找树.这个平衡条件必 ...

  3. Python笔记_基础

    1.注释 # 单行注释 """ 多行注释,一般用于类说明 """ 或 ''' 多行注释 ''' 2.工作日志 # TODO 说明性文字 记录 ...

  4. 【原创】为什么Redis集群有16384个槽

    引言 我在<那些年用过的Redis集群架构(含面试解析)>一文里提到过,现在redis集群架构,redis cluster用的会比较多. 如下图所示 对于客户端请求的key,根据公式HAS ...

  5. Leetcode之深度优先搜索(DFS)专题-1080. 根到叶路径上的不足节点(Insufficient Nodes in Root to Leaf Paths)

    Leetcode之深度优先搜索(DFS)专题-1080. 根到叶路径上的不足节点(Insufficient Nodes in Root to Leaf Paths) 这篇是DFS专题的第一篇,所以我会 ...

  6. SqlServer关于“无法删除数据库 "XXXX",因为该数据库当前正在使用”问题的解决方案

    引言 在项目中,通过使用SQL语句“DROP DATABASE [数据库名]”删除数据时,一直出现“无法删除数据库 "XXXX",因为该数据库当前正在使用”的错误信息,经测试在Sq ...

  7. 四种为HttpClient添加默认请求报头的解决方案

    HttpClient在Web调用中具有广泛的应用,而为它添加默认请求头是我们经常遇到的需求,本文介绍4种为HttpClient添加默认请求头的方式. 第一种方式 直接在创建的HttpClient对象的 ...

  8. [转]Linux系统结构

    Linux系统一般有4个主要部分:内核.shell.文件系统.应用程序. 内核.shell和文件系统一起形成了基本的操作系统结构,它们使得用户可以运行程序.管理文件并使用系统. 1.linux内核 内 ...

  9. 09 Scrapy框架在爬虫中的使用

    一.简介 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架.它集成高性能异步下载,队列,分布式,解析,持久化等. Scrapy 是基于twisted框架开发而来,twisted是一个 ...

  10. 牛客练习赛38 E 出题人的数组 2018ccpc桂林A题 贪心

    https://ac.nowcoder.com/acm/contest/358/E 题意: 出题人有两个数组,A,B,请你把两个数组归并起来使得cost=∑i∗ci 最小,归并要求原数组的数的顺序在新 ...