fastdfs单机部署安装

环境准备

使用的系统软件

名称

说明

centos

7.x

libfastcommon

FastDFS分离出的一些公用函数包

FastDFS

FastDFS本体

fastdfs-nginx-module

FastDFS和nginx的关联模块

nginx

nginx1.15.4

编译环境

yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y

磁盘目录

说明

位置

所有安装包

/mydata/fast-dfs

数据存储位置

/mydata/fast-dfs-data

日志目录

/mydata/fast-dfs-log

安装libfastcommon

在/mydata/fast-dfs目录下

[root@mac-shuidi-7-120 fast-dfs]# git clone https://gitee.com/ShiZan/libfastcommon.git  --depth 1
[root@mac-shuidi-7-120 fast-dfs]# cd libfastcommon/
[root@mac-shuidi-7-120 libfastcommon]#./make.sh && ./make.sh install #编译安装

安装FastDFS

在/mydata/fast-dfs目录下

[root@mac-shuidi-7-120 fast-dfs]# git clone https://gitee.com/ShiZan/fastdfs.git --depth 1
[root@mac-shuidi-7-120 fast-dfs]# cd fastdfs/
[root@mac-shuidi-7-120 fastdfs]# ./make.sh && ./make.sh install #编译安装
#配置文件准备
[root@mac-shuidi-7-120 fastdfs]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
[root@mac-shuidi-7-120 fastdfs]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
[root@mac-shuidi-7-120 fastdfs]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用
[root@mac-shuidi-7-120 fastdfs]# cp conf/http.conf /etc/fdfs/ #供nginx访问使用
[root@mac-shuidi-7-120 fastdfs]# cp conf/mime.types /etc/fdfs/ #供nginx访问使用

安装fastdfs-nginx-module

在/mydata/fast-dfs目录下

[root@mac-shuidi-7-120 fast-dfs]# git clone https://gitee.com/ShiZan/fastdfs-nginx-module.git --depth 1
[root@mac-shuidi-7-120 fastdfs-nginx-module]# cp src/mod_fastdfs.conf /etc/fdfs/

安装nginx-详见另一篇笔记,中间配置 #添加fastdfs-nginx-module模块

#添加fastdfs-nginx-module模块
./configure --add-module=/mydata/fast-dfs/fastdfs-nginx-module/src/ 

make && make install #编译安装

单机部署

tracker配置

#服务器ip为 192.168.54.120

vim /etc/fdfs/tracker.conf
#需要修改的内容如下
port=22122  # tracker服务器端口(默认22122,一般不修改)
base_path=/mydata/fast-dfs-data  # 存储日志和数据的根目录

storage配置

vim /etc/fdfs/storage.conf
#需要修改的内容如下
port=23000  # storage服务端口(默认23000,一般不修改)
base_path=/mydata/fast-dfs-data  # 数据和日志文件存储根目录
store_path0=/mydata/fast-dfs-data  # 第一个存储目录
tracker_server=192.168.54.120:22122  # tracker服务器IP和端口
http.server_port=8888  # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)

client测试

vim /etc/fdfs/client.conf
#需要修改的内容如下
base_path=/mydata/fast-dfs-data
tracker_server=192.168.54.120:22122    #tracker服务器IP和端口

关闭防火墙

#不关闭防火墙的话无法使用
systemctl stop firewalld.service #关闭
systemctl restart firewalld.service #重启

启动tracker

/etc/init.d/fdfs_trackerd start #启动tracker服务
/etc/init.d/fdfs_trackerd restart #重启动tracker服务
/etc/init.d/fdfs_trackerd stop #停止tracker服务
chkconfig fdfs_trackerd on #自启动tracker服务

启动storage

/etc/init.d/fdfs_storaged start #启动storage服务
/etc/init.d/fdfs_storaged restart #重动storage服务
/etc/init.d/fdfs_storaged stop #停止动storage服务
chkconfig fdfs_storaged on #自启动storage服务

测试上传

#保存后测试,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
[root@mac-shuidi-7-120 client]# fdfs_upload_file /etc/fdfs/client.conf /mydata/fast-dfs/nginx-1.15.4.tar.gz
group1/M00/00/00/wKg2eF_Il2SAP8jEAA-itrfn0m4.tar.gz

配置nginx访问

vim /etc/fdfs/mod_fastdfs.conf

#需要修改的内容如下
tracker_server=192.168.54.120:22122  #tracker服务器IP和端口
url_have_group_name=true
store_path0=/mydata/fast-dfs-data
#配置nginx.config
vim /mydata/fast-dfs/nginx-1.15.4/conf/nginx.conf 

#添加如下配置
server {
    listen       8888;    ## 该端口为storage.conf中的http.server_port相同
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
    }
}

启动nginx

/usr/local/nginx/sbin/nginx #启动nginx
/usr/local/nginx/sbin/nginx -s reload #重启nginx
/usr/local/nginx/sbin/nginx -s stop #停止nginx

测试访问刚才上传的文件

http://192.168.54.120:8888/group1/M00/00/00/wKg2eF_Il2SAP8jEAA-itrfn0m4.tar.gz

通过访问连接下载刚才上传的文件

权限控制

前面使用nginx支持http方式访问文件,但所有人都能直接访问这个文件服务器了,所以做一下权限控制。

FastDFS的权限控制是在服务端开启token验证,客户端根据文件名、当前unix时间戳、秘钥获取token,在地址中带上token参数即可通过http方式访问文件

# 服务端开启token验证
vim /etc/fdfs/http.conf  


# if use token to anti-steal
# default value is false (0)
# 设置为true表示开启token验证
http.anti_steal.check_token = true

# token TTL (time to live), seconds
# default value is 600
# 设置token失效的时间单位为秒(s)
http.anti_steal.token_ttl = 1800

# secret key to generate anti-steal token
# this parameter must be set when http.anti_steal.check_token set to true
# the length of the secret key should not exceed 128 bytes
# 密钥,跟客户端配置文件的fastdfs.http_secret_key保持一致
http.anti_steal.secret_key = FastDFS1234567890


# return the content of the file when check token fail
# default value is empty (no file sepecified)
# 如果token检查失败,返回的页面
http.anti_steal.token_check_fail = /home/yuqing/fastdfs/conf/anti-steal.jpg

参考文档连接 https://github.com/happyfish100/fastdfs/wiki

猜你喜欢

转载自blog.csdn.net/dyangel2013/article/details/119428170