FastDFS集群搭建
-
进入 https://github.com/happyfish100 网站下载FastDFS相关资源。
-
建议使用百度云链接
链接:https://pan.baidu.com/s/1ncHDDLV0t1uDti9h8aDqFg
提取码:db1n
-
准备三台服务器 :
CentOSA
CentOSB
CentOSC
上传所需的文件 -
安装依赖包libfastcommon
//[root@CentOSX ~] :代表所有服务器 同步执行
[root@CentOSX ~]# yum install -y gcc-c++
[root@CentOSX ~]# tar -zvxf V1.0.35.tar.gz
[root@CentOSX ~]# cd libfastcommon-1.0.35/
[root@CentOSX libfastcommon-1.0.35]# ./make.sh
[root@CentOSX libfastcommon-1.0.35]# ./make.sh install
- 安装FastDFS
[root@CentOSX ~]# yum install -y perl-devel
[root@CentOSX ~]# tar -zvxf V5.10.tar.gz
[root@CentOSX ~]# cd fastdfs-5.10/
[root@CentOSX fastdfs-5.10]# ./make.sh
[root@CentOSX fastdfs-5.10]# ./make.sh install
当软件安装结束后,默认FastDFS启动所需的配置文件放置在/etc/fdfs目录下
[root@CentOSX ~]# yum install -y tree
[root@CentOSX ~]# tree /etc/fdfs/
/etc/fdfs/
├── client.conf.sample
├── storage.conf.sample
├── storage_ids.conf.sample
└── tracker.conf.sample
0 directories, 4 files
配置服务
- 创建fdfs运行所需的数据目录
[root@CentOSX fastdfs-5.10]# mkdir -p /data/fdfs/{tracker,storage/store01,storage/store02}
[root@CentOSX fastdfs-5.10]# tree /data/
/data/
└── fdfs
├── storage
│ ├── store01
│ └── store02
└── tracker
5 directories, 0 files
- 创建启动所需的配置文件
[root@CentOSX ~]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
[root@CentOSX ~]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
[root@CentOSX ~]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
- 配置Tracker Server
[root@CentOSX ~]# vi /etc/fdfs/tracker.conf
//修改如下配置
base_path=/data/fdfs/tracker
- 配置Storage Server
[root@CentOSX ~]# vi /etc/fdfs/storage.conf
//修改如下配置
base_path=/data/fdfs/storage
store_path_count=2
store_path0=/data/fdfs/storage/store01
store_path1=/data/fdfs/storage/store02
tracker_server=CentOSA:22122
tracker_server=CentOSB:22122
tracker_server=CentOSC:22122
- 修改Client端
vi /etc/fdfs/client.conf
//修改如下配置
base_path=/tmp
tracker_server=CentOSA:22122
tracker_server=CentOSB:22122
tracker_server=CentOSC:22122
[root@CentOSX ~]# /etc/init.d/fdfs_trackerd start
Starting FastDFS tracker server:
[root@CentOSX ~]# /etc/init.d/fdfs_storaged start
Starting FastDFS storage server:
[root@CentOSX ~]# ps -aux | grep fdfs
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 78950 0.0 0.1 144784 2040 ? Sl 21:06 0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 79000 13.0 3.2 83520 67144 ? Sl 21:06 0:06 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root 79324 0.0 0.0 103320 884 pts/0 S+ 21:07 0:00 grep fdfs
[root@CentOSX ~]#
FastDFS操作
- 上传文件
[root@CentOSX ~]# fdfs_upload_file /etc/fdfs/client.conf t017e61fd84afec6822.jpg
---------------返回结果--------------
group1/M01/00/00/wKi_g10jrkKAIcVjAABbKaBfuVk766.jpg
- 下载
[root@CentOSX ~]# fdfs_download_file /etc/fdfs/client.conf group1/M01/00/00/wKi_g10jrkKAIcVjAABbKaBfuVk766.jpg
Nginx集成FastDFS
Nginx配置安装
- 安装nginx
[root@CentOSX ~]# tar -zxf fastdfs-nginx-module.tar.gz
[root@CentOSX ~]# yum install -y pcre-devel
[root@CentOSX ~]# yum install -y openssl-devel
[root@CentOSX ~]# tar -zvxf nginx-1.11.1.tar.gz
[root@CentOSA nginx-1.11.1]# cd nginx-1.11.1
[root@CentOSX nginx-1.11.1]# ./configure --prefix=/usr/local/nginx-1.11.1/ --add-module=/root/fastdfs-nginx-module/src
[root@CentOSX nginx-1.11.1]# make
[root@CentOSX nginx-1.11.1]# make install
- 拷贝配置
[root@CentOSX ~]# cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@CentOSX ~]# cd fastdfs-5.10/conf/
[root@CentOSX conf]# cp http.conf mime.types anti-steal.jpg /etc/fdfs/
[root@CentOSX conf]# cd
- 配置nginx.conf
[root@CentOSX ~]# cd /usr/local/nginx-1.11.1/conf/
//修改如下配置
location ~ /group[0-9]+/M00 {
root /data/fdfs/storage/store01;
ngx_fastdfs_module;
}
location ~ /group[0-9]+/M01 {
root /data/fdfs/storage/store02;
ngx_fastdfs_module;
}
- 修改mod_fastdfs.conf
tracker_server=CentOSA:22122
tracker_server=CentOSB:22122
tracker_server=CentOSC:22122
url_have_group_name = true
store_path_count=2
store_path0=/data/fdfs/storage/store01
store_path1=/data/fdfs/storage/store02
- 启动nginx
[root@CentOSX ~]# cd /usr/local/nginx-1.11.1/
[root@CentOSX nginx-1.11.1]# ./sbin/nginx -t
ngx_http_fastdfs_set pid=116305
ngx_http_fastdfs_set pid=116305
nginx: the configuration file /usr/local/nginx-1.11.1//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.11.1//conf/nginx.conf test is successful
[root@CentOSX nginx-1.11.1]# ./sbin/nginx
- 访问测试
http://192.168.191.133/group1/M01/00/00/wKi_g10jrkKAIcVjAABbKaBfuVk766.jpg
集成FastDHT去重
- 安装BerkeleyDB 下载db-4.7.25.tar.gz
[root@CentOSX ~]# tar -zxf db-4.7.25.tar.gz
[root@CentOSX ~]# cd db-4.7.25
[root@CentOSX db-4.7.25]# cd build_unix/
[root@CentOSX build_unix]# ./../dist/configure
[root@CentOSX build_unix]# make
[root@CentOSX build_unix]# make install
- 安装FastDHT
[root@CentOSX ~]# tar zxf FastDHT_v2.01.tar.gz
[root@CentOSX ~]# cd FastDHT
[root@CentOSX FastDHT]# ./make.sh
[root@CentOSX FastDHT]# ./make.sh install
安装结束后会在/etc目录下产生fdht文件夹
- 修改fdhtd.conf
[root@CentOSX ~]# mkdir /data/fastdht
[root@CentOSX ~]# vi /etc/fdht/fdhtd.conf
base_path=/data/fastdht
- 修改fdht_servers.conf
[root@CentOSX ~]# vi /etc/fdht/fdht_servers.conf
group_count = 1
group0 = CentOSA:11411
group1 = CentOSB:11411
group2 = CentOSC:11411
- 修改fdht_client.conf配置文件
[root@CentOSX ~]# vi /etc/fdfs/storage.conf
//修改如下配置
check_file_duplicate=1
keep_alive=1
#include /etc/fdht/fdht_servers.conf
- 分别启动fdhtd服务、fastfs
[root@CentOSX usr]# /usr/local/bin/fdhtd /etc/fdht/fdhtd.conf restart
[root@CentOSX usr]# /etc/init.d/fdfs_trackerd restart
[root@CentOSX usr]# /etc/init.d/fdfs_storaged restart
- 上传测试文件
[root@CentOSA ~]# fdfs_upload_file /etc/fdfs/client.conf t017e61fd84afec6822.jpg
group1/M00/00/00/wKikgl0qC4KAErBTAAAixXWAIyY133.jpg
[root@CentOSA ~]# fdfs_upload_file /etc/fdfs/client.conf t017e61fd84afec6822.jpg
group1/M00/00/00/wKikgl0qDAqAa0XwAAAixWB5m1c851.jpg
可以看出系统产生了wKikgl0qC4KAErBTAAAixXWAIyY133.jpg的两个链接