关于fastdfs:centos7上单机安装fastdfs609

3次阅读

共计 9783 个字符,预计需要花费 25 分钟才能阅读完成。

1、背景

最近因为某些起因接触到了分布式存储,而像 阿里云的 OSS等都是须要付费的,那么有没有收费的呢?fastdfs就是一个收费的,此处记录一下如何搭建一个单机版的 fastdfs 环境。

2、fastdfs 的一些常识

2.1 fastdfs 的特点

  1. 分组存储,灵便简洁
  2. 对等构造,不存在单点
  3. 文件 ID 由 FastDFS 生成,作为文件拜访凭证。FastDFS 不须要传统的 name server
  4. 和风行的 web server 无缝连接,FastDFS 已提供 apache 和 nginx 扩大模块
  5. 大、中、小文件均能够很好反对,反对海量小文件存储
  6. 反对多块磁盘,反对单盘数据恢复
  7. 反对雷同文件内容只保留一份,节俭存储空间
  8. 存储服务器上能够保留文件附加属性
  9. 下载文件反对多线程形式,反对断点续传

2.2 架构图

2.2.1 client 介绍

客户端,即文件上传或下载的服务器,也就是咱们本人我的项目部署的服务器。

2.2.2 tracker-server 介绍

  1. tracker-server是跟踪服务器,次要起调度作用。负责管理所有 storage server的元数据信息,比方:storage ip、port、group等信息。每个 storage server 在启动的时候,会向 tracker server 连贯,上报本人的元数据信息,并与之放弃周期性的心跳。
  2. tracker-server之间通常不会互相通信

2.2.3 storage-server 介绍

  1. storage-server是存储服务器,次要用来存储各种文件。
  2. storage-server是以 Group 为单位,每个 Group 内能够有多台 storage server,同一个组内多个 storage server 为互为备份关系。
  3. 每个 Group 中的机器的存储倡议配置成一样大,否则以这个 Group 内容量最小的 storage 为准。
  4. storage server 被动向 tracker server 报告状态信息

2.3 fastdfs 须要装置的软件

依赖库 备注
libfatscommon 根底库 -fastdfs 分离出来的公共函数
libserverframe 根底库 - 网络框架库
FastDFS fastdfs 本地
fastdfs-nginx-module fastdfs 与 nginx 整合模块
nginx nginx

2.4 为什么须要 fastdfs-nginx-module

其实这个次要是因为,同一个 group 中存在多个 storage server,而多个 storage server 之间会存在文件同步,那么可能就会呈现 同步提早 问题。
比方:
咱们存在 2 台 storage server,别离是 storageA 和 storageB。

FastDFS 通过 Tracker 服务器,将文件放入到了 storageA 服务器存储。上传胜利后将 文件 ID 返回给客户端。此时 FastDFS 存储集群机制会将这个文件同步到同组存储 storageB,在文件还没有复制实现的状况下,客户端如果用这个文件 ID 在 storageB 上取文件, 就会呈现文件无法访问的谬误。而 fastdfs-nginx-module 能够重定向文件连贯到源服务器取文件, 防止客户端因为同步提早导致的文件无法访问谬误。

2.5 fastdfs 的一些材料

  1. fastdfs 源码地址 https://github.com/happyfish100/
  2. fastdfs 官方论坛 http://bbs.chinaunix.net/forum.php?mod=forumdisplay&fid=240&filter=typeid&typeid=424
  3. fastdfs 配置文件解释 http://bbs.chinaunix.net/thread-1941456-1-1.html
  4. fastdfs ppt 介绍 http://bbs.chinaunix.net/thread-1958475-1-1.html
  5. fastdfs faq http://bbs.chinaunix.net/thread-1920470-1-1.html

3、fastdfs 软件装置

3.1 前置条件

3.1.1 依赖库装置

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

3.1.2 fastdfs 源码所在目录

[[email protected] fastdfs]# pwd
/opt/fastdfs
[[email protected] fastdfs]# ls
fastdfs-6.09.tar.gz  fastdfs-nginx-module-1.23.tar.gz  libfastcommon-1.0.61.tar.gz  libserverframe-1.1.20.tar.gz  nginx-1.22.0.tar.gz
[[email protected] fastdfs]#

3.1.3 tracker 和 storage server

此处因为是 fastdfs 单机装置,因而 tracker server 和 storage server 装置到同一台机器上。

3.2 装置根底库 -libfatscommon

[[email protected] fastdfs]# cd /opt/fastdfs
[[email protected] fastdfs]# tar -zxvf libfastcommon-1.0.61.tar.gz
[[email protected] fastdfs]# cd libfastcommon-1.0.61
[[email protected] libfastcommon-1.0.61]# ./make.sh && ./make.sh install
[[email protected] fdfs]# ls /usr/lib64 | grep libfastcommon.so
libfastcommon.so
[[email protected] fdfs]# ls /usr/lib | grep libfastcommon.so
libfastcommon.so

3.3 装置根底库 -libserverframe

[[email protected] fastdfs]# cd /opt/fastdfs
[[email protected] fastdfs]# tar -zxvf libserverframe-1.1.20.tar.gz
[[email protected] fastdfs]# cd libserverframe-1.1.20
[[email protected] libfastcommon-1.0.61]# ./make.sh && ./make.sh install
[[email protected] fdfs]# ls /usr/lib | grep libserverframe.so
libserverframe.so
[[email protected] fdfs]# ls /usr/lib64 | grep libserverframe.so
libserverframe.so

3.4 装置 fastdfs

[[email protected] fastdfs]# cd /opt/fastdfs
[[email protected] fastdfs]# tar -zxvf fastdfs-6.09.tar.gz
[[email protected] fastdfs]# cd fastdfs-6.09
[[email protected] fastdfs-6.09]# ./make.sh && ./make.sh install

3.4.1 默认配置文件地位

[[email protected] fdfs]# cd /etc/fdfs/
[[email protected] fdfs]# ll
total 32
-rw-r--r--. 1 root root  1909 Oct  6 22:30 client.conf
-rw-r--r--. 1 root root 10246 Oct  6 22:30 storage.conf
-rw-r--r--. 1 root root   620 Oct  6 22:30 storage_ids.conf
-rw-r--r--. 1 root root  9138 Oct  6 22:30 tracker.conf
[[email protected] fdfs]#

3.4.2 默认命令工具

[[email protected] bin]# cd /usr/bin/ && ll | grep fdfs
-rwxr-xr-x.   1 root root    438264 Oct  6 22:30 fdfs_appender_test
-rwxr-xr-x.   1 root root    438048 Oct  6 22:30 fdfs_appender_test1
-rwxr-xr-x.   1 root root    429064 Oct  6 22:30 fdfs_append_file
-rwxr-xr-x.   1 root root    427736 Oct  6 22:30 fdfs_crc32
-rwxr-xr-x.   1 root root    429088 Oct  6 22:30 fdfs_delete_file
-rwxr-xr-x.   1 root root    429816 Oct  6 22:30 fdfs_download_file
-rwxr-xr-x.   1 root root    429848 Oct  6 22:30 fdfs_file_info
-rwxr-xr-x.   1 root root    440816 Oct  6 22:30 fdfs_monitor
-rwxr-xr-x.   1 root root    429344 Oct  6 22:30 fdfs_regenerate_filename
-rwxr-xr-x.   1 root root   1364800 Oct  6 22:30 fdfs_storaged
-rwxr-xr-x.   1 root root    444152 Oct  6 22:30 fdfs_test
-rwxr-xr-x.   1 root root    443336 Oct  6 22:30 fdfs_test1
-rwxr-xr-x.   1 root root    571736 Oct  6 22:30 fdfs_trackerd
-rwxr-xr-x.   1 root root    430048 Oct  6 22:30 fdfs_upload_appender
-rwxr-xr-x.   1 root root    431080 Oct  6 22:30 fdfs_upload_file
[[email protected] bin]#

3.4.3 fastdfs 默认启动脚本

[[email protected] init.d]# cd /opt/fastdfs/fastdfs-6.09/init.d/ && ll
total 8
-rwxrwxr-x. 1 root root 961 Sep 14 16:33 fdfs_storaged
-rwxrwxr-x. 1 root root 963 Sep 14 16:33 fdfs_trackerd
[[email protected] init.d]#

3.5 创立 fastdfs 数据根目录

mkdir -p /data/fastdfs
mkdir -p /data/fastdfs/tracker
mkdir -p /data/fastdfs/storage
mkdir -p /data/fastdfs/client

3.6 配置 tracker server

3.6.1 批改配置文件

vim /etc/fdfs/tracker.conf

# 配置文件是否不失效 false 为失效
disabled = false
# tracker 服务的端口
port = 22122
# tracker 存储数据和日志文件的根目录,根目录须要提前创立好
base_path = /data/fastdfs/tracker

3.6.2 防火墙放行端口

[[email protected] fdfs]# firewall-cmd --zone=public --add-port=22122/tcp --permanent
success
[[email protected] fdfs]# firewall-cmd --reload
success
[[email protected] fdfs]#

3.6.3 启动 tracker server

1、复制启动脚本

[[email protected] logs]# cp /opt/fastdfs/fastdfs-6.09/init.d/fdfs_trackerd /etc/init.d/

2、启动 tracker server

[[email protected] logs]# systemctl start fdfs_trackerd

3、检测 tracker server 是否启动

[[email protected] logs]# ps aux | grep fd
root      6686  0.0  0.3  79556  5900 ?        Sl   05:38   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root      6694  0.0  0.1 106180  1892 pts/0    R+   05:39   0:00 grep --color=auto fd

4、检测 22122 端口是否被监听

[[email protected] logs]# netstat -anp | grep 22122
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      6686/fdfs_trackerd

5、敞开 tracker server

[[email protected] logs]# /etc/init.d/fdfs_trackerd stop
Stopping fdfs_trackerd (via systemctl):            [OK]

3.7 配置 storage server

3.7.1 批改配置文件

/etc/fdfs/storage.conf

# 配置文件是否不失效,false 为失效
disabled=false 
# 指定此 storage server 所在 组
group_name=group1
# storage server 服务的端口
port=23000
# Storage 数据和日志目录地址,根目录必须提前创立好
base_path=/data/fastdfs/storage
# 文件存储门路的个数。store_path_count=1
# 配置 store_path_count 个门路,索引号从 0 开始。# 如果不配置 store_path0,那它就和 base_path 的门路一样。store_path0=/data/fastdfs/storage
# FastDFS 存储文件时,采纳了两级目录。这里配置寄存文件的目录个数。# tracker_server 的列表,会被动连贯 tracker_server
# 当存在多个 tracker server 时,每个 tracker server 写一行
tracker_server=192.168.121.137:22122
# 此存储服务器上 web 服务器的端口
http.server_port=8888

3.6.2 防火墙放行端口

[[email protected] fdfs]# firewall-cmd --zone=public --add-port=23000/tcp --permanent
success
[[email protected] fdfs]# firewall-cmd --zone=public --add-port=8888/tcp --permanent
success
[[email protected] fdfs]# firewall-cmd --reload
success
[[email protected] fdfs]#

3.6.3 启动 storage server

1、复制启动脚本

[[email protected] logs]# cp /opt/fastdfs/fastdfs-6.09/init.d/fdfs_storaged /etc/init.d/

2、启动 storage server

[[email protected] logs]# systemctl start fdfs_storaged

3、检测 storage server 是否启动

[[email protected] logs]# ps aux | grep fd
ps aux | grep fd
root      6723  0.0  0.6 145092  8980 ?        Sl   05:55   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root      6774  1.8  4.5 139948 68364 ?        Sl   06:12   0:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
root      6785  0.0  0.1 106180  1864 pts/0    R+   06:12   0:00 grep --color=auto fd

4、检测 23000 端口是否被监听

[[email protected] logs]# netstat -anp | grep 23000
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      6686/fdfs_trackerd

5、敞开 storage server

[[email protected] logs]# /etc/init.d/fdfs_storaged stop
Stopping fdfs_trackerd (via systemctl):            [OK]

3.8 查看 storage 和 tracker 是否在通信

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

3.9 文件上传测试

3.9.1 批改配置文件

vim /etc/fdfs/client.conf

# 存储 client 的日志文件
base_path = /data/fastdfs/client
# tracker 服务器的地址,多个写多行
tracker_server = 192.168.121.137:22122

3.9.2 上传文件

[[email protected] fastdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /opt/fastdfs/ 小红帽.jpg
group1/M00/00/00/wKh5iWM_VlCAUwAtAAAwWD4VeAg204.jpg
[[email protected] fastdfs]#
[[email protected] 00]# pwd
/data/fastdfs/storage/data/00/00
[[email protected] 00]# ls
wKh5iWM_VlCAUwAtAAAwWD4VeAg204.jpg
[[email protected] 00]#

文件 id 解释

3.10 storage 服务装置 nginx

[[email protected] fastdfs]# tar -zxf nginx-1.22.0.tar.gz
[[email protected] fastdfs]# cd nginx-1.22.0
[[email protected] fastdfs]# ./configure
[[email protected] fastdfs]# make
[[email protected] fastdfs]# make install
[[email protected] sbin]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.22.0

1、启动 nginx

[[email protected] sbin]# /usr/local/nginx/sbin/nginx
[[email protected] sbin]# ps aux | grep nginx
root      9460  0.0  0.1   4436  1528 ?        Ss   06:40   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    9461  0.0  0.1   4880  2260 ?        S    06:40   0:00 nginx: worker process
root      9463  0.0  0.1 106180  1884 pts/0    R+   06:40   0:00 grep --color=auto nginx

2、进行 nginx

[[email protected] sbin]# /usr/local/nginx/sbin/nginx -s stop
[[email protected] sbin]# ps aux | grep nginx
root      9466  0.0  0.1 106180  1860 pts/0    R+   06:41   0:00 grep --color=auto nginx

3.11 装置 fastdfs-nginx-module

3.11.1 装置

[[email protected] sbin]# /usr/local/nginx/sbin/nginx -s stop
[[email protected] sbin]# cd /opt/fastdfs/
[[email protected] sbin]# tar -zxf fastdfs-nginx-module-1.23.tar.gz
[[email protected] sbin]# cd /opt/fastdfs/nginx-1.22.0
[[email protected] sbin]# ./configure --add-module=../fastdfs-nginx-module-1.23/src/
[[email protected] sbin]# make && make install
[[email protected] nginx-1.22.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments: --add-module=../fastdfs-nginx-module-1.23/src/

3.11.2 复制 mod_fastdfs.conf 文件

复制 fastdfs-nginx-module-1.23 源码中的配置文件到 /etc/fdfs 目录

cp /opt/fastdfs/fastdfs-nginx-module-1.23/src/mod_fastdfs.conf /etc/fdfs/

3.11.3 编辑 mod_fastdfs.conf 文件

vim /etc/fdfs/mod_fastdfs.conf

# tracker server 的地址,多个写多行
tracker_server=192.168.121.137:22122
# storage server 的端口
storage_server_port=23000
# storage server 的组名
group_name=group1
# url 上是否有组名
url_have_group_name = true
# 和 storage.conf 配置文件中配置的一样
store_path_count=1
# 和 storage.conf 配置文件中配置的一样
store_path0=/data/fastdfs/storage

3.11.5 拷贝 mime.types 和 http.conf 文件

[[email protected] nginx-1.22.0]# cp /opt/fastdfs/fastdfs-6.09/conf/mime.types /etc/fdfs/
[[email protected] nginx-1.22.0]# cp /opt/fastdfs/fastdfs-6.09/conf/http.conf /etc/fdfs/

不拷贝的话,可能文件不能拜访

3.11.4 编辑 nginx 配置文件

vim /usr/local/nginx/conf/nginx.conf

server {
        listen       8888;
        server_name  192.168.121.137;
        location ~/group([0-9])/ {ngx_fastdfs_module;}
 }

此处的 8888/etc/fdfs/storage.conf中的 http.server_port=8888 值要统一。

3.11.5 启动 nginx

[[email protected] nginx-1.22.0]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=12113

3.11.6 拜访之前上传的文件

正文完
 0