FastDFS的安装和配置(超详细)

1.编译环境

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

2.磁盘目录

说明位置
所有安装包/user/local/src
数据存储位置/home/dfs/
mkdir /home/dfs #创建数据存储目录
cd /usr/local/src #切换到安装目录准备下载安装包

3. 安装libfatscommon

git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install #编译安装

4.安装FastDFS

cd ../ #返回上一级目录
git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
./make.sh && ./make.sh install #编译安装
#配置文件准备
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用
cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用

5.安装fastdfs-nginx-module

cd ../ #返回上一级目录
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

6.安装nginx

wget http://nginx.org/download/nginx-1.15.4.tar.gz #下载nginx压缩包
tar -zxvf nginx-1.15.4.tar.gz #解压
cd nginx-1.15.4/ #添加fastdfs-nginx-module模块
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/
make && make install #编译安装

7.分布式部署

tracker配置
#服务器ip为 192.168.52.2,192.168.52.3,192.168.52.4
#建议用ftp下载下来这些文件 本地修改
vim /etc/fdfs/tracker.conf
#需要修改的内容如下
port=22122  # tracker服务器端口(默认22122,一般不修改)
base_path=/home/dfs  # 存储日志和数据的根目录
storage配置
vim /etc/fdfs/storage.conf
#需要修改的内容如下
port=23000  # storage服务端口(默认23000,一般不修改)
base_path=/home/dfs  # 数据和日志文件存储根目录
store_path0=/home/dfs  # 第一个存储目录
tracker_server=192.168.52.2:22122  # 服务器1
tracker_server=192.168.52.3:22122  # 服务器2
tracker_server=192.168.52.4:22122  # 服务器3
http.server_port=8888  # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
client测试
vim /etc/fdfs/client.conf
#需要修改的内容如下
base_path=/home/moe/dfs
tracker_server=192.168.52.2:22122  # 服务器1
tracker_server=192.168.52.3:22122  # 服务器2
tracker_server=192.168.52.4:22122  # 服务器3
#保存后测试,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz

8.配置nginx访问

vim /etc/fdfs/mod_fastdfs.conf
#需要修改的内容如下
tracker_server=192.168.52.2:22122  # 服务器1
tracker_server=192.168.52.3:22122  # 服务器2
tracker_server=192.168.52.4:22122  # 服务器3
url_have_group_name=true
store_path0=/home/dfs
#配置nginx.config
vim /usr/local/nginx/conf/nginx.conf
#添加如下配置
server {
    listen       8888;    ## 该端口为storage.conf中的http.server_port相同
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

9.启动

防火墙
#关闭防火墙或者开放相关端口 centos 7.x下
systemctl stop firewalld.service #关闭
systemctl restart firewalld.service #重启
tracker
/etc/init.d/fdfs_trackerd start #启动tracker服务
/etc/init.d/fdfs_trackerd restart #重启动tracker服务
/etc/init.d/fdfs_trackerd stop #停止tracker服务
chkconfig fdfs_trackerd on #自启动tracker服务
storage
/etc/init.d/fdfs_storaged start #启动storage服务
/etc/init.d/fdfs_storaged restart #重动storage服务
/etc/init.d/fdfs_storaged stop #停止动storage服务
chkconfig fdfs_storaged on #自启动storage服务
nginx
/usr/local/nginx/sbin/nginx #启动nginx
/usr/local/nginx/sbin/nginx -s reload #重启nginx
/usr/local/nginx/sbin/nginx -s stop #停止nginx
监测集群
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
# 会显示会有几台服务器 有3台就会 显示 Storage 1-Storage 3的详细信息

10.说明

配置文件

tracker_server #有几台服务器写几个
group_name #地址的名称的命名
bind_addr #服务器ip绑定
store_path_count #store_path(数字)有几个写几个
store_path(数字) #设置几个储存地址写几个 从0开始

可能遇到的问题

如果不是root 用户 你必须在除了cd的命令之外 全部加sudo
如果不是root 用户 编译和安装分开进行 先编译再安装
如果上传成功 但是nginx报错404 先检查mod_fastdfs.conf文件中的store_path0是否一致
如果nginx无法访问 先检查防火墙 和 mod_fastdfs.conf文件tracker_server是否一致
如果不是在/usr/local/src文件夹下安装 可能会编译出错

11.注意

上述ip地址可以写内网或者外网地址,切勿写127.0.0.1或者localhost
参考资料

[https://github.com/happyfish100/fastdfs](

  • 10
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
安装配置 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 安装配置步骤,根据实际情况进行调整。希望对你有所帮助!如果你还有其他问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值