03-基于CentOS7搭建FastDFS
搭建fastdfs文件服务器
资源准备
- centos7
- libfastcommon 公共函数包
- FastDFS 本体
- fastdfs-nginx-module 与Nginx的关联模块
- nginx 1.15.4
官方文档
https://github.com/happyfish100/fastdfs/wiki
环境搭建
服务器IP规划
tracker |
storeage |
192.168.247.142 |
192.168.247.143 |
记得关闭防火墙~
tracker
# 创建部署包文件夹
mkdir /home/software/FASTDFS -p
将包上传到该文件夹下
安装依赖环境
yum install -y gcc gcc-c++
yum install -y libevent
解压包
# 安装libfastcommon tar -zxvf libfastcommon-1.0.42.tar.gz cd libfastcommon-1.0.42/ ./make.sh ./make.sh install # 安装FastDFS本体 cd ../ tar -zxvf fastdfs-6.04.tar.gz cd fastdfs-6.04/ ./make.sh ./make.sh install cd conf/ cp * /etc/fdfs/
storage 也搭建到上述的步骤
配置tracker服务
cd /etc/fdfs/ mkdir /usr/local/fastdfs/tracker -p vi tracker.conf
修改位置
# 基础路径
base_path=/usr/local/fastdfs/tracker
启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
查看tracker服务
ps -ef|grep tracker
启动ok
配置storage服务
cd /etc/fdfs/ mkdir /usr/local/fastdfs/storage -p vi storage.conf
修改位置
group_name=dance base_path=/usr/local/fastdfs/storage store_path0=/usr/local/fastdfs/storage # 默认有两个 注释一个修改一个 tracker_server=192.168.247.142:22122 # tracker_server=192.168.209.122:22122
启动
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
查看storage服务
ps -ef|grep storaged
启动ok
注意
需要先启动tracker, 然后启动storaged
测试
修改storage的client配置
cd /etc/fdfs/ mkdir /usr/local/fastdfs/client -p vi client.conf
修改配置
base_path=/usr/local/fastdfs/client # 修改一行注释一行 tracker_server=192.168.247.142:22122 # tracker_server=192.168.0.197:22122
测试
cd /usr/bin/ # 下载一张图片 wget https://img14.360buyimg.com/n0/jfs/t1/164012/18/30376/165351/63283bb6E1497b8c7/b15be526f4c39894.jpg
下载完成后可以看到存储的名字
移动到home下并重命名
mv b15be526f4c39894.jpg /home/test.jpg
测试上传图片
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/test.jpg
返回结果
This is FastDFS client test program v6.04 Copyright (C) 2008, Happy Fish / YuQing FastDFS may be copied only under the terms of the GNU General Public License V3, which may be found in the FastDFS source kit. Please visit the FastDFS Home Page http://www.fastken.com/ for more detail. [2022-09-20 05:50:22] DEBUG - base_path=/usr/local/fastdfs/client, connect_timeout=10, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 # 查询可用storage集合 tracker_query_storage_store_list_without_group: server 1. group_name=, ip_addr=192.168.247.143, port=23000 # 确定上传的storage group_name=dance, ip_addr=192.168.247.143, port=23000 storage_upload_by_filename # 上传组 和 远程文件名 group_name=dance, remote_filename=M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063.jpg # 源IP source ip address: 192.168.247.143 # 上传时间 file timestamp=2022-09-20 05:50:22 # 文件大小 file size=218181 file crc32=432168862 # 上传完成后会返回一个地址 并不能直接访问 需要配合Nginx example file url: http://192.168.247.143/dance/M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063.jpg storage_upload_slave_by_filename group_name=dance, remote_filename=M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063_big.jpg source ip address: 192.168.247.143 file timestamp=2022-09-20 05:50:22 file size=218181 file crc32=432168862 # 大图 example file url: http://192.168.247.143/dance/M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063_big.jpg
返回的URL还不能直接访问, 需要配合Nginx
分类:
FastDFS与OSS
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2020-10-04 CAS 原子操作
2020-10-04 简单理解Callable接口