FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件上传、文件下载等,解决了大容量存储和负载均衡的问题。
FastDFS 安装
- 安装 libfastcommon
# 下载
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.41.tar.gz
# 解压
tar -zxvf V1.0.41.tar.gz
# 编译 安装
cd libfastcommon-1.0.41/
sh make.sh
sh make.sh install
-
安装 fast dfs
# 下载 wget https://github.com/happyfish100/fastdfs/archive/V6.01.tar.gz # 解压编译安装 tar -zxvf V6.01.tar.gz cd fastdfs-6.01/ sh make.sh sh make.sh install
-
创建必要文件夹
mkdir -p /data/fastdfs/log mkdir -p /data/fastdfs/data mkdir -p /data/fastdfs/tracker mkdir -p /data/fastdfs/client
-
修改配置文件 配置文件在 /etc/fdfs 下
-
配置 tracker.conf
cd /etc/fdfs/ cp tracker.conf.sample tracker.conf 注意下 tracker.conf 文件的几个地方 ## 存储数据和日志文件的基本路径 base_path=/data/fastdfs/tracker ## Http服务端口 http.server_port=8080 ## 默认提供服务端口 port=22122 启动 跟踪器 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start 查看状态 netstat -apn|grep fdfs
-
配置 storage.conf 存储服务
cp storage.conf.sample storage.conf ## 关注如下几个配置 ## storage存储data和log的跟路径 base_path=/data/fastdfs/data ## 默认组名 group_name=group1 ## 默认端口,相同组的storage端口号必须一致 port=23000 ## 配置一个存储路径 store_path_count=1 store_path0=/data/fastdfs/data ## 配置跟踪器IP和端口 tracker_server=192.168.72.130:22122 ## 启动 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start ## 查看进程 netstat -apn|grep fdfs ----------------------- ## 查看启动日志 tail -f /data/fastdfs/data/logs/storaged.log
-
配置 client.conf
cp client.conf.sample client.conf ## 关注如下几个配置 ## client数据和日志目录 base_path=/data/fastdfs/client ## 配置跟踪器IP和端口 tracker_server=192.168.72.130:22122
测试 上传:
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/test.txt 会反馈一个 字符串 也就是路径 group1/M00/00/00/XXXXX-XXXX.txt
-
Nginx 安装 & 整合FastDFS
-
下载 nginx
wget http://nginx.org/download/nginx-1.16.1.tar.gz
-
下载 Fastdfs-nginx-moudle
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.
-
安装必要依赖
## pcre-devel 环境 yum install -y pcre pcre-devel ## zlib-devel 环境 yum install -y zlib zlib-devel ## openssl-devel 环境 yum install -y openssl openssl-devel
-
nginx 配置安装
在nginx 文件夹下,执行:
# =/root/fastdfs-nginx-module/src 填你的 Fastdfs-nginx-moudle文件位置 # 有必要的话 将 src 下config 文件中的local 去掉 ./configure --add-module=/root/fastdfs-nginx-module/src make && make install
-
查看是否安装成功
$ /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.16.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) configure arguments: --add-module=/root/fastdfs/fastdfs-nginx-module-1.21/src
测试访问
-
配置客户端
## 移动配置文件 [root@localhost src]# pwd /root/fastdfs-nginx-module/src [root@localhost src]# ls mod_fastdfs.conf [root@localhost src]# cp mod_fastdfs.conf /etc/fdfs/ [root@localhost fdfs]# pwd /etc/fdfs [root@localhost fdfs]# vim mod_fastdfs.conf ## 调整如下配置 ## 连接超时 connect_timeout=30 ## 配置跟踪器IP和端口 tracker_server=你的ip:22122 ## 路径包含group url_have_group_name = true # 必须和storage配置相同 store_path0=/data/fastdfs/data
-
完善dfs 配置
[root@localhost fdfs]# cd /root/fastdfs-5.11/conf/ [root@localhost conf]# cp anti-steal.jpg http.conf mime.types /etc/fdfs/
-
更改nginx 文件配置 (路径是 /usr/local/nginx/conf/ 一定不要搞错了)
server { listen 80; location ~/group([0-9])/M00 { root /data/fastdfs/data; ngx_fastdfs_module; } }
启动nginx 等
## 启动
/usr/local/nginx/sbin/nginx
## 停止
/usr/local/nginx/sbin/nginx -s stop
## 重启
/usr/local/nginx/sbin/nginx -s reload