FastDFS分布式文件系统的安装和部署(带文件资源)
文章目录
前言
FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。
看到了就想尝试安装下,顺便记录下学习过程。
一、前期准备
1. 1 安装资源
获取途径:官方Github 地址: https://github.com/happyfish100/fastdfs/wiki 也有详细的步骤
1.2. 使用的系统软件
名称 | 说明 |
---|---|
centos | 7.x |
libfastcommon | FastDFS分离出的一些公用函数包 |
FastDFS | FastDFS本体 |
fastdfs-nginx-module | FastDFS和nginx的关联模块 |
nginx | nginx1.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
yum -y install libevent
1.4. 上传所需文件(资源在底部)
我是上传在/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的文件资源目录
2.2 解压FastDFS本体安装包,老样子进入FastDFS路径,解压,进入,编译,安装
cd ../
tar -zxvf fastdfs-6.04.tar.gz
cd fastdfs-6.04
./make.sh
./make.sh install
还是能够看到我们的一个安装路径
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
之后,找猫画虎,步骤一样,只是要修改的多了一些
- 可以修改11行的 group_name
- 创建目录 mkdir /usr/local/fastdfs/storage -p
- 修改21和25为新建的目录 /usr/local/fastdfs/storage
- 配置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
三、 测试 - 配置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
解释下
- 为在/home上传了一个girl.png的测试图片
- Fdfs_test 是测试上传的命令 - 可以在/us r/bin 目录下 使用 l s fdfs* 查看
- 命令分4个部分 1. fdfs_test命令 2. client.conf文件路径。 3. upload命令. 4. 待上传文件路径
我们可以在 /usr/local/fastdfs/storage/data/00/00 里看到我们刚刚存入的文件,一份文件会有4个备份
为了演示为上传了两次,所以有8个文件
四、 避免踩坑
我是阿里云远程服务安装,单机安装tracker和storage 如果要部署分布式的话,只需要将上面tracker和storage的conf文件修改启动分别在两个机器上操作即可
如果上传失败,很有可能是阿里云安全组或者防火墙拦截,需要先开放对应端口
没有修改的话,tracker是22122 storage是23000
防火墙操作可见:Linux防火墙相关命令
五、资源文件
链接: https://pan.baidu.com/s/1pxMbf5GEPniggdHwjSx1xA 密码: labf