centos 安装使用 fasdfs
简要
准备两台服务器:
Tracker Server:跟踪服务器,主要做调度工作
Storage Server:存储服务器,主要提供容量和备份服务
FASDFS 采用是卷存储策略,只要能扩展卷,你的存量就可以够大。
FASDFS 上传下载原理:
客户端上传将文件发送给 TRACKER SERVER ,Tracker 查询可用存储并读取文件信息(文件大小,文件元数据),Tracker 将文件发送给 Starage Server 存储,存储文件返回文件 ID 和路径,Tracker 将文件组路径信息地址返回给客户端。
客户端下载 直接使用文件地址信息去请求 Tracker 服务,Tracker 去查找文件返回给客户端
环境
yum install -y gcc gcc-c++
yum -y install libevent
安装
wget http://tar.matosiki.site/tar/libfastcommon-1.0.7.tar.gz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
tar -zxvf libfastcommon-1.0.7.tar.gz -C/usr/local
cd /usr/local/libfastcommon-1.0.7/
#编译
./make.sh
#安装
./make.sh install
cd /usr/lib64
ls | grep libfastcommon.so
cp libfastcommon.so /usr/lib
|
wget http://tar.matosiki.site/tar/fastdfs-5.05.tar.gz
1
2
3
4
5
6
7
8
9
10
11
|
cd /home/iki/download
tar -vxzf fastdfs-5.05.tar.gz -C /usr/local
cd /usr/local/fastdfs-5.05/
./make.sh && ./make.sh install
cp /usr/local/fastdfs-5.05/conf/* /etc/fdfs/
|
配置
配置 Tracker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
cp /etc/fdfs/
cp tracker.conf.sample tracker.conf
vi tracker.conf
# 设置
base_path=/home/iki/fastdfs
#配置http端口
http.server_port=6655
mkdir /home/iki/fastdfs
#启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
|
查看日志:
tail -f /home/iki/fastdfs/log/trackerd.log
配置 storage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
cd /etc/fdfs/
cp storage.conf.sample storage.conf
vi storage.conf
#配置组名
group_name=group1
base_path=/home/iki/fastdfs
store_path0=/home/iki/fastdfs_storage
tracker_server=172.27.82.119:22122
http.server_port=5566
# 创建存储目录
mkdir /home/iki/fastdfs_storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
|
cd /home/iki/fastdfs_storage/data
查看数据
ls
使用 fastdfs 测试工具
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
cd /etc/fdfs/
cp client.conf.sample client.conf
vim client.conf
base_path=/home/iki/fastdfs
tracker_server=172.27.82.119:22122
http.tracker_server_port=6655
# 测试运行
cd /home/iki/
echo "hollo fastdfs!!" > hello.md
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/iki/hello.md
|
可用查看输出日志

访问:
http://172.27.82.119/M00/00/00/rBtSd1ukkS-AA5kFAAAAG3Cag0g6276.md
http://172.27.82.119/M00/00/00/rBtSd1ukkS-AA5kFAAAAG3Cag0g6276_big.md
安装 fastdfs-nginx-module
这里注意去看看 nginx 安装教程配置对比
wget http://tar.matosiki.site/zip/fastdfs-nginx-module.zip
1
2
3
4
5
6
7
8
9
10
11
12
|
unzip fastdfs-nginx-module.zip
mv fastdfs-nginx-module /usr/local
# 关闭原nginx进程
pkill nginx
# 进入nginx 源码目录
cd /usr/local/nginx-1.15.0
./configure --add-module=/usr/local/fastdfs-nginx-module/src
|
注意查看 模块添加是否成功

配置 nginx
mkdir -p /usr/local/nginx/logs
vi /usr/local/nginx/conf/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
|
pid /usr/local/nginx/logs/nginx.pid;
location /M00 {
root /home/iki/fastdfs/data;
ngx_fastdfs_module;
}
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
ln -s /home/iki/fastdfs/data /home/iki/fastdfs/data/M00
cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
|
vi /etc/fdfs/mod_fastdfs.conf
1
2
3
4
5
|
url_have_group_name = true
tracker_server=172.27.82.119:22122
store_path0=/home/iki/fastdfs_storage
|
1
2
3
4
|
cp /usr/local/fastdfs-5.05/conf/http.conf /etc/fdfs/http.conf
cp /usr/local/fastdfs-5.05/conf/mime.types /etc/fdfs/mime.types
|
java API 使用

参考链接