赞
踩
FastDFS 是一个开源的分布式文件系统,特别适合大容量文件的存储和管理。它具有高性能、高可用性和易扩展的特点,常用于视频、图片、文档等文件的存储。以下是 FastDFS 的一些关键特点和组件:
以下是 FastDFS 的基本安装步骤:
FastDFS 被广泛应用于需要大规模存储和高并发访问的场景,如视频点播、直播平台、图片存储服务等。
(1)检查Linux上是否安装了 gcc、libevent、libevent-devel
yum list installed | grep gcc
yum list installed | grep libevent
yum list installed | grep libevent-devel
(2)如果没有安装,则需进行安装
yum install gcc libevent libevent-devel –y
安装 libfastcommon库 libfastcommon 库是 FastDFS 文件系统运行需要的公共 C 语言函数库
(3)将下载好的 libfastcommon ,fastdfs, fastdfs-nginx-module, nginx-1.18.0 等文件使用工具上传到Linux服务器中(例如/usr/local/src)
安装ibfastcommon
# 解压下载下来的tar.gz压缩包到当前目录
tar -zxvf libfastcommon-1.0.36.tar.gz
# 切换到解压后的libfastcommon目录
cd libfastcommon-1.0.36
# 执行make脚本进行编译
./make.sh
# 注意:make编译的时候如果报错,需解决错误后再次进行make,通常发生错误是由于Linux缺少某些依赖库导致,根据错误提示解决错误
#执行make install进行安装
./make.sh install
# 解压下载下来的tar.gz压缩包到当前目录
tar -zxvf fastdfs-5.11.tar.gz
# 切换到解压后FastDFS的目录
cd fastdfs-5.11
# 执行make脚本进行编译
./make.sh
# 执行make install进行安装
./make.sh install
#至此FastDFS安装完成,所有编译出来的文件存放在/usr/bin目录下, 所有配置文件存放在/etc/fdfs目录下
# 查看FastDFS相关的可执行程序
ll /usr/bin/fdfs*
[root@withlevi ~]# ll /usr/bin/fdfs*
-rwxr-xr-x 1 root root 455560 Dec 30 18:11 /usr/bin/fdfs_append_file
-rwxr-xr-x 1 root root 468952 Dec 30 18:11 /usr/bin/fdfs_appender_test
-rwxr-xr-x 1 root root 468784 Dec 30 18:11 /usr/bin/fdfs_appender_test1
-rwxr-xr-x 1 root root 452336 Dec 30 18:11 /usr/bin/fdfs_crc32
-rwxr-xr-x 1 root root 455584 Dec 30 18:11 /usr/bin/fdfs_delete_file
-rwxr-xr-x 1 root root 456568 Dec 30 18:11 /usr/bin/fdfs_download_file
-rwxr-xr-x 1 root root 456168 Dec 30 18:11 /usr/bin/fdfs_file_info
-rwxr-xr-x 1 root root 476728 Dec 30 18:11 /usr/bin/fdfs_monitor
-rwxr-xr-x 1 root root 455744 Dec 30 18:11 /usr/bin/fdfs_regenerate_filename
-rwxr-xr-x 1 root root 1629192 Dec 30 18:11 /usr/bin/fdfs_storaged
-rwxr-xr-x 1 root root 478496 Dec 30 18:11 /usr/bin/fdfs_test
-rwxr-xr-x 1 root root 477816 Dec 30 18:11 /usr/bin/fdfs_test1
-rwxr-xr-x 1 root root 662632 Dec 30 18:11 /usr/bin/fdfs_trackerd
-rwxr-xr-x 1 root root 456312 Dec 30 18:11 /usr/bin/fdfs_upload_appender
-rwxr-xr-x 1 root root 457688 Dec 30 18:11 /usr/bin/fdfs_upload_file
# /usr/bin是Linux的环境变量,可通过echo $PATH查看
[root@withlevi ~]# ll /etc/fdfs/
total 72
-rw-r--r-- 1 root root 1909 Dec 30 20:29 client.conf
-rw-r--r-- 1 root root 965 Dec 30 18:14 http.conf
-rw-r--r-- 1 root root 31172 Dec 30 18:14 mime.types
-rw-r--r-- 1 root root 3756 Dec 31 09:31 mod_fastdfs.conf
-rw-r--r-- 1 root root 10250 Dec 30 21:23 storage.conf
-rw-r--r-- 1 root root 620 Dec 30 18:09 storage_ids.conf
-rw-r--r-- 1 root root 9138 Dec 30 18:23 tracker.conf
# 另外注意需要把解压后的fastdfs-5.11/conf目录下的两个文件拷贝到/etc/fdfs/ ,否则后续会有很多奇怪问题不好解决
# cp http.conf /etc/fdfs/
# cp mime.types /etc/fdfs/
client.conf.sample:客户端的配置文件,测试用
storage.conf.sample:存储器的配置文件
tracker.conf.sample:跟踪器的配置文件
# 拷贝文件 tracker.conf.sample 并重命名为 tracker.conf
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
# 编辑 tracker.conf 配置文件
vim /etc/fdfs/tracker.conf
默认指向的FastDFS作者余庆的目录,因为在我们的机器上不存在,所有手动改一下
base_path=/opt/fastdfs/tracker #配置tracker存储数据的目录
bind an address of this host
empty for bind all addresses of this host
允许访问 tracker 服务器的 IP 地址,为空则表示不受限制
bind_addr =
the tracker server port
tracker 服务监听端口
port = 22122
connect timeout in seconds
default value is 30
Note: in the intranet network (LAN), 2 seconds is enough.
connect_timeout = 5
network timeout in seconds for send and recv
default value is 30
network_timeout = 60
the base path to store data and log files
tracker 服务器的运行数据和日志的存储父路径(需要提前创建好 切记切记)
base_path = /opt/fastdfs/tracker
max concurrent connections this server support
you should set this parameter larger, eg. 10240
default value is 256
max_connections = 1024
accept thread count
default value is 1 which is recommended
since V4.07
accept_threads = 1
拷贝文件 tracker.conf.sample 并重命名为 tracker.conf
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
编辑 tracker.conf 配置文件
vi /etc/fdfs/tracker.conf
storage存储数据目录 一定要手动创建!!!!
base_path=/opt/fastdfs/storage
真正存放文件的目录 一定要手动创建!!!!
store_path0=/opt/fastdfs/storage/files
注册当前存储节点的跟踪器地址 可以改为自己的服务器ip
tracker_server=192.168.235.128:22122
/opt/fastdfs/tracker
/opt/fastdfs/storage
/opt/fastdfs/storage/files
重启tracker
fdfs_trackerd /etc/fdfs/tracker.conf restart
重启storage
fdfs_storaged /etc/fdfs/storage.conf restart
关闭tracker执行命令
# 在任意目录下执行:
fdfs_trackerd /etc/fdfs/tracker.conf stop
关闭storage执行命令
#在任意目录下执行:
fdfs_storaged /etc/fdfs/storage.conf stop
或者kill关闭fastdfs,但不建议在线上使用 kill -9 强制关闭,因为可能会导致文件信息不同步问题。
FastDFS安装完成之后,可以使用fdfs_test脚本测试文件上传。
测试之前,需要修改client.conf配置文件,修改两个配置
cd /etc/fdfs/
vim client.conf
base_path=/opt/fastdfs/client
tracker_server=192.168.179.128:22122
# 在/opt/fastdfs/目录下创建client
mkdir -p /opt/fastdfs/client
准备需要上传的文件
[root@withlevi ~]# vim levi.txt
[root@withlevi ~]# fdfs_test /etc/fdfs/client.conf upload levi.txt
This is FastDFS client test program v6.07
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.fastken.com/
for more detail.
[2022-01-22 22:30:30] DEBUG - base_path=/opt/fastdfs/client, connect_timeout=5, 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=47.94.41.166, port=23000
group_name=group1, ip_addr=47.94.41.166, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/L14ppmHsFQaAeE8QAAAAMRNuHPQ770.txt
source ip address: 47.94.41.166
file timestamp=2022-01-22 22:30:30
file size=49
file crc32=325983476
example file url: http://47.94.41.166/group1/M00/00/00/L14ppmHsFQaAeE8QAAAAMRNuHPQ770.txt
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/L14ppmHsFQaAeE8QAAAAMRNuHPQ770_big.txt
source ip address: 47.94.41.166
file timestamp=2022-01-22 22:30:30
file size=49
file crc32=325983476
example file url: http://47.94.41.166/group1/M00/00/00/L14ppmHsFQaAeE8QAAAAMRNuHPQ770_big.txt
[root@withlevi ~]#
[root@withlevi ~]# cd /opt/fastdfs/storage/files/data/00/00
[root@withlevi 00]# ls
L14ppmHNt9iAB-isAEDjYcGKVKU004.JPG L14ppmHOZm-AB5qXAAAAMXE697s795.txt
L14ppmHNt9iAB-isAEDjYcGKVKU004.JPG-m L14ppmHOZm-AB5qXAAAAMXE697s795.txt-m
L14ppmHNt9iAB-isAEDjYcGKVKU004_big.JPG L14ppmHOmquAeSV2AFLl1Mib3u8860.MP4
L14ppmHNt9iAB-isAEDjYcGKVKU004_big.JPG-m L14ppmHOmquAeSV2AFLl1Mib3u8860.MP4-m
L14ppmHNukOAelKJCbKFnorDROQ719.MP4 L14ppmHOnCWAQeMDAoZgN58pFDA765.MP4
L14ppmHNukOAelKJCbKFnorDROQ719.MP4-m L14ppmHOnCWAQeMDAoZgN58pFDA765.MP4-m
L14ppmHNunqALviEAOLrkS2oe-A587.dmg L14ppmHcQ5qAIZ_qAAAADdzq_m0512.txt
L14ppmHNunqALviEAOLrkS2oe-A587.dmg-m L14ppmHcQ5qAIZ_qAAAADdzq_m0512.txt-m
L14ppmHNvIGAB2ssAAOeigwPYJ4967.zip L14ppmHcQ5qAIZ_qAAAADdzq_m0512_big.txt
L14ppmHNvIGAB2ssAAOeigwPYJ4967.zip-m L14ppmHcQ5qAIZ_qAAAADdzq_m0512_big.txt-m
L14ppmHOZgqAIVpGAEDjYcGKVKU626.JPG L14ppmHsFQaAeE8QAAAAMRNuHPQ770.txt
L14ppmHOZgqAIVpGAEDjYcGKVKU626.JPG-m L14ppmHsFQaAeE8QAAAAMRNuHPQ770.txt-m
L14ppmHOZgqAIVpGAEDjYcGKVKU626_big.JPG L14ppmHsFQaAeE8QAAAAMRNuHPQ770_big.txt
L14ppmHOZgqAIVpGAEDjYcGKVKU626_big.JPG-m L14ppmHsFQaAeE8QAAAAMRNuHPQ770_big.txt-m
FastDFS生成的文件目录结构及名称示例
# fdfs_delete_file /etc/fdfs/client.conf group1/要删除的文件路径
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/L14ppmHsFQaAeE8QAAAAMRNuHPQ770.txt-m
注意
● 没有搭建集群默认只有一个组group1
● 后缀名包含-m的为属性文件(meta)
● 在Linux中并没有磁盘一说,是虚拟的
概述 在文件上传的时候,上传成功的信息中有提示我们可以通过某个路径去访问上传的文件,但是我们直接访问这个路径,却不可以,那么已经上传到FastDFS文件系统中的文件,我们如何在浏览器中访问呢? FastDFS提供了一个Nginx扩展模块,利用该模块,我们可以通过Nginx访问已经上传到FastDFS上的文件
1. 将Fastdfs的Nginx扩展模块源代码上传到Linux上
2. 解压下载下来的fastdfs-nginx-module-master.zip 文件
unzip fastdfs-nginx-module-master.zi
因为这个模块必须在Nginx的安装的过程中才能添加,所有我们需要重新安装一个nginx,为了和原来已安装的Nginx进行区分,我们把新安装的Nginx取名为nginx_fdfs
1. 将Nginx的tar包上传到Linux上
2. 解压上传的Nginx文件
3. 切换至解压后的Nginx主目录,执行配置操作
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx_fdfs --add-module=/home/soft/fastdfs-nginx-module-master/src
• prefix是指定nginx安装路径
• add-module指定fastDFS的nginx模块的源代码路径
执行命令进行编译
make
执行命令进行安装
make install
以上安装Nginx的FastDFS扩展模块注意事项
我们知道,Nginx的安装需要Linux安装相关的几个库,否则编译会出现错误,这几个库分别是:
gcc编译器是否安装
检查是否安装:
yum list installed | grep gcc
执行安装:
yum install gcc -y
openssl库是否安装
检查是否安装:
yum list installed | grep openssl
执行安装:
yum install openssl openssl-devel -y
pcre库是否安装
检查是否安装:
yum list installed | grep pcre
执行安装:
yum install pcre pcre-devel -y
zlib库是否安装
检查是否安装:
yum list installed | grep zlib
执行安装:
yum install zlib zlib-devel -y
yum install gcc openssl openssl-devel pcre pcre-devel zlib zlib-devel –y
# 将/home/soft/fastdfs-nginx-module-master/src(自己实际存放Nginx扩展模块的目录)目录下的mod_fastdfs.conf文件拷贝到 /etc/fdfs/目录下,这样才能正常启动Nginx
cp /home/soft/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
修改mod_fastdfs.conf配置文件
base_path=/opt/fastdfs/nginx_mod
tracker_server=192.168.235.128:22122 #可以添加自己的服务器ip地址
url_have_group_name = true
store_path0=/opt/fastdfs/storage/files
在/opt/fastdfs/目录下创建nginx_mod目录
mkdir -p /opt/fastdfs/nginx_mod
配置Nginx的配置文件
拦截请求路径中包含 /group[1-9]/M0[0-9] 的请求,用 fastdfs的Nginx 模块进行转发
location ~ /group[1-9]/M0[0-9] {
ngx_fastdfs_module;
}
# ngx_fastdfs_module; #这个指令不是Nginx本身提供的,是扩展模块提供的,根据这个指令找到FastDFS提供的Nginx模块配置文件,然后找到Tracker,最终找到Stroager。
1. 测试带有Fastdfs模块的Nginx
[root@withlevi ~]# /usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf -t
ngx_http_fastdfs_set pid=14496
nginx: the configuration file /usr/local/nginx_fdfs/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx_fdfs/conf/nginx.conf test is successful
2. 启动带有Fastdfs模块的Nginx
/usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf
fdfs_trackerd /etc/fdfs/tracker.conf restart
fdfs_storaged /etc/fdfs/storage.conf restart
当遇到400错误,检查配置/etc/fdfs/mod_fastdfs.conf url_have_group_name=true 该配置表示访问路径中是否需要带有group1,改为true表示路径中需要有group1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。