FastDFS分布式文件系统搭建与配置
off999 2025-03-10 19:20 17 浏览 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设计模式 第 13 章 中介者模式(Mediator Pattern)
-
在行为型模式中,中介者模式是解决“多对象间网状耦合”问题的核心模式。它就像“机场调度中心”——多个航班(对象)无需直接沟通起飞、降落时间,只需通过调度中心(中介者)协调,避免航班间的冲突与混乱...
- 1.3.1 python交互式模式的特点和用法
-
什么是Python交互模式Python交互模式,也叫Python交互式编程,是一种在Python解释器中运行的模式,它允许用户在解释器窗口中输入单个Python语句,并立即查看结果,而不需要编写整个程...
- Python设计模式 第 8 章 装饰器模式(Decorator Pattern)
-
在结构型模式中,装饰器模式是实现“动态功能扩展”的核心模式。它就像“手机壳与手机的关系”——手机(原始对象)具备通话、上网等基础功能,手机壳(装饰器)可在不改变手机本身的前提下,为其新增保护、...
- python设计模式 综合应用与实战指南
-
经过前面16章的学习,我们已系统掌握创建型模式(单例、工厂、建造者、原型)、结构型模式(适配器、桥接、组合、装饰器、外观、享元、代理)、行为型模式(责任链、命令、迭代器、中介者、观察者、状态、策略...
- Python入门学习教程:第 16 章 图形用户界面(GUI)编程
-
16.1什么是GUI编程?图形用户界面(GraphicalUserInterface,简称GUI)是指通过窗口、按钮、菜单、文本框等可视化元素与用户交互的界面。与命令行界面(CLI)相比,...
- Python 中 必须掌握的 20 个核心:str()
-
str()是Python中用于将对象转换为字符串表示的核心函数,它在字符串处理、输出格式化和对象序列化中扮演着关键角色。本文将全面解析str()函数的用法和特性。1.str()函数的基本用法1.1...
- Python偏函数实战:用functools.partial减少50%重复代码的技巧
-
你是不是经常遇到这样的场景:写代码时同一个函数调用了几十次,每次都要重复传递相同的参数?比如处理文件时总要用encoding='utf-8',调用API时固定传Content-Type...
- 第2节.变量和数据类型【第29课-输出总结】
-
同学们,关于输出的知识点讲解完成之后,把重点性的知识点做一个总结回顾。·首先对于输出这一章节讲解的比如有格式化符号,格式化符号这里需要同学们额外去多留意的是不是百分号s格式化输出字符串。当然课上也说百...
- AI最火语言python之json操作_python json.loads()
-
JSON(JavaScriptObjectNotation,JavaScript对象表示法)是一种开放标准的文件格式和数据交换格式,它易于人阅读和编写。JSON是一种常用的数据格式,比如对接各种第...
- python中必须掌握的20个核心函数—split()详解
-
split()是Python字符串对象的方法,用于将字符串按照指定的分隔符拆分成列表。它是文本处理中最常用的函数之一。一、split()的基本用法1.1基本语法str.split(sep=None,...
- 实用方法分享:pdf文件分割方法 横向A3分割成纵向A4
-
今天在街上打印店给儿子打印试卷时,我在想:能不能,把它分割成A4在家中打印,这样就不需要跑到街上的打印店打印卷子了。原来,老师发的作业,是电子稿,pdf文件,A3格式的试卷。可是家中的打印机只能打印A...
- 20道常考Python面试题大总结_20道常考python面试题大总结免费
-
20道常考Python面试题大总结关于Python的面试经验一般来说,面试官会根据求职者在简历中填写的技术及相关细节来出面试题。一位拿了大厂技术岗SpecialOffer的网友分享了他总结的面试经...
- Kotlin Data Classes 快速上手_kotlin快速入门
-
引言在日常开发中,我们常常需要创建一些只用来保存数据的类。问题是,这样的类往往需要写一堆模板化的方法:equals()、hashCode()、toString()……每次都重复,既枯燥又容易出错。//...
- python自动化RobotFramework中Collections字典关键字使用(五)
-
前言介绍安装好robotframework库后,跟之前文章介绍的BuiltIn库一样BuiltIn库使用介绍,在“python安装目录\Lib\site-packages\robot\librarie...
- Python中numpy数据分析库知识点总结
-
Python中numpy数据分析库知识点总结二、对已读取数据的处理②指定一个值,并对该值双边进行修改③指定两个值,并对第一个值的左侧和第二个值的右侧进行修改2.4数组的拼接和行列交换①竖直拼接(np...
你 发表评论:
欢迎- 一周热门
- 最近发表
-
- Python设计模式 第 13 章 中介者模式(Mediator Pattern)
- 1.3.1 python交互式模式的特点和用法
- Python设计模式 第 8 章 装饰器模式(Decorator Pattern)
- python设计模式 综合应用与实战指南
- Python入门学习教程:第 16 章 图形用户界面(GUI)编程
- Python 中 必须掌握的 20 个核心:str()
- Python偏函数实战:用functools.partial减少50%重复代码的技巧
- 第2节.变量和数据类型【第29课-输出总结】
- AI最火语言python之json操作_python json.loads()
- python中必须掌握的20个核心函数—split()详解
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python进度条 (67)
- python吧 (67)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python列表切片 (59)
- python面向对象编程 (60)
- python 代码加密 (65)
- python串口编程 (77)
- python封装 (57)
- python写入txt (66)
- python读取文件夹下所有文件 (59)
- python操作mysql数据库 (66)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)