FastDFS搭建及整合Nginx实现文件上传
创始人
2024-03-22 14:20:09
0

一、准备环境

        FastDFS需要两个服务,一个tracker跟踪器,一个storage存储节点,tracker做调度配置,storage完成文件存储上传等功能。

        这里我们使用两台虚拟机服务器(centos 7)来部署,有条件的同学建议直接上云资源,区别就是云端服务器更安全,需要开放一下对应端口

二、下载所需资源包:

https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.42
https://codeload.github.com/happyfish100/fastdfs/tar.gz/V6.04
https://codeload.github.com/happyfish100/fastdfs-nginx-module/tar.gz/V1.22

下载好的资源上传到服务器,这里我放在/home/software/FastDFS里

 

 因为FastDFS是C语言开发,所以需要安装之前构建服务器的C环境,执行命令:

yum -y install gcc-c++

yum -y install libevent

 三、安装libfastcommon和fastdfs服务

1.解压

tar -zxvf libfastcommon-1.0.42.tar.gz

tar -zxvf fastdfs_.6.04.tar.gz

2.然后进到目录里,有一个make.sh文件,执行编译安装,两个都执行此步骤

./make.sh    编译

./make.sh install   安装

3.在安装fastdfs时,安装完成后会生成目录  /etc/fdfs ,里面会生成sample文件,我们需要将安装完成后的配置文件copy一份到目录下

cd /home/software/FastDFS/fastdfs-6.04/conf

cp * /etc/fdfs

        以上步骤,需要在两台服务器上同步执行,同样的安装和复制配置文件,区别是在1主机上,作为tracker服务,修改tracker的配置文件,2主机修改storage文件的配置文件

四、修改配置文件,启动服务

1.安装完成并copy配置文件到指定目录后,修改tracker的配置文件,这里port是tracker服务的端口,base_path是要存储数据的目录,可以自定义

# bind an address of this host
# empty for bind all addresses of this host
bind_addr=# the tracker server port
port=22122# connect timeout in seconds
# default value is 30
# Note: in the intranet network (LAN), 2 seconds is enough.
connect_timeout=10# network timeout in seconds for send and recv
# default value is 30
network_timeout=60# the base path to store data and log files
base_path=/usr/local/fastdfs/tracker

2.启动服务试一下,使用/etc/fdfs/下的tracker.conf配置文件启动

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

3.查一下服务状态

ps -ef | grep tracker

4.tracker启动后,我们配置一下storage

# the storage server port
port=23000# the base path to store data and log files
# NOTE: the binlog files maybe are large, make sure
#       the base path has enough disk space
base_path=/usr/local/fastdfs/storage# store_path#, based on 0, to configure the store paths to store file
# if store_path0 not exists, it's value is base_path (NOT recommended)
# the paths must be exist
#
# IMPORTANT NOTE:
#       the store paths' order is very important, don't mess up!!!
#       the base_path should be independent (different) of the store pathsstore_path0=/usr/local/fastdfs/storage
#store_path1=/home/yuqing/fastdfs2# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
#   the HOST can be hostname or ip address,
#   and the HOST can be dual IPs or hostnames seperated by comma,
#   the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
#   or two different types of inner (intranet) IPs.
#   for example: 192.168.2.100,122.244.141.46:22122
#   another eg.: 192.168.1.10,172.17.4.21:22122tracker_server=192.168.98.131:22122
# tracker_server=192.168.209.122:22122

port:服务端口,云服务器的同学需要开通一下23000的端口

base_path:storage的存储路径,自定义

store_path0:建议同base_path配置成相同路径

tracker_server:关联调度中心,也就是tracker的服务ip和端口

5.然后保存,启动一下

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

6.查一下服务状态

ps -ef | grep storage

 五、测试文件上传

        调度和执行器都完成后,我们来测试一下,fastdfs提供了一个客户端client,在服务器上可以直接使用client测试文件上传

1. 修改执行器storage上的 client.conf ,base_path 依旧自定义,tracker_server关联调度中心

base_path=/usr/local/fastdfs/client# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
#   the HOST can be hostname or ip address,
#   and the HOST can be dual IPs or hostnames seperated by comma,
#   the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
#   or two different types of inner (intranet) IPs.
#   for example: 192.168.2.100,122.244.141.46:22122
#   another eg.: 192.168.1.10,172.17.4.21:22122tracker_server=192.168.98.131:22122
# tracker_server=192.168.0.197:22122

2.我们进到 /usr/bin 下找到服务自带的fdfs_test应用程序,使用刚刚修改的client.conf 配置上传,这里我找了服务器上一个图片做测试

cd /usr/bin/
ls fdfs*
./fdfs_test /etc/fdfs/client.conf upload /home/2bpp63hc1.jpg

上传结果:

[root@hrs-node2 bin]# ./fdfs_test /etc/fdfs/client.conf upload /home/2bpp63hc1.jpg
This is FastDFS client test program v6.04Copyright (C) 2008, Happy Fish / YuQingFastDFS 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-12-05 18:17:08] DEBUG - base_path=/usr/local/fastdfs/client, connect_timeout=10, 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: 0tracker_query_storage_store_list_without_group: server 1. group_name=, ip_addr=192.168.98.133, port=23000group_name=imooc, ip_addr=192.168.98.133, port=23000
storage_upload_by_filename
group_name=imooc, remote_filename=M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599.jpg
source ip address: 192.168.98.133
file timestamp=2022-12-05 18:17:08
file size=255034
file crc32=2007384531
example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599.jpg
storage_upload_slave_by_filename
group_name=imooc, remote_filename=M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg
source ip address: 192.168.98.133
file timestamp=2022-12-05 18:17:08
file size=255034
file crc32=2007384531
example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg

访问地址:

example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg

Ng 待更新

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
【NI Multisim 14...   目录 序言 一、工具栏 🍊1.“标准”工具栏 🍊 2.视图工具...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
月入8000+的steam搬砖... 大家好,我是阿阳 今天要给大家介绍的是 steam 游戏搬砖项目,目前...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...