FastDFS 环境搭建
发布于: 刚刚

1.FastDFS 环境搭建
1.1 环境准备
使用的系统软件
编译环境
CentOS7
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
复制代码
磁盘目录
安装 libfastcommon
git clone https://github.com/happyfish100/libfastcommon.git --depth 1cd libfastcommon/#编译安装./make.sh && ./make.sh install复制代码
安装 FastDFS
cd ../ #返回上一级目录git clone https://github.com/happyfish100/fastdfs.git --depth 1cd fastdfs/./make.sh && ./make.sh install #编译安装#供nginx访问使用cp /usr/local/soft/fastdfs/conf/http.conf /etc/fdfs/ cp /usr/local/soft/fastdfs/conf/mime.types /etc/fdfs/ 复制代码
安装 fastdfs-nginx-module
cd ../ #返回上一级目录git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1cp /usr/local/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs复制代码
安装 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/soft/fastdfs-nginx-module/src/ make && make install #编译安装复制代码
1.2 单机部署
服务器 ip: 192.168.3.13
# /etc/hosts192.168.3.13 fastdfs.com复制代码
tracker 配置
mkdir -p /data/fastdfs
vim /etc/fdfs/tracker.conf#需要修改的内容如下port=22122 # tracker服务器端口(默认22122,一般不修改)base_path=/data/fastdfs # 存储日志和数据的根目录复制代码
storage 配置
vim /etc/fdfs/storage.conf#需要修改的内容如下port=23000 # storage服务端口(默认23000,一般不修改)base_path=/data/fastdfs # 数据和日志文件存储根目录store_path0=/data/fastdfs # 第一个存储目录tracker_server=fastdfs.com:22122 # tracker服务器IP和端口http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)复制代码
启动服务
# 关闭防火墙systemctl stop firewalld.service# 永久关闭防火墙systemctl disable firewalld.service
#启动tracker/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf#启动storage/usr/bin/fdfs_storaged /etc/fdfs/storage.conf# 重启storage/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart复制代码
client 测试
vim /etc/fdfs/client.conf#需要修改的内容如下base_path=/data/fastdfstracker_server=fastdfs.com:22122 #tracker服务器IP和端口#保存后测试,返回ID表示成功 如:group1/M00/00/00/wKgDDWDtRu6AMPhBARBlpcz7xUs146.jpg# 上传文件fdfs_upload_file /etc/fdfs/client.conf /usr/local/soft/fox.jpg# 删除文件fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgDCmD1LHaADXrMAAW3ED-O1WQ106.jpg复制代码
配置 nginx 访问(client)
vim /etc/fdfs/mod_fastdfs.conf#需要修改的内容如下tracker_server=fastdfs.com:22122 #tracker服务器IP和端口url_have_group_name=truestore_path0=/data/fastdfs
#配置nginx.configvim /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; }}
/usr/local/nginx/sbin/nginx #启动nginx/usr/local/nginx/sbin/nginx -s reload #重启nginx/usr/local/nginx/sbin/nginx -s stop #停止nginx复制代码
测试:http://fastdfs.com:8888/group1/M00/00/00/wKgDDWDtRu6AMPhBARBlpcz7xUs146.jpg
1.3 集群部署
服务器 ip 为 192.168.3.10,192.168.3.12,192.168.3.13
192.168.3.13 fastdfs.com192.168.3.12 fastdfs2.com192.168.3.10 fastdfs3.com复制代码
tracker 配置
vim /etc/fdfs/tracker.conf#需要修改的内容如下port=22122 # tracker服务器端口(默认22122,一般不修改)base_path=/data/fastdfs # 存储日志和数据的根目录复制代码
storage 配置
vim /etc/fdfs/storage.conf#需要修改的内容如下port=23000 # storage服务端口(默认23000,一般不修改)base_path=/data/fastdfs # 数据和日志文件存储根目录store_path0=/data/fastdfs # 第一个存储目录tracker_server=fastdfs.com:22122 # 服务器1tracker_server=fastdfs2.com:22122 # 服务器2tracker_server=fastdfs3.com:22122 # 服务器3http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)复制代码
client 测试
vim /etc/fdfs/client.conf#需要修改的内容如下base_path=/data/fastdfstracker_server=fastdfs.com:22122 # 服务器1tracker_server=fastdfs2.com:22122 # 服务器2tracker_server=fastdfs3.com:22122 # 服务器3#保存后测试,返回ID表示成功 如:group1/M00/00/00/wKgDDWDtRu6AMPhBARBlpcz7xUs146.jpgfdfs_upload_file /etc/fdfs/client.conf /usr/local/soft/fox.jpg复制代码
配置 nginx 访问
vim /etc/fdfs/mod_fastdfs.conf#需要修改的内容如下tracker_server=fastdfs.com:22122 # 服务器1tracker_server=fastdfs2.com:22122 # 服务器2tracker_server=fastdfs3.com:22122 # 服务器3url_have_group_name=truestore_path0=/data/fastdfs
#配置nginx.configvim /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; }}复制代码
检测集群
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf# 会显示会有几台服务器 有3台就会 显示 Storage 1-Storage 3的详细信息复制代码
划线
评论
复制
发布于: 刚刚阅读数: 3
版权声明: 本文为 InfoQ 作者【程序员Fox】的原创文章。
原文链接:【http://xie.infoq.cn/article/466a6f1546905491e22c73ea4】。文章转载请联系作者。
程序员Fox
关注
有道无术,术尚可求也,有术无道,止于术。 2019.03.12 加入
多年中间件,高并发经验,擅长高并发,中间件,微服务架构,源码控,喜欢分享技术











评论