FastDFS 的安装步骤

FastDFS 的安装步骤

安装FastDFS (standalone)

环境以及软件准备

ip: 192.168.13.33
path: /tmp/fastdfs

# 下载FastDFS安装包及Nginx模块插件
mkdir /tmp/fastdfs
cd /tmp/fastdfs
git clone https://github.com/happyfish100/libfastcommon
git clone https://github.com/happyfish100/fastdfs
git clone https://github.com/happyfish100/fastdfs-nginx-module
wget "http://nginx.org/download/nginx-1.13.0.tar.gz"

# 安装依赖包
yum groupinstall -y "Development Tools"
yum install -y libevent* pcre-devel zlib-devel openssl openssl-devel

FastDFS 安装

cd /tmp/fastdfs/libfastcommon
./make.sh
./make.sh install

cd /tmp/fastdfs/fastdfs
./make.sh
./make.sh install

# 配置 ip && paths.
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim /etc/fdfs/tracker.conf
bind_addr=192.168.13.33
base_path=/tmp/fastdfs

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim /etc/fdfs/storage.conf
base_path=/tmp/fastdfs
store_path0=/tmp/fastdfs
tracker_server=192.168.13.33:22122

Nginx 安装

cd /tmp/fastdfs
tar -xvf nginx-1.13.0.tar.gz
cd nginx-1.13.0
mkdir -vp /var/cache/nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp}

# ./configure
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--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/nginx/scgi_temp \
--add-module=/tmp/fastdfs/fastdfs-nginx-module/src

make && make install

# 配置 nginx.conf
vim /etc/nginx/nginx.conf
# nginx访问fds的权限问题
user  root;
server {
    listen      80;
    server_name 192.168.13.33;
    location / {
        root  html;
        index  index.html index.htm;
    }

    location /group1/M00/ {
            alias /tmp/fastdfs/data;
            ngx_fastdfs_module;
    }
    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root  html;
    }
}

# 添加nginx用户
useradd -M -s /sbin/nologin nginx

# 配置 
cp /tmp/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
cp /tmp/fastdfs/fastdfs/conf/http.conf /etc/fdfs/
cp /tmp/fastdfs/fastdfs/conf/mime.types /etc/fdfs/

vim /etc/fdfs/mod_fastdfs.conf
base_path=/tmp/fastdfs
tracker_server=192.168.13.33:22122
store_path0=/tmp/fastdfs
url_have_group_name=true

启动

# 启动 tracker
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

# 启动 storage
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

# 执行检查
netstat -ltnp | grep fdfs

在这里插入图片描述

# 启动 Nginx
/usr/sbin/nginx -c /etc/nginx/nginx.conf

测试


vim /etc/fdfs/client.conf
base_path=/tmp/fastdfs
tracker_server=192.168.13.33:22122
http.tracker_server_port=80

cd /tmp
vim hello-fdfs.txt
# 写入 hello fastdfs. hello nginx.

# 上传文件
/usr/local/bin/fdfs_test /etc/fdfs/storage.conf upload hello-fdfs.txt 
# 上传输出如下图:

在这里插入图片描述

# 在浏览器中使用 http://192.168.13.33/group1/M00/00/00/wKgNIVkdSxSAVIDAAAAAHM2M_Qg494_big.txt 进行访问
结果如下图:

至此,FastFDS (standalone)安装部署完毕

在这里插入图片描述

集群安装 (cluster)

以 192.168.13.32, 192.168.13.33 两台机器为集群机器
每台机器都需要按照上述的步骤进行安装

安装好单机版,并运行通过之后,停掉每台FastDFS上的相关进程,进行如下配置,两台机器配置一致

配置

vim /etc/fdfs/tracker.conf
use_storage_id = true

cp /tmp/fastdfs/fastdfs/conf/storage_ids.conf /etc/fdfs/
vim /etc/fdfs/storage_ids.conf
100001  group1  192.168.13.32
100002  group1  192.168.13.33

vim /etc/fdfs/storage.conf
tracker_server=192.168.13.32:22122
tracker_server=192.168.13.33:22122

vim /etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.13.32:22122
tracker_server=192.168.13.33:22122 

vim /etc/fdfs/client.conf
tracker_server=192.168.13.32:22122
tracker_server=192.168.13.33:22122

# 启动 
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
/usr/sbin/nginx -c /etc/nginx/nginx.conf

# 测试这里就不赘述了

Java 客户端使用

使用开源的客户端实现,和SpringBoot进行了整合

引用依赖包

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>com.github.tobato</groupId>
    <artifactId>fastdfs-client</artifactId>
    <version>1.25.3-RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

Java Client Config

@Configuration
@Import(FdfsClientConfig.class)
public class ComponetImport {

}

application.yml

fdfs:
  soTimeout: 1500
  connectTimeout: 600
  thumbImage:            #缩略图生成参数
    width: 150
    height: 150
  trackerList:            #TrackerList参数,支持多个
    - 192.168.13.32:22122
    - 192.168.13.33:22122
  pool:
    #从池中借出的对象的最大数目
    maxTotal: 100
    #获取连接时的最大等待毫秒数100
    maxWaitMillis: 1000
spring:
  jmx:
    enabled: false

API概述

  1. 文件上传、断点续传
  2. 文件下载(落地、返回字节流)
  3. 图片上传,并生成缩略图
  4. 文件删除
  5. 文件清空
  6. 文件 metadata 修改
  7. 文件信息查询
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GettingReal

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值