记一次 Centos7.x 安装部署 FastDfs (单机版)

一、简介

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

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

存储节点存储文件,完成文件管理的所有功能:存储、同步和提供存取接口,FastDFS同时对文件的meta data进行管理。所谓文件的meta data就是文件的相关属性,以键值对(key value pair)方式表示,如:width=1024,其中的key为width,value为1024。文件meta data是文件属性列表,可以包含多个键值对。

FastDFS系统结构如下图所示:

跟踪器和存储节点都可以由一台多台服务器构成。跟踪器和存储节点中的服务器均可以随时增加或下线而不会影响线上服务。其中跟踪器中的所有服务器都是对等的,可以根据服务器的压力情况随时增加或减少。

为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式。存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷 的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起 到了冗余备份和负载均衡的作用。

在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。

当存储空间不足或即将耗尽时,可以动态添加卷。只需要增加一台或多台服务器,并将它们配置为一个新的卷,这样就扩大了存储系统的容量。

二、下载地址

1、基本安装包下载

https://gitee.com/fastdfs100/fastdfs

或:https://github.com/happyfish100/fastdfs/releases

2、依赖工具下载地址

https://gitee.com/fastdfs100

或:https://github.com/happyfish100

三、基础环境

1、系统说明

系统:CentOS-7-x86_64-Minimal-1708

下载地址: 

 http://archive.kernel.org/centos-vault/7.4.1708/isos/x86_64/   

2、安装虚拟机(我选择了单节点安装)

虚拟机配置:  2G内存  2核CPU

安装过程可参考:

https://blog.csdn.net/llwy1428/article/details/89328381

3、工具:xshell5

4、VMware 版本:VMware Workstation Pro15

四、安装部署

1、安装基础工具

[root@localhost ~]# yum install -y vim lrzsz gcc gcc-c++ make  pcre pcre-devel zlib zlib-devel openssl openssl-devel lrzsz wget net-tools tree zip unzip git

2、防火墙操作

# 停止防火服务
[root@localhost ~]# systemctl stop firewalld
# 查看防火墙的当前状态
[root@localhost ~]# systemctl status firewalld
# 开机禁止启动防火墙
[root@localhost ~]# systemctl disable firewalld

或者防火墙开开启指定端口

https://blog.csdn.net/llwy1428/article/details/99676257

可参考第 三 部分的 1、2、3 步

3、创建目录、下载安装文件

[root@loccalhost ~]# mkdir /opt/fdfs

[root@loccalhost ~]# cd /opt/fdfs

[root@loccalhost fdfs]# git clone https://gitee.com/fastdfs100/libfastcommon.git

[root@loccalhost fdfs]# git clone https://gitee.com/fastdfs100/fastdfs-client-java.git

[root@loccalhost fdfs]# git clone https://gitee.com/fastdfs100/fastdfs.git

4、切换目录、编译安装 libfastcommon

[root@loccalhost ~]# cd /opt/fdfs/libfastcommon/

[root@loccalhost libfastcommon]# ./make.sh

[root@loccalhost libfastcommon]# ./make.sh install

查看

[root@loccalhost ~]# ls /usr/lib64/libfastcommon.so

将/usr/lib64下的库文件拷贝至/usr/lib下

(注意:此时先查看 /usr/lib 下有无文件 libfastcommon.so ,如果已经有了,则不用拷贝)

[root@loccalhost ~]# cp /usr/lib64/libfastcommon.so /usr/lib

5、配置 trackered  编译、安装 fastdfs

切换目录

[root@loccalhost ~]# cd /opt/fdfs/fastdfs

查看目录

[root@localhost fastdfs]# ll
总用量 132
drwxr-xr-x 3 root root  4096 10月 24 21:20 client
drwxr-xr-x 2 root root   189 10月 24 21:20 common
drwxr-xr-x 2 root root   146 10月 24 21:20 conf
-rw-r--r-- 1 root root 35067 10月 24 21:20 COPYING-3_0.txt
drwxr-xr-x 4 root root    56 10月 24 21:20 docker
-rw-r--r-- 1 root root  3170 10月 24 21:20 fastdfs.spec
-rw-r--r-- 1 root root 37049 10月 24 21:20 HISTORY
drwxr-xr-x 2 root root    27 10月 24 21:20 images
drwxr-xr-x 2 root root    48 10月 24 21:20 init.d
-rw-r--r-- 1 root root  8344 10月 24 21:20 INSTALL
-rwxr-xr-x 1 root root  5517 10月 24 21:20 make.sh
drwxr-xr-x 2 root root   320 10月 24 21:20 php_client
-rw-r--r-- 1 root root  2448 10月 24 21:20 README.md
-rw-r--r-- 1 root root  1700 10月 24 21:20 README_zh.md
-rwxr-xr-x 1 root root  1768 10月 24 21:20 restart.sh
-rwxr-xr-x 1 root root   763 10月 24 21:20 setup.sh
-rwxr-xr-x 1 root root  1680 10月 24 21:20 stop.sh
drwxr-xr-x 4 root root  4096 10月 24 21:20 storage
drwxr-xr-x 2 root root   317 10月 24 21:20 test
drwxr-xr-x 2 root root  4096 10月 24 21:20 tracker

[root@loccalhost fastdfs]# ./make.sh && ./make.sh install

配置

把 /opt/fdfs/fastdfs/conf 下的文件拷贝到 /etc/fdfs/ 下

[root@loccalhost ~]# cp /opt/fdfs/fastdfs/conf/* /etc/fdfs/

切换目录

[root@loccalhost ~]# cd /etc/fdfs/

查看目录

[root@localhost fdfs]# ll
总用量 124
-rw-r--r-- 1 root root 23981 10月 24 22:08 anti-steal.jpg
-rw-r--r-- 1 root root  1909 10月 24 22:08 client.conf
-rw-r--r-- 1 root root  1909 10月 24 22:06 client.conf.sample
-rw-r--r-- 1 root root   965 10月 24 22:08 http.conf
-rw-r--r-- 1 root root 31172 10月 24 22:08 mime.types
-rw-r--r-- 1 root root 10246 10月 24 22:08 storage.conf
-rw-r--r-- 1 root root 10246 10月 24 22:06 storage.conf.sample
-rw-r--r-- 1 root root   620 10月 24 22:08 storage_ids.conf
-rw-r--r-- 1 root root   620 10月 24 22:06 storage_ids.conf.sample
-rw-r--r-- 1 root root  9138 10月 24 22:08 tracker.conf
-rw-r--r-- 1 root root  9138 10月 24 22:06 tracker.conf.sample

创建目录

[root@loccalhost ~]# mkdir /home/fdfs_storage /home/fastdfs

编辑配置文件

[root@loccalhost ~]# vim /etc/fdfs/tracker.conf

disabled = false
port = 22122
base_path = /home/fastdfs
allow_hosts = *
http.server_port = 80

启动 tracker

[root@loccalhost ~]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

(其他:  重启 tracker  [root@loccalhost ~]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

停止 tracker  [root@loccalhost ~]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop    )

查看启动状态

[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      2617/fdfs_trackerd  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      875/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1305/master         
tcp6       0      0 :::22                   :::*                    LISTEN      875/sshd            
tcp6       0      0 ::1:25

6、配置 storage

[root@localhost ~]# vim /etc/fdfs/storage.conf

group_name = group1
client_bind = true
port = 23000
base_path = /home/fastdfs
store_path0 = /home/fdfs_storage
tracker_server = 192.168.11.11:22122
#tracker_server = *.*.*.*:22122
allow_hosts = *

说明:192.168.11.11 是我虚拟机的 IP

启动 storage

[root@localhost~]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start

(其他:  重启 storage   [root@localhost~]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

停止 storage   [root@localhost~]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start  )

7、查看启动状态

[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      2617/fdfs_trackerd  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      875/sshd            
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      2704/fdfs_storaged  
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1305/master         
tcp6       0      0 :::22                   :::*                    LISTEN      875/sshd            
tcp6       0      0 ::1:25 

8、查看存储目录

[root@localhost ~]# ls /home/fdfs_storage/data/
00  0A  14  1E  28  32  3C  46  50  5A  64  6E  78  82  8C  96  A0  AA  B4  BE  C8  D2  DC  E6  F0  FA
01  0B  15  1F  29  33  3D  47  51  5B  65  6F  79  83  8D  97  A1  AB  B5  BF  C9  D3  DD  E7  F1  FB
02  0C  16  20  2A  34  3E  48  52  5C  66  70  7A  84  8E  98  A2  AC  B6  C0  CA  D4  DE  E8  F2  FC
03  0D  17  21  2B  35  3F  49  53  5D  67  71  7B  85  8F  99  A3  AD  B7  C1  CB  D5  DF  E9  F3  FD
04  0E  18  22  2C  36  40  4A  54  5E  68  72  7C  86  90  9A  A4  AE  B8  C2  CC  D6  E0  EA  F4  FE
05  0F  19  23  2D  37  41  4B  55  5F  69  73  7D  87  91  9B  A5  AF  B9  C3  CD  D7  E1  EB  F5  FF
06  10  1A  24  2E  38  42  4C  56  60  6A  74  7E  88  92  9C  A6  B0  BA  C4  CE  D8  E2  EC  F6
07  11  1B  25  2F  39  43  4D  57  61  6B  75  7F  89  93  9D  A7  B1  BB  C5  CF  D9  E3  ED  F7
08  12  1C  26  30  3A  44  4E  58  62  6C  76  80  8A  94  9E  A8  B2  BC  C6  D0  DA  E4  EE  F8
09  13  1D  27  31  3B  45  4F  59  63  6D  77  81  8B  95  9F  A9  B3  BD  C7  D1  DB  E5  EF  F9

四、使用 FastDFS 自带工具测试

1、修改配置文件 client.conf

[root@localhost ~]# vim /etc/fdfs/client.conf

base_path = /home/fastdfs
tracker_server = 192.168.11.11:22122
#tracker_server = *.*.*.*:22122

说明:192.168.11.11 是我虚拟机的 IP

2、我在系统的 /tmp 下存放了一张图片 20201024223330.png、

用命令上传文件

[root@localhost ~]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/20201024223330.png

五、编译安装 Nginx

Nginx 下载地址:http://nginx.org/download/

1、切换目录

[root@localhost opt]# cd /opt

2、下载 nginx-1.19.3.tar.gz

[root@localhost opt]# wget http://nginx.org/download/nginx-1.19.3.tar.gz

3、解压缩

[root@localhost opt]# tar zxvf nginx-1.19.3.tar.gz

4、切换目录,下载 FastDfs Nginx 相关配置

[root@loccalhost ~]# cd /usr/local

[root@loccalhost local]# git clone https://gitee.com/fastdfs100/fastdfs-nginx-module.git

5、编译、安装 Nginx

切换目录

[root@loccalhost ~]# cd  /opt/nginx-1.19.3

[root@loccalhost nginx-1.19.3]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src/

[root@loccalhost nginx-1.19.3]# make && make install

6、把fastdfs-nginx-module安装目录中src目录下的mod_fastdfs.conf 拷贝到/etc/fdfs目录下

[root@loccalhost ~]# cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

7、编辑配置文件 mod_fastdfs.conf

[root@loccalhost ~]# vim /etc/fdfs/mod_fastdfs.conf

base_path=/home/fastdfs
tracker_server=192.168.11.11:22122
group_name=group1
store_path0=/home/fdfs_storage
url_have_group_name = true

8、编辑 Nginx 的配置文件 nginx.conf

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

worker_processes  1;
pid        /usr/local/nginx/logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    sendfile        on;    
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location /group1/M00/ {
		    alias /home/fdfs_storage/data/;
		    ngx_fastdfs_module;
	    }
    }
}

9、启动 Nginx 服务

[root@localhost ~]# /usr/local/nginx/sbin/nginx

( 其他Nginx操作参考

https://blog.csdn.net/llwy1428/article/details/85063944

https://blog.csdn.net/llwy1428/article/details/101013214  )

10、查看系统服务的启动状态

六、浏览器查看:

浏览器地址栏录入上文生成的地址即可看到上文通过命令上传的图片:

http://192.168.11.11/group1/M00/00/00/wKgLC1-UO6yAaO0LAAx1V2pCd9o583_big.png

至此,Centos7.x 安装部署  FastDfs (单机版)操作完毕!

猜你喜欢

转载自blog.csdn.net/llwy1428/article/details/109115770