侧边栏壁纸
博主头像
张种恩的技术小栈博主等级

行动起来,活在当下

  • 累计撰写 748 篇文章
  • 累计创建 65 个标签
  • 累计收到 39 条评论

目 录CONTENT

文章目录

使用CentOS 7搭建FastDFS分布式文件系统

zze
zze
2019-11-02 / 0 评论 / 0 点赞 / 555 阅读 / 5902 字

不定期更新相关视频,抖音点击左上角加号后扫一扫右方侧边栏二维码关注我~正在更新《Shell其实很简单》系列

下面内容是在已安装好 CentOS 7 的基础上进行。
后续使用到的资源可通过 https://pan.baidu.com/s/1JvdGzo3ePCeXUHYB6GmYbA 下载。
tracker 和 storage 的安装都使用同一个安装包:FastDFS_v5.05.tar.gz
对应 GitHub 地址: https://github.com/happyfish100/FastDFS

tracker 安装

 初次安装可只安装一台 tracker, 快速体验。

准备安装环境

FastDFS 是 C 语言开发,建议在 Linux 上运行,本教程使用 Centos7 作为安装环境。
安装 FastDFS 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,需要安装 gcc:

yum install gcc-c++

安装 libevent

 FastDFS 依赖 libevent 库,需要安装:

 yum -y install libevent

安装 libfastcommon

libfastcommon 是 FastDFS 官方提供的, libfastcommon 包含了 FastDFS 运行所需要的一些基础库。
libfastcommonV1.0.7.tar.gz 拷贝至 /usr/local/ 下,解压并编译安装,如下:

cd /usr/local
tar -zxf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install

注意: libfastcommon 安装好后会自动将库文件拷贝至 /usr/lib64 下, 由于 FastDFS 程序引用 usr/lib 目录所以需要将 /usr/lib64 下的库文件拷贝至 /usr/lib 下。

cp /usr/lib64/libfastcommon.so /usr/lib

安装 tracker

 将 FastDFS_v5.05.tar.gz 拷贝至 /usr/local/ 下,解压并编译安装,如下:

tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install

 安装成功将安装目录下的 conf 下的文件拷贝到 /etc/fdfs/ 下:

cp /usr/local/FastDFS/conf/* /etc/fdfs -p

配置 tracker

进入 /etc/fdfs 目录,编辑 tracker.conf 配置文件,测试时仅需注意修改如下几项:

# 启用配置
disabled=false
# 设置 tracker 的端口号
port=22122 
# 设置 tracker 的数据文件和日志目录(该目录必须已存在)
base_path=/home/fastdfs/trackerdata       

启动 tracker

执行下面命令启动 tracker:

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

检查 tracker 服务是否已启动成功:

[root@localhost fdfs]# netstat -antp | grep trackerd
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      1917/fdfs_trackerd

storage 安装

 初次安装可只安装一台 storage,快速体验。

storage 的前面安装步骤和 tracker 安装相同,所以先参考 tracker 安装在另一台及其执行下面步骤:

  • 安装 libevent;
  • 安装 libfastcommon;
  • 安装 storage(使用同一个安装包,所以同安装 tracker);

配置 storage

进入 /etc/fdfs 目录,编辑 storage.conf 配置文件,测试时仅需注意修改如下几项:

# 启用配置文件
disabled=false
# 组名,根据实际情况修改
group_name=group1
# 设置 storage 的端口号
port=23000        
# 设置 storage 的日志目录(需预先创建)
base_path=/home/fastdfs/log
# 存储路径个数,需要和 store_path 个数匹配
store_path_count=1                      
# 存储路径(需预先创建)
store_path0=/home/fastdfs/storagedata
# tracker 服务器的 IP 地址和端口号
tracker_server=192.168.146.136:22122              

启动 storage

执行下面命令启动 storage:

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

检查 storage 服务是否已启动成功:

[root@localhost fdfs]# netstat -antp | grep storage
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      1991/fdfs_storaged  
tcp        0      0 192.168.146.137:54564   192.168.146.136:22122   ESTABLISHED 1991/fdfs_storaged 

如果启动一直是阻塞状态可以关闭一下防火墙试试:systemctl stop firewalld

测试上传文件

 FastDFS 安装成功可通过 /usr/bin/fdfs_test 程序来测试上传、下载等操作。
 修改 /etc/fdfs/client.conf 中如下项:

base_path=/home/fastdfs
tracker_server=192.168.146.134:22122
tracker_server=192.168.146.136:22122

tracker_server 根据自己部署虚拟机的情况配置 。

使用格式:

/usr/bin/fdfs_test <客户端配置文件地址> upload <上传文件>

这里我将家目录下的 3.png 上传到 FastDFS 中:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload ~/3.png

打印日志如下:

This is FastDFS client test program v5.05

Copyright (C) 2008, Happy Fish / YuQing

FastDFS 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.csource.org/ 
for more detail.

[2019-10-31 14:29:05] DEBUG - base_path=/home/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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: 0

tracker_query_storage_store_list_without_group: 
	server 1. group_name=, ip_addr=192.168.146.133, port=23000

group_name=group2, ip_addr=192.168.146.133, port=23000
storage_upload_by_filename
group_name=group2, remote_filename=M00/00/00/wKiShV26fzGAbaF7AAA6wXXtNr0202.png
source ip address: 192.168.146.133
file timestamp=2019-10-31 14:29:05
file size=15041
file crc32=1978480317
example file url: http://192.168.146.133/group2/M00/00/00/wKiShV26fzGAbaF7AAA6wXXtNr0202.png
storage_upload_slave_by_filename
group_name=group2, remote_filename=M00/00/00/wKiShV26fzGAbaF7AAA6wXXtNr0202_big.png
source ip address: 192.168.146.133
file timestamp=2019-10-31 14:29:05
file size=15041
file crc32=1978480317
example file url: http://192.168.146.133/group2/M00/00/00/wKiShV26fzGAbaF7AAA6wXXtNr0202_big.png

在上述日志中, http://192.168.146.133/group2/M00/00/00/wKiShV26fzGAbaF7AAA6wXXtNr0202_big.png 就是文件的下载路径,暂时还不能直接访问,要让它能够被访问需要提供 http 服务。

FastDFS整合Nginx

Waiting update....

0

评论区