FastDFS安装及配置


FastDFS 是一款开源的、分布式文件系统(Distributed File System), 由淘宝开发平台部资深架构师余庆开发。它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载、文件删除)等,解决了大容量存储和负载均衡的问题。

架构简介:

image.png


FastDFS

1、安装

1.1 libfastcommon 的安装

libfastcommon 为FastDFS 操作的基础库,FastDFS 没有使用标准的库,而是封装了一套和

FastDFS 相关的库。libfastcommon 的git 下载地址:https://github.com/happyfish100/libfastcommon安装FastDFS 前,需要先安装libfastcommon(libfastcommon-1.0.43.tar.gz)

1). 安装libfastcommon

#解压
sudo tar -xzvf libfastcommon-1.0.43.tar.gz
#进入解压后的目录
cd libfastcommon-1.0.43
#编译代码
sudo ./make.sh
#安装
sudo ./make.sh install

2). 动态库安装成功后的路径

安装成功后,默认会复制到 /usr/lib64 下:

cd /usr/lib64
ls
libfastcommon.so

3). 设置环境变量或者创建软连接

由于系统不会自动在/usr/lib64 找动态库,所以需要人为设置环境变量或者创建软链接

1) export LD_LIBRARY_PATH=/usr/lib64/:$LD_LIBRARY_PATH

2) sudo ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so(推荐)

ln: failed to create symbolic link '/usr/lib/libfastcommon.so': File exists(表示已经创建软链接)

1.2 FastDFS 的安装

源码下载:

https://code.google.com/archive/p/fastdfs/downloads

这里使用的是V6.06 版本:fastdfs-6.06.tar.gz

1). 安装

#解压
sudo tar -zxvf fastdfs-6.06.tar.gz
#进入解压后的目录
cd fastdfs-6.06
#编译代码
sudo ./make.sh
#安装
sudo ./make.sh install

2). 确认make没有出错后,执行安装,可执行的默认程序安装到 /usr/bin 中:

   image.png

3). 安装成功后,自动在 /etc/fdfs 中添加三个配置文件:

image.png

 

2、FastDFS的配置

先配置tracker,再添加一个storage,每添加添加一个storage,实际上是storage 连接tracker,tracker 必须存在,否则storage 无法加进来,client 主要用于测试上传、下载文件。

如果有足够多的机器或虚拟机(3 台或3 台以上),一台作为tracker、一台作为client、多台作为storage,当然必须保证这几台机器网络是可以ping 通。

如果嫌麻烦或者没有这么多机器,一台机器可以同时为tracker、storage、client。

配置文件在 /etc/fdfs:

ubuntu@VM-0-5-ubuntu:/etc/fdfs$ ls
client.conf         storage.conf         storage_ids.conf         tracker.conf
client.conf.sample  storage.conf.sample  storage_ids.conf.sample  tracker.conf.sample

 

配置之前,需要先建立一个目录用来存储文件信息 fastdfs 文件夹,其中包含client、storage、tracker三个文件夹。

   image.png

 

1)修改 tracker.conf

ubuntu@VM-0-5-ubuntu:/etc/fdfs$ sudo vi tracker.conf

更改内容
1. bind_addr
#我用的是腾讯云,这里ip 写的 172.26.0.7 (内网ip)

2. 更改
base_path = /home/ubuntu/fastdfs/tracker

2)修改storage.conf

ubuntu@VM-0-5-ubuntu:/etc/fdfs$ sudo vi storage.conf

1. bind_addr = ”内网地址“

2. base_path = /home/ubuntu/fastdfs/storage

3. 注释掉一个storage地址,根据实际需求选择
    store_path0 = /home/ubuntu/fastdfs/storage/fastdfs0
    #store_path1 = /home/yuqing/fastdfs2
4. tracker_server = “内网地址”:22122

3) 修改client.conf

ubuntu@VM-0-5-ubuntu:/etc/fdfs$ sudo vi client.conf

1. base_path = /home/ubuntu/fastdfs/client

2. tracker_server = 内网地址:22122

 

启动服务

1)启动tracker

先进入
    ubuntu@VM-0-5-ubuntu:~/cloudpan/fdfs/fastdfs-6.06$   根目录
再启动tracker
    sudo ./tracker/fdfs_trackerd /etc/fdfs/tracker.conf
接着
    ps -aux | grep fdfs   查看服务是否启动
ubuntu@VM-0-5-ubuntu:~/cloudpan/fdfs/fastdfs-6.06$ ps -aux|grep fdfs
root      5700  0.0  0.3 155312  5884 ?        Sl   20:45   0:00 ./tracker/fdfs_trackerd /etc/fdfs/tracker.conf
root      9525  0.0  0.1 150212  3748 ?        Sl   21:10   0:00 ./storage/fdfs_storaged /etc/fdfs/storage.conf
ubuntu   21928  0.0  0.0  13232  1032 pts/3    S+   22:18   0:00 grep --color=auto fdfs

2)启动storage

启动storage
sudo ./storage/fdfs_storaged /etc/fdfs/storage.conf
再按照上述方式查看进程ID

3) 拷贝fdfs_trackerd 和fdfs_storaged 到/usr/bin 目录

在文件目录下ubuntu@VM-0-5-ubuntu:~/cloudpan/fdfs/fastdfs-6.06$
#拷贝fdfs_trackerd    
sudo cp -rf ./tracker/fdfs_trackerd /usr/bin
#拷贝fdfs_storaged
sudo cp -rf ./storage/fdfs_storaged /usr/bin

4)测试FastDFS客户端状态

测试storage状态

image.png

进入以下文件目录 /usr/bin 
通过fdfs_monitor 测试storage 状态,正常状态必须是ACTIVE,否则无法上传、下载文件
ubuntu@VM-0-5-ubuntu:/usr/bin$ sudo ./fdfs_monitor /etc/fdfs/client.conf
然后出现一大片代码,
检查下面是否为ACTIVE,是则正常
ip_addr = “内网地址”  ACTIVE

5)上传、下载、删除 文件测试

上传 
milo@ubuntu:~/share$ fdfs_upload_file /etc/fdfs/client.conf 0voice.txt

下载
milo@ubuntu:~/share$ fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKg0g17U-fuAWE9mAAAALM0Lv-Q064.txt

删除
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKg0g17U-fuAWE9mAAAALM0Lv-Q064.txt

 

FastDFS 的Nginx 模块

1、Nginx 上部署FastDFS

注意:全部安装条件在确保之前的FastDFS 的tracker、storage 和client 可以正常使用。

模块包源码包本地下载路径:https://github.com/happyfish100/fastdfs-nginx-module/releases

1) 解压Nginx 的FastDFS 模块包:

sudo tar -xzvf fastdfs-nginx-module-1.22.tar.gz
cd fastdfs-nginx-module         / 会发现里面有个INSTALL 和src 目录,这个不需要make 而是需要重新编译一下storage 的Nginx 模块。

2) 查看fastdfs-nginx-module 模块src 路径:

ubuntu@VM-0-5-ubuntu:~/cloudpan/06_fastdfs_nginx_module/fastdfs-nginx-module-1.22/src$ pwd
/home/ubuntu/cloudpan/06_fastdfs_nginx_module/fastdfs-nginx-module-1.22/src

3) 安装和编译Nginx 并添加FastDFS 模块

#进入到nginx 源码目录
cd nginx-1.16.1/
sudo ./configure --add-module=/opt/dfs/fastdfs-nginx-module-1.22/src
其中/usr/local/src/fastdfs-nginx-module/src 是刚才解压的fastdfs_nginx_module 模块的绝对路径,就是在编译Nginx 时候,连同这个模块一起编译。

#编译时, 出现下面信息表示添加成功。
adding module in /home/milo/software/fastdfs/fastdfs-nginx-module-1.22/src/ 
+ ngx_http_fastdfs_module was configured

4) 给nginx 目录下的objs/Makefile 文件中增加头文件目录:

ALL_INCS = -I src/core \
                -I /usr/include/fastdfs \   #增加内容    
                -I /usr/include/fastcommon \   #增加内容
        -I src/event \
        -I src/event/modules \
        -I src/os/unix \
        -I objs \
        -I src/http \
        -I src/http/modules \

5) 重新编译及安装nginx

sudo make

sudo make install

2、fastdfs-nginx-module 的配置

1) fastdfs-nginx-module 配置文件

将fastdfs-nginx-module/src/mod_fastdfs.conf 拷贝到 /etc/fdfs/ 下:

2)建立软连接

3)配置nginx 

location /group1/M00 {
root /home/ubuntu/fastdfs/storage/fastdfs0/data;
ngx_fastdfs_module;
}

4)重启nginx

sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

5)测试环境

如果测试没有问题,那么Fastdfs就搭建成功了

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装配置 FastDFS 可以按照以下步骤进行操作: 1. 安装依赖库: ``` sudo apt-get update sudo apt-get install -y libevent-dev libevent-extra-2.1-6 libevent-openssl-2.1-6 libevent-pthreads-2.1-6 zlib1g-dev ``` 2. 下载 FastDFS: ``` wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz tar -zxvf V6.06.tar.gz cd fastdfs-6.06/ ``` 3. 编译和安装 FastDFS: ``` ./make.sh sudo ./make.sh install ``` 4. 配置 Tracker 服务器: - 复制 `tracker.conf.sample` 文件并重命名为 `tracker.conf`: ``` cp conf/tracker.conf.sample conf/tracker.conf ``` - 编辑 `tracker.conf` 文件,设置 `base_path` 参数为 FastDFS 存储数据的根目录: ``` vi conf/tracker.conf base_path=/your/path/to/fdfs/tracker/data ``` 5. 启动 Tracker 服务器: ``` sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf ``` 6. 配置 Storage 服务器: - 复制 `storage.conf.sample` 文件并重命名为 `storage.conf` : ``` cp conf/storage.conf.sample conf/storage.conf ``` - 编辑 `storage.conf` 文件,设置 `base_path` 参数为 FastDFS 存储数据的根目录,设置 `tracker_server` 参数为 Tracker 服务器的 IP 地址: ``` vi conf/storage.conf base_path=/your/path/to/fdfs/storage/data tracker_server=tracker_ip:tracker_port ``` 7. 启动 Storage 服务器: ``` sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf ``` 8. 配置客户端: - 复制 `client.conf.sample` 文件并重命名为 `client.conf`: ``` cp conf/client.conf.sample conf/client.conf ``` - 编辑 `client.conf` 文件,设置 `base_path` 参数为 FastDFS 存储数据的根目录,设置 `tracker_server` 参数为 Tracker 服务器的 IP 地址: ``` vi conf/client.conf base_path=/your/path/to/fdfs/data tracker_server=tracker_ip:tracker_port ``` 9. 测试 FastDFS 是否安装成功: ``` sudo /usr/bin/fdfs_test /etc/fdfs/client.conf upload /path/to/your/file.ext ``` 以上是基本的 FastDFS 安装配置步骤,根据实际情况进行调整。希望对你有所帮助!如果你还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值