目录

FastDFS安装

FastDFS是开源的高性能分布式文件系统(DFS)。主要功能包括:文件存储、文件同步和文件访问,以及高容量和负载均衡设计。

FastDFS:V6.12.2

libfastcommon:V1.0.75

libserverframe:V1.2.5

fastdfs-nginx-module:v1.24

Nginx:V1.28.0

apt-get install -y ca-certificates build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev wget git
git clone -b V1.0.75 https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon
./make.sh && ./make.sh install
git clone -b V1.2.5 https://github.com/happyfish100/libserverframe.git --depth 1
cd libserverframe
./make.sh && ./make.sh install
git clone -b V6.12.2 https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs
./make.sh && ./make.sh install

复制一份配置文件

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

创建 tracker 文件夹

mkdir -p /opt/fastdfs/tracker

修改配置文件

vi /etc/fdfs/tracker.conf
# base_path 目录地址(根目录必须存在,子目录会自动创建)
base_path=/opt/fastdfs/tracker

# 系统预留空间,当一个group中的任何storage的剩余空间小于定义的值,整个group就不能上传文件了
reserved_storage_space = 10G
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

停止 tracker 服务

fdfs_storaged /etc/fdfs/tracker.conf stop

重启 tracker 服务

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

查看是否有 tracker 进程

ps aux | grep tracker

一般 storage 服务会单独安装,这里为了方便安装在同一台。

如果 storage 单独安装的话,上面安装的步骤也要重新跑一遍,配置时只配置 storage,不配置 tracker

复制一份配置文件

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

创建storage存储目录

mkdir -p /opt/fastdfs/storage

修改配置

vi /etc/fdfs/storage.conf 
# 数据存储目录地址
base_path=/opt/fastdfs/storage

# store_path#,从 0 开始编号,用于配置存储文件的目录
# 如果 store_path0 不存在,则它的值会被设为 base_path(不推荐这样做)
# 这些路径必须事先存在。
#
# 重要提示:
#       store_path 的顺序非常重要,不要弄乱!
#       base_path 应该是独立的(与 store_path 不同)

store_path0 = /opt/fastdfs/storage/storage0
#store_path1 = /opt/fastdfs/storage/storage1

# 设置tracker_server
tracker_server=192.168.1.114:22122
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

首次启动会很慢,因为它在创建预设存储文件的目录

停止 storage 服务

fdfs_storaged /etc/fdfs/storage.conf stop

重启 storage 服务

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

查看是否有 storage 进程

ps aux | grep storage

利用自带的 client 进行测试

复制一份配置文件

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

创建client数据目录

mkdir -p /opt/fastdfs/client

编辑配置文件

vi /etc/fdfs/client.conf
# 存储日志文件的基本路径
base_path=/data/fastdfs/client

# tracker server的列表
tracker_server=192.168.1.114:22122

在终端中通过 shell 上传 opt 目录下的一张图片:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.jpg

如下图箭头所示,生成的图片地址为:http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg

即使我们现在知道图片的访问地址我们也访问不了,因为我们还没装 FastDFS 的 Nginx 模块

上传成功后,在 目标文件夹会生成4个文件夹,有 _big 的是备份文件,后缀名 -m 是文件的元数据

Nginx 添加模块需要重新编译,如果已有 ngxin 需要使用平滑升级的方式添加模块

下载源码

git clone -b V1.24 https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1

复制文件

cp fastdfs/conf/http.conf /etc/fdfs/http.conf
cp fastdfs/conf/mime.types /etc/fdfs/mime.types
cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf

编辑 Nginx 模块的配置文件

在已启动 Nginx 的情况下修改内容需要重启 Nginx

vi /etc/fdfs/mod_fastdfs.conf
#指定tracker服务器的IP和端口
tracker_server=192.168.1.114:22122

# store_path#,从 0 开始编号。如果 store_path0 不存在,则它的值默认为 base_path
# 这些路径必须事先存在
# 必须与 storage.conf 中的配置保持一致
store_path0 = /opt/fastdfs/storage/storage0
#store_path1 = /opt/fastdfs/storage/storage1

解压 Nginx

tar zxf nginx-1.28.0.tar.gz
cd nginx-1.28.0

编译(注意最后一行)

./configure \
--prefix=/usr/local/nginx \
--add-module=/root/fastdfs-nginx-module/src

修改 Nginx 配置

user root;	# 注意这一行,如果有权限问题,使用 root 用户去运行 nginx
server {
	listen 80;
	server_name localtion;
	client_max_body_size 30m;
    location ~/group[0-9]/M0[0-9] {
        ngx_fastdfs_module;
        add_header Access-Control-Allow-Origin *;
/usr/bin/fdfs_monitor /etc/fdfs/client.conf

FDFS_STORAGE_STATUS:INIT      :初始化,尚未得到同步已有数据的源服务器
FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有数据的源服务器
FDFS_STORAGE_STATUS:SYNCING   :同步中
FDFS_STORAGE_STATUS:DELETED   :已删除,该服务器从本组中摘除
FDFS_STORAGE_STATUS:OFFLINE   :离线
FDFS_STORAGE_STATUS:ONLINE    :在线,尚不能提供服务
FDFS_STORAGE_STATUS:ACTIVE    :在线,可以提供服务

FastDFS 配置文件详解(修订版1)

FastDFS 配置文件详解

相关内容