FastDFS分布式文件系统搭建与配置
off999 2025-03-10 19:20 14 浏览 0 评论
介绍
FastDFS是一个开源的轻量级的高性能分布式文件系统。
其主要功能包括:文件存储、文件同步和文件访问(文件上传和文件下载),解决了大容量和负载均衡问题。FastDFS应满足基于照片分享网站、视频分享网站等文件的网站的服务要求,适合存储 4KB~500MB 之间的小文件,特别适合以文件为载体的在线服务,如图片、视频、文档等等。
FastDFS服务安装环境准备
FastDFS安装所需要的组件
名称 | 说明 |
OpenResty | 文件下载使用的服务 |
Libfatscommon | FastDFS分操作的一些公共函数包 |
FastDFS Nginx Module | FastDFS和Nginx的关联模块 |
FastDFS | FastDFS分布式文件系统 |
环境准备
服务 | IP地址 | 操作系统 |
Tracker Server 跟踪器 | 192.168.65.116 | CentOS Linux release 7.3 |
Storage Server1 存储节点 | 192.168.65.74 | CentOS Linux release 7.3 |
Storage Server1 存储节点 | 192.168.65.75 | CentOS Linux release 7.3 |
服务器上安装基础环境
yum install gcc gcc-c++ make pcre-devel zlib-devel openssl-devel
FastDFS服务安装路径规划
位置 | 说明 |
/dfs/soft | 所有安装包 |
/dfs/tracker | tracker服务器数据存储位置 |
/dfs/storage | storage服务器数据存储位置 |
[root@fdfs-116 ~]# mkdir /dfs/tracker -p #创建数据存储目录(tracker服务器)
[root@fdfs-74 ~]# mkdir /dfs/storage -p #创建数据存储目录(storage服务器)
[root@fdfs-75 ~]# mkdir /dfs/storage -p #创建数据存储目录(storage服务器)
安装libfastcommon(tracker和storage都安装)
cd /dfs/soft #切换到安装目录准备下载安装包
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
#如果服务器未联网,需要手动下载libfastcommon的安装包
#解压后进入libfastcommon目录,手动./make.sh && ./make.sh install
[root@fdfs-116 soft]# unzip libfastcommon-master.zip
[root@fdfs-116 soft]# cd libfastcommon-master
[root@fdfs-116 libfastcommon-master]# ./make.sh && ./make.sh install #编译安装
安装FastDFS(tracker和storage都安装)
cd /dfs/soft #切换到安装目录准备下载安装包
git clone https://github.com/happyfish100/fastdfs.git --depth 1
#如果服务器未联网需要手动下载FastDfs的安装包
#解压后进入fastdfs目录中,并手动./make.sh && ./make.sh install
[root@fdfs-116 soft]# tar -zxvf FastDFS_v5.08.tar.gz
[root@fdfs-116 soft]# cd FastDFS
[root@fdfs-116 FastDFS]# ./make.sh && ./make.sh install #编译安装
#配置文件准备
#tracker配置文件(tracker服务器使用)
[root@fdfs-116 FastDFS]# cp conf/tracker.conf /etc/fdfs/
#storage配置文件(storage服务器使用)
[root@fdfs-74 FastDFS]# cp conf/storage.conf /etc/fdfs/
[root@fdfs-75 FastDFS]# cp conf/storage.conf /etc/fdfs/
#客户端文件,测试用
[root@fdfs-116 FastDFS]# cp conf/client.conf /etc/fdfs/
#Fastdfs为fastdfs安装路径,这里是我的安装路径,请以自己的实际安装路径为准
[root@fdfs-116 FastDFS]# cp conf/http.conf conf/mime.types /etc/fdfs/
[root@fdfs-74 FastDFS]# cp conf/http.conf conf/mime.types /etc/fdfs/
[root@fdfs-75 FastDFS]# cp conf/http.conf conf/mime.types /etc/fdfs/
安装fastdfs-nginx-module(storage服务器安装)
cd /dfs/soft #切换到安装目录准备下载安装包
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
#如果服务器未连接互联网,需要手动下载fastdfs-nginx-module包
#此处的fastdfs-nginx-module包需要注意版本
# /dfs/soft/fastdfs-nginx-module为解压目录,这里是我的目录,实际请以自己的为准
[root@fdfs-74 soft]# unzip fastdfs-nginx-module.zip
[root@fdfs-74 soft]# cp /dfs/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@fdfs-75 soft]# unzip fastdfs-nginx-module.zip
[root@fdfs-75 soft]# cp /dfs/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
安装OpenResty(storage服务器安装)
cd /dfs/soft #切换到安装目录准备下载安装包
wget https://openresty.org/download/openresty-1.19.3.1.tar.gz #下载nginx压缩包
#如果服务器未连接互联网,需要手动下载nginx包,并解压
[root@fdfs-74 soft]# tar -zxf openresty-1.19.3.1.tar.gz
[root@fdfs-74 soft]# cd openresty-1.19.3.1
#添加fastdfs-nginx-module模块
#prefix指定一个自己的nginx目录
#add-module指定对应的fastdfs-nginx-module目录
#/dfs/soft/fastdfs-nginx-module这里是我自己的目录,实际请以自己的为准
[root@fdfs-74 openresty-1.19.3.1]# ./configure --add-module=/dfs/soft/fastdfs-nginx-module/src/
[root@fdfs-74 openresty-1.19.3.1]# gmake && gmake install #编译安装
#另一台Storage一样的命令
[root@fdfs-75 openresty-1.19.3.1]# ./configure --add-module=/dfs/soft/fastdfs-nginx-module/src/
[root@fdfs-75 openresty-1.19.3.1]# gmake && gmake install #编译安装
以上3~6步,已经把FastDFS的组件安装完成
FastDFS集群配置(Tracker配置)
tracker.conf 需要修改的内容如下
vim /etc/fdfs/tracker.conf
port=22122 # tracker服务器端口(默认22122,一般不修改)
base_path=/dfs/tracker # 存储tracker日志和数据的根目录
store_group=group1 #设置组名
http.server_port = 8080 #tracker HTTP服务端口
修改防火墙,开放22122端口和8080端口(iptables或firewall,此处以firewall为例)
# 开放端口
firewall-cmd --permanent --add-port=22122/tcp --add-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
# 查询端口是否开放
firewall-cmd --query-port=22122/tcp
firewall-cmd --query-port=8080/tcp
启动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服务
FastDFS集群配置(Storage配置)
storage.conf 需要修改的内容如下
vim /etc/fdfs/storage.conf
port=23000 # storage服务端口(默认23000,一般不修改)
base_path=/dfs/storage # 数据和日志文件存储根目录
store_path0=/dfs/storage # 第一个存储目录
tracker_server=192.168.65.116:22122 # tracker服务器1
#tracker_server=xxx.xxx.xx.xxx:22122 # tracker服务器2
http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和OpenResty中保持一致)
修改防火墙,开放23000端口和8888端口(iptables或firewall,此处以firewall为例)
# 开放端口
firewall-cmd --permanent --add-port=23000/tcp --add-port=8888/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
# 查询端口是否开放
firewall-cmd --query-port=23000/tcp
firewall-cmd --query-port=8888/tcp
启动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服务
配置Client测试(tracker服务器)
修改client.conf配置文件
vim /etc/fdfs/client.conf
#需要修改的内容如下
base_path=/dfs/tracker #tracker服务器
tracker_server=192.168.65.116:22122 # tracker服务器1
#tracker_server=xxx.xxx.xx.xxx:22122 # tracker服务器2
http.tracker_server_port=8080 #修改端口
测试上传文件
#保存后测试,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
[root@fdfs-116 soft]# fdfs_upload_file /etc/fdfs/client.conf ./7-1664778559.png
group1/M00/00/00/wKhBSmQAQ5KAKKUsAADlaTAPbnU808.png
配置OpenResty使可以通过HTTP访问(两台Storage都需要配置)
修改fastdfs-nginx-module
vim /etc/fdfs/mod_fastdfs.conf
#需要修改的内容如下
tracker_server=192.168.65.116:22122 # 服务器1
#tracker_server=xxx.xxx.xx.xx:22122 # 服务器2
url_have_group_name=true #访问路径中携带组名,如group1
store_path0=/dfs/storage #storage地址
修改Nginx配置
#配置nginx.config
vim /usr/local/openresty/nginx/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服务
#测试Nginx配置
[root@fdfs-74 openresty-1.19.3.1]# /usr/local/openresty/nginx/sbin/nginx -t
ngx_http_fastdfs_set pid=32222
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
/usr/local/openresty/nginx/sbin/nginx #启动nginx
/usr/local/openresty/nginx/sbin/nginx -s reload #重启nginx
/usr/local/openresty/nginx/sbin/nginx -s stop #停止nginx
测试一下看上传的文件能不能访问
group1/M00/00/00/wKhBSmQAQ5KAKKUsAADlaTAPbnU808.png
相关推荐
- Python钩子函数实现事件驱动系统(created钩子函数)
-
钩子函数(HookFunction)是现代软件开发中一个重要的设计模式,它允许开发者在特定事件发生时自动执行预定义的代码。在Python生态系统中,钩子函数广泛应用于框架开发、插件系统、事件处理和中...
- Python函数(python函数题库及答案)
-
定义和基本内容def函数名(传入参数):函数体return返回值注意:参数、返回值如果不需要,可以省略。函数必须先定义后使用。参数之间使用逗号进行分割,传入的时候,按照顺序传入...
- Python技能:Pathlib面向对象操作路径,比os.path更现代!
-
在Python编程中,文件和目录的操作是日常中不可或缺的一部分。虽然,这么久以来,钢铁老豆也还是习惯性地使用os、shutil模块的函数式API,这两个模块虽然功能强大,但在某些情况下还是显得笨重,不...
- 使用Python实现智能物流系统优化与路径规划
-
阅读文章前辛苦您点下“关注”,方便讨论和分享,为了回馈您的支持,我将每日更新优质内容。在现代物流系统中,优化运输路径和提高配送效率是至关重要的。本文将介绍如何使用Python实现智能物流系统的优化与路...
- Python if 语句的系统化学习路径(python里的if语句案例)
-
以下是针对Pythonif语句的系统化学习路径,从零基础到灵活应用分为4个阶段,包含具体练习项目和避坑指南:一、基础认知阶段(1-2天)目标:理解条件判断的逻辑本质核心语法结构if条件:...
- [Python] FastAPI基础:Path路径参数用法解析与实例
-
查询query参数(上一篇)路径path参数(本篇)请求体body参数(下一篇)请求头header参数本篇项目目录结构:1.路径参数路径参数是URL地址的一部分,是必填的。路径参...
- Python小案例55- os模块执行文件路径
-
在Python中,我们可以使用os模块来执行文件路径操作。os模块提供了许多函数,用于处理文件和目录路径。获取当前工作目录(CurrentWorkingDirectory,CWD):使用os....
- python:os.path - 常用路径操作模块
-
应该是所有程序都需要用到的路径操作,不废话,直接开始以下是常用总结,当你想做路径相关时,首先应该想到的是这个模块,并知道这个模块有哪些主要功能,获取、分割、拼接、判断、获取文件属性。1、路径获取2、路...
- 原来如此:Python居然有6种模块路径搜索方式
-
点赞、收藏、加关注,下次找我不迷路当我们使用import语句导入模块时,Python是怎么找到这些模块的呢?今天我就带大家深入了解Python的6种模块路径搜索方式。一、Python模块...
- 每天10分钟,python进阶(25)(python进阶视频)
-
首先明确学习目标,今天的目标是继续python中实例开发项目--飞机大战今天任务进行面向对象版的飞机大战开发--游戏代码整编目标:完善整串代码,提供完整游戏代码历时25天,首先要看成品,坚持才有收获i...
- python 打地鼠小游戏(打地鼠python程序设计说明)
-
给大家分享一段AI自动生成的代码(在这个游戏中,玩家需要在有限时间内打中尽可能多的出现在地图上的地鼠),由于我现在用的这个电脑没有安装sublime或pycharm等工具,所以还没有测试,有兴趣的朋友...
- python线程之十:线程 threading 最终总结
-
小伙伴们,到今天threading模块彻底讲完。现在全面总结threading模块1、threading模块有自己的方法详细点击【threading模块的方法】threading模块:较低级...
- Python信号处理实战:使用signal模块响应系统事件
-
信号是操作系统用来通知进程发生了某个事件的一种异步通信方式。在Python中,标准库的signal模块提供了处理这些系统信号的机制。信号通常由外部事件触发,例如用户按下Ctrl+C、子进程终止或系统资...
- Python多线程:让程序 “多线作战” 的秘密武器
-
一、什么是多线程?在日常生活中,我们可以一边听音乐一边浏览新闻,这就是“多任务处理”。在Python编程里,多线程同样允许程序同时执行多个任务,从而提升程序的执行效率和响应速度。不过,Python...
- 用python写游戏之200行代码写个数字华容道
-
今天来分析一个益智游戏,数字华容道。当初对这个游戏颇有印象还是在最强大脑节目上面,何猷君以几十秒就完成了这个游戏。前几天写2048的时候,又想起了这个游戏,想着来研究一下。游戏玩法用尽量少的步数,尽量...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python自定义函数 (53)
- python进度条 (67)
- python吧 (67)
- python字典遍历 (54)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python串口编程 (60)
- python读取文件夹下所有文件 (59)
- java调用python脚本 (56)
- python操作mysql数据库 (66)
- python字典增加键值对 (53)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python人脸识别 (54)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)