FastDFS分布式文件系统的安装和部署(带文件资源)

FastDFS分布式文件系统的安装和部署(带文件资源)

前言

​ FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。

​ FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。

​ 看到了就想尝试安装下,顺便记录下学习过程。

一、前期准备

1. 1 安装资源

获取途径:官方Github 地址: https://github.com/happyfish100/fastdfs/wiki 也有详细的步骤

1.2. 使用的系统软件
名称说明
centos7.x
libfastcommonFastDFS分离出的一些公用函数包
FastDFSFastDFS本体
fastdfs-nginx-moduleFastDFS和nginx的关联模块
nginxnginx1.15.4
1.3. 安装所需软件编译环境

CentOS

yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y

image-20210225222324884

yum -y install libevent

image-20210225222520531

1.4. 上传所需文件(资源在底部)

image-20210225222632223

我是上传在/home/software

cd /home/software/FastDFS

二、安装流程

2.1 解压libfastcommon-1.0.42.tar.gz
tar -zxvf libfastcommon-1.0.42.tar.gz

cd libfastcommon-1.0.42.tar.gz

./make.sh

./make.sh install

安装完我们可以看见,一些FastDFS的文件资源目录

image-20210225223325952

2.2 解压FastDFS本体安装包,老样子进入FastDFS路径,解压,进入,编译,安装
cd ../

tar -zxvf fastdfs-6.04.tar.gz

cd fastdfs-6.04

./make.sh

./make.sh install

还是能够看到我们的一个安装路径

image-20210225223835943

2.3 配置tracker/storage/client conf文件
//进入conf目录后
cd /home/software/FastDFS/conf 

// 复制所有文件到 /etc/fdfs 里
cp * /etc/fdfs

// 创建目录,之后会用到 (-p 会递归创建)
mkdir /usr/local/fastdfs/tracker -p

// 修改tracker.conf 
cd /etc/fdfs
vim tracker.conf

tracker.conf 只需要修改第23行为 base_path=/usr/local/fastdfs/tracker就行了

# is this config file disabled
# false for enabled
# true for disabled
disabled = false

# 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 = 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
base_path=/usr/local/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

# work thread count
# work threads to deal network io
# default value is 4
# since V2.00
work_threads = 4

# the min network buff size
# default value 8KB
min_buff_size = 8KB

# the max network buff size
# default value 128KB
max_buff_size = 128KB

# the method for selecting group to upload files
# 0: round robin
# 1: specify group
# 2: load balance, select the max free space group to upload file
store_lookup = 2

# which group to upload file
# when store_lookup set to 1, must set store_group to the group name
store_group = group2

。。。。

启动服务

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

// 查看
p s -ef|grep tracker

image-20210225234526961

之后,找猫画虎,步骤一样,只是要修改的多了一些

  1. ​ 可以修改11行的 group_name
  2. ​ 创建目录 mkdir /usr/local/fastdfs/storage -p
  3. ​ 修改21和25为新建的目录 /usr/local/fastdfs/storage
  4. ​ 配置trackserver 为你的安装机器的ip
###########省略#############

group_name = group1

# bind an address of this host
# empty for bind all addresses of this host
bind_addr =

# if bind an address of this host when connect to other servers 
# (this storage server as a client)
# true for binding the address configured by the above parameter: "bind_addr"
# false for binding any address of this host
client_bind = true

# the storage server port
port = 23000

###########省略#############

base_path = /usr/local/fastdfs/storage

。。。

tracker_server=ip地址:22122
# tracker_server=192.168.0.197:22122

store_path0 = /usr/local/fastdfs/storage
#store_path1 = /home/yuqing/fastdfs2

###########省略#############

# the port of the web server on this storage server
http.server_port = 8888

启动服务

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

查看进程
ps -ef|grep storage

image-20210225235535627

三、 测试 - 配置client.conf(测试需要这个文件)

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

// 修改base_path=/usr/local/fastdfs/client (记得创建目录) 和 tracker_server=ip地址:22122  重复不再演示
vim client.conf 

之后,直接运行

cd /usr/bin

./fdfs_test /etc/fdfs/client.conf upload /home/girl.png

解释下

  1. 为在/home上传了一个girl.png的测试图片
  2. Fdfs_test 是测试上传的命令 - 可以在/us r/bin 目录下 使用 l s fdfs* 查看
  3. 命令分4个部分 1. fdfs_test命令 2. client.conf文件路径。 3. upload命令. 4. 待上传文件路径

image-20210226003657702

我们可以在 /usr/local/fastdfs/storage/data/00/00 里看到我们刚刚存入的文件,一份文件会有4个备份

为了演示为上传了两次,所以有8个文件

image-20210226003930245

四、 避免踩坑

​ 我是阿里云远程服务安装,单机安装tracker和storage 如果要部署分布式的话,只需要将上面tracker和storage的conf文件修改启动分别在两个机器上操作即可

​ 如果上传失败,很有可能是阿里云安全组或者防火墙拦截,需要先开放对应端口

​ 没有修改的话,tracker是22122 storage是23000

防火墙操作可见:Linux防火墙相关命令

image-20210226004649036

五、资源文件

链接: https://pan.baidu.com/s/1pxMbf5GEPniggdHwjSx1xA 密码: labf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值