阿里云部署FastDfs并配置外网访问

第一章 FastDFS简介

1.1、FastDFS的简介

FastDFS是一个开源的轻量级分布式文件系统,为互联网应用量身定做,简单、灵活、高效,采用C语言 开发,由阿里巴巴开发并开源。

FastDFS对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载、文件删除)等,解决了大容量文件存储的问题,特别适合以文件为载体的在线服务,如相册网站、文档网站、图片网站、视频网站等等。

FastDFS充分考虑了冗余备份、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

1.2、FastDFS的整体架构

FastDFS文件系统由两大部分构成,一个是客户端,一个是服务端。

客户端通常指我们的程序,比如我们的Java程序去连接FastDFS、操作FastDFS,那我们的Java程序就是一个客户端,FastDFS提供专有API访问,目前提供了C、Java和PHP几种编程语言的API,用来访问FastDFS文件系统。

服务端由两个部分构成:一个是跟踪器(tracker),一个是存储节点(storage)。

跟踪器(tracker)主要做调度工作,在内存中记录集群中存储节点storage的状态信息,是前端Client和后端存储节点storage的枢纽。因为相关信息全部在内存中,Tracker server的性能非常高,一个较大的集群(比如上百个group)中有3台就足够了。

存储节点(storage)用于存储文件,包括文件和文件属性(meta data)都保存到存储服务器磁盘上,完成文件管理的所有功能:文件存储、文件同步和提供文件访问等。

1.3、FastDFS的官方网址

官方网址:https://link.csdn.net/?target=https%3A%2F%2Fgithub.com%2Fhappyfish100%2Ffastdfs

第二章 FastDFS单实例部署

2.1、环境准备

虚拟机的版本:VMware-workstation-full-15.5.6-16341506.exe
系统镜像版本:阿里云服务器CentOS-7.30-x86_64-bin-DVD1.iso,全新安装,桌面版,可上网
连接工具版本:SecureCRTSecureFX_HH_x64_7.0.0.326.zip

2.1.1 开启阿里云防火墙配置规则

主要开启 80端口、22122端口、22123端口

2.2、安装依赖

[root@caochenlei ~]# yum install -y gcc gcc-c++ perl perl-devel openssl openssl-devel pcre pcre-devel zlib zlib-devel libevent libevent-devel

2.3、安装libfastcommon库

下载:

[root@caochenlei ~]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz

解压:

[root@caochenlei ~]# tar -zxvf V1.0.43.tar.gz

切换:

[root@caochenlei ~]# cd libfastcommon-1.0.43

编译:

[root@caochenlei libfastcommon-1.0.43]# ./make.sh

安装:

[root@caochenlei libfastcommon-1.0.43]# ./make.sh install
[root@caochenlei libfastcommon-1.0.43]# cd ~

2.4、安装FastDFS

下载:

[root@caochenlei ~]# wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz

解压:

[root@caochenlei ~]# tar -zxvf V6.06.tar.gz

切换:

[root@caochenlei ~]# cd fastdfs-6.06

编译:

[root@caochenlei fastdfs-6.06]# ./make.sh

安装:

[root@caochenlei fastdfs-6.06]# ./make.sh install

查看可执行文件:

[root@caochenlei fastdfs-6.06]# ll /usr/bin/fdfs*

在这里插入图片描述
查看配置文件:

[root@caochenlei fastdfs-6.06]# ll /etc/fdfs/

在这里插入图片描述
拷贝其它配置:

[root@caochenlei fastdfs-6.06]# cd conf

[root@caochenlei conf]# cp http.conf /etc/fdfs/
[root@caochenlei conf]# cp mime.types /etc/fdfs/

[root@caochenlei conf]# cd /etc/fdfs/

[root@caochenlei fdfs]# mv client.conf.sample client.conf
[root@caochenlei fdfs]# mv storage.conf.sample storage.conf
[root@caochenlei fdfs]# mv storage_ids.conf.sample storage_ids.conf
[root@caochenlei fdfs]# mv tracker.conf.sample tracker.conf

#3 2.5、配置FastDFS
配置 tracker :

修改tracker.conf的以下几项配置项:vi tracker.conf

#配置tracker存储数据的目录
base_path = /opt/fastdfs/tracker
创建相对应的文件夹:

[root@caochenlei fdfs]# mkdir -p /opt/fastdfs/tracker

配置 storage :

修改storage.conf的以下几项配置项:vi storage.conf

#storage存储数据目录
base_path = /opt/fastdfs/storage
#真正存放文件的目录
store_path0 = /opt/fastdfs/storage/files
#注册当前存储节点的跟踪器地址
tracker_server = 阿里云外网IP+22122

创建相对应的文件夹:

[root@caochenlei fdfs]# mkdir -p /opt/fastdfs/storage
[root@caochenlei fdfs]# mkdir -p /opt/fastdfs/storage/files

2.6、启动FastDFS
启动 tracker :

[root@caochenlei fdfs]# fdfs_trackerd /etc/fdfs/tracker.conf

启动 storage :

[root@caochenlei fdfs]# fdfs_storaged /etc/fdfs/storage.conf

查看启动情况:

[root@caochenlei fdfs]# ps -ef | grep fdfs

检查监控信息:

[root@caochenlei fdfs]# fdfs_monitor /etc/fdfs/storage.conf

查看数据目录:

[root@caochenlei fdfs]# ls /opt/fastdfs/storage/files/data/

2.7、重启FastDFS
重启 tracker :

[root@caochenlei fdfs]# fdfs_trackerd /etc/fdfs/tracker.conf restart
waiting for pid [32335] exit ...
starting ...

重启 storage :

[root@caochenlei fdfs]# fdfs_storaged /etc/fdfs/storage.conf restart
waiting for pid [32375] exit ...
starting ...

查看启动情况:

[root@caochenlei fdfs]# ps -ef | grep fdfs

在这里插入图片描述

2.8、测试FastDFS
配置 client :

修改client.conf的以下几项配置项:vi client.conf

#client存储数据目录

base_path = /opt/fastdfs/client
#注册当前存储节点的跟踪器地址

tracker_server = 阿里云外网IP:22122
创建相对应的文件夹:

[root@caochenlei fdfs]# mkdir -p /opt/fastdfs/client

创建 a.txt :

[root@caochenlei fdfs]# echo "Hello,FastDFS" > a.txt

上传 a.txt :

格式:fdfs_test /etc/fdfs/client.conf upload 文件路径
[root@caochenlei fdfs]# fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/a.txt

在这里插入图片描述
地址格式,举例如下图:
在这里插入图片描述
查看上传后的数据文件:

[root@caochenlei fdfs]# ll /opt/fastdfs/storage/files/data/00/00/
总用量 16

-rw-r--r--. 1 root root 14 9月   5 20:39 wKjvgF9ThuWAGUrIAAAADtHNnrs806_big.txt
-rw-r--r--. 1 root root 49 9月   5 20:39 wKjvgF9ThuWAGUrIAAAADtHNnrs806_big.txt-m
-rw-r--r--. 1 root root 14 9月   5 20:39 wKjvgF9ThuWAGUrIAAAADtHNnrs806.txt
-rw-r--r--. 1 root root 49 9月   5 20:39 wKjvgF9ThuWAGUrIAAAADtHNnrs806.txt-m

删除 a.txt :

格式:fdfs_delete_file /etc/fdfs/client.conf (group_name)/(remote_filename)
[root@caochenlei fdfs]# fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKjvgF9ThuWAGUrIAAAADtHNnrs806.txt
[root@caochenlei fdfs]# ll /opt/fastdfs/storage/files/data/00/00/
总用量 8
-rw-r--r--. 1 root root 14 9月   5 20:39 wKjvgF9ThuWAGUrIAAAADtHNnrs806_big.txt
-rw-r--r--. 1 root root 49 9月   5 20:39 wKjvgF9ThuWAGUrIAAAADtHNnrs806_big.txt-m

[root@caochenlei fdfs]# fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKjvgF9ThuWAGUrIAAAADtHNnrs806_big.txt
[root@caochenlei fdfs]# ll /opt/fastdfs/storage/files/data/00/00/
总用量 0

2.9、关闭FastDFS

关闭 tracker :

[root@caochenlei fdfs]# fdfs_trackerd /etc/fdfs/tracker.conf stop
waiting for pid [32441] exit ...
pid [32441] exit.

关闭 storage :

[root@caochenlei fdfs]# fdfs_storaged /etc/fdfs/storage.conf stop
waiting for pid [32453] exit ...
pid [32453] exit.

查看启动情况:

[root@caochenlei fdfs]# ps -ef | grep fdfs

注意问题:

没有搭建集群默认只有一个组group1
后缀名包含-m的为属性文件(meta)
在Linux中并没有磁盘一说,M00是虚拟的,它其实就是data目录
现在FastDFS已经安装完成,但现在外部还不能访问,有两大原因:一是防火墙未关闭、二是FastDFS默认不支持外部访问,想要访问需要继续往下学习

2.10、开启FastDFS外部访问

启动 tracker :

[root@caochenlei fdfs]# fdfs_trackerd /etc/fdfs/tracker.conf

启动 storage :

[root@caochenlei fdfs]# fdfs_storaged /etc/fdfs/storage.conf

关闭防火墙:

[root@caochenlei fdfs]# service iptables stop
[root@caochenlei fdfs]# chkconfig iptables off

回退根目录:

[root@caochenlei fdfs]# cd ~

Nginx依赖:

[root@caochenlei ~]# yum install -y gcc gcc-c++ make libtool wget pcre pcre-devel zlib zlib-devel openssl openssl-devel

Nginx下载:

[root@caochenlei ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz

Nginx解压:

[root@caochenlei ~]# tar -zxvf nginx-1.18.0.tar.gz

fastdfs-nginx-module下载:

[root@caochenlei ~]# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz

fastdfs-nginx-module解压:

[root@caochenlei ~]# tar -zxvf V1.22.tar.gz

#查看一下拓展模块所在路径,后边会用到这个路径

[root@caochenlei ~]# cd fastdfs-nginx-module-1.22/src/
[root@caochenlei src]# pwd
/root/fastdfs-nginx-module-1.22/src

#回退到根目录,方便接下来的一系列安装

[root@caochenlei src]# cd ~

Nginx及fastdfs-nginx-module安装:

注意:因为这个模块必须在Nginx的安装的过程中才能添加,所有我们需要重新安装一个Nginx,为了进行区分,我们把新安装的Nginx取名为nginx_fdfs

[root@caochenlei ~]# cd nginx-1.18.0
[root@caochenlei nginx-1.18.0]# ./configure --prefix=/usr/local/nginx_fdfs --add-module=/root/fastdfs-nginx-module-1.22/src
[root@caochenlei nginx-1.18.0]# make && make install

注意:安装完成后的路径为:/usr/local/nginx_fdfs

Nginx命令(此处了解,先不要敲呢,跳过这步):

普通启动服务:/usr/local/nginx_fdfs/sbin/nginx
配置文件启动:/usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf
暴力停止服务:/usr/local/nginx_fdfs/sbin/nginx -s stop
优雅停止服务:/usr/local/nginx_fdfs/sbin/nginx -s quit
检查配置文件:/usr/local/nginx_fdfs/sbin/nginx -t
重新加载配置:/usr/local/nginx_fdfs/sbin/nginx -s reload
查看相关进程:ps -ef | grep nginx
FastDFS的Nginx访问配置:

将 /root/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf 拷贝到 /etc/fdfs/ 目录下,这样才能正常启动Nginx

[root@caochenlei nginx-1.18.0]# cp /root/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/

修改mod_fastdfs.conf配置文件:

修改mod_fastdfs.conf的以下几项配置项:vi /etc/fdfs/mod_fastdfs.conf

#mod_fastdfs存储数据目录

base_path=/opt/fastdfs/nginx_mod
#注册当前存储节点的跟踪器地址

tracker_server=阿里云外网IP:22122
#路径中是否包含分组名称,我们为true

url_have_group_name=true
#真正存放文件的目录

store_path0=/opt/fastdfs/storage/files
创建相对应的文件夹:

[root@caochenlei nginx-1.18.0]# mkdir -p /opt/fastdfs/nginx_mod

配置Nginx的拓展模块请求转发:

[root@caochenlei nginx-1.18.0]# vi /usr/local/nginx_fdfs/conf/nginx.conf
1
location ~ /group[1-9]/M0[0-9] {	
     ngx_fastdfs_module;  
}

注意:ngx_fastdfs_module; #这个指令不是Nginx本身提供的,是扩展模块提供的,根据这个指令找到FastDFS提供的Nginx模块配置文件,然后找到Tracker,最终找到Stroager

启动带有Fastdfs模块的Nginx:

[root@caochenlei nginx-1.18.0]# /usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf
ngx_http_fastdfs_set pid=35500
[root@caochenlei fdfs]# fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/a.txt

在这里插入图片描述
在虚拟机外部浏览器访问上传的文件:

注意:直接输入example file url: http://121.199.2.55/group1/M00/00/00/eccCN2C0NHmAUtvBAAAADtHNnrs372_big.txt

在这里插入图片描述

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
阿里云安装fastdfs的步骤如下: 1. 准备安装所需的软件包,包括libfastcommon和fastdfs。可以通过下载源码并编译安装,或者使用已经编译好的二进制文件进行安装。\[1\] 2. 配置tracker.conf文件和storage.conf文件,这些文件包含了fastdfs配置信息,如存储路径、端口号等。可以根据实际需求进行配置。\[1\] 3. 启动fastdfs服务进行测试。可以使用命令行工具来测试fastdfs的功能,如上传文件、下载文件等。\[1\] 4. 安装fastdfs-nginx-module插件,该插件可以将fastdfs与nginx进行集成,提供更好的性能和扩展性。需要配置nginx的相关参数,并打开要使用的端口号。\[1\] 5. 安装成功后,需要创建软链接来确保系统能够正确找到fastdfs的库文件。可以使用以下命令创建软链接:\[2\] ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so 6. 最后,可以进行一些测试来验证fastdfs是否正常工作。可以上传和下载一些文件,检查是否能够正常访问。\[2\] 需要注意的是,以上步骤是基于阿里云服务器CentOS 7操作系统的安装过程。如果使用其他操作系统或版本,可能会有些许差异。\[3\] #### 引用[.reference_title] - *1* *2* [阿里云服务器Centos7安装fastdfs文件服务器](https://blog.csdn.net/luoluchen/article/details/88256341)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [阿里云部署FastDfs配置外网访问](https://blog.csdn.net/qq_42264638/article/details/117409282)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

从入门小白到小黑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值