FASTDFS分布式文件存储服务器搭建

linux环境Ubuntu16.04 1. 在指定目录下创建fastdfs 安装文件夹
mkdir /wjw #下载tar.zp软件包并安装
mkdir /wjw/testfile #上载文件测试文件夹
mkdir /wjw #fastdfs根文件
mkdir /wjw/fastdfs/track #tracker文件配置路径
mkdir /wjw/fastdfs/storage #storage配置路径
mkdir /wjw/fastdfs/clintlog #client配置路径
2. 安装libfastcommon
1. 解压安装 libfastcommon
https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
ar -zxvf V1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install
安装FastDFS https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz

tar -zxvf V5.05.tar.gz
cd fastdfs-5.05
./make.sh
./make.sh install
3.Tracker、Storage、Client、HTTP服务
1.配置Tracker服务
cd /etc/fdfs
ls
cp tracker.conf.sample tracker.conf # 配置跟踪文件
vi tracker.conf # 进入conf文件
修改配置文件
base_path=/data/fastdfs/track # 修改跟踪路径
http.server_port=80 # 修改端口号
方式启动服务,查看监听:
export LD_LIBRARY_PATH=/usr/lib64/
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
netstat -unltp|grep fdfs #查看服务
2.配置Storage服务
cd /etc/fdfs
cp storage.conf.sample storage.conf # 修改存储路径
vi storage.conf # 修改存储文件
group_name=group1 # 修改组名
base_path=/data/fastdfs/storage # 修改存储路径
store_path0=/data/fastdfs/storage #这里可以设置多个存储服务器
tracker_server=10.0.2.15:22122 # 改为本地ip,查看本地ip:ifconfig
http.server_port=8888 # 设置端口号,如果没有冲突尽量默认
启动查看storage服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
netstat -unltp|grep fdfs #查看服务
3.配置Clint服务
cd /etc/fdfs
cp clint.conf.sample clint.conf #修改客户端路径文件
vi clint.conf
进入conf文件后完成以下参数的修改:
base_path=/wjw/fastdfs/clientlog #设置客户端存储路径
tracker_server=10.0.2.15:22122 #改为本地ip
http.tracker_server_port=80
#include http.conf 注意,#include http.conf 这句,原配置文件中有2个#,删掉一个。
4.置HTTP服务
cp /software/fastdfs-5.05/conf/http.conf /etc/fdfs/http.conf # 配置http服务文件
cd /etc/fdfs
vi http.conf
进入conf文件后完成以下参数的修改:
http.anti_steal.token_check_fail=/data/fastdfs/httppic/anti-steal.jpg
4. 设置环境变量和软链接
export LD_LIBRARY_PATH=/usr/lib64/
5.启动fastdfs
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
测试Tracker 和 Storage 服务通信
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
6. 测试上传文件功能
cd /software/testfile
ls
touch test.txt
vi test.txt
fdfs_test /etc/fdfs/client.conf upload /wjw/fastdfs/fastdfs-5.05/conf/anti-steal.jpg
此时浏览器浏览不能直接访问因为还需要配置nginx进行文件上传下载功能
7. 安装Nginx 和 fastdfs-nginx-module,pcre,zlib
https://nginx.org/download/nginx-1.10.1.tar.gz
【FASTDFS分布式文件存储服务器搭建】 在安装Nginx之前,需要安装如下(gcc/pcre/zlib/openssl)插件
dpkg -l | grep zlib
插件安装
openssl安装:
sudo apt-get install openssl libssl-dev
pcre安装:
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install openssl libssl-dev
zlib安装:
sudo apt-get install zlib1g-dev
gcc安装:
sudo apt-get install build-essential
https://github.com/happyfish100/fastdfs-nginx-module/archive/master.tar.gz

解压并修改congfig
编辑配置文件config
命令: vim /wjw/fast/fastdfs-nginx-module/src/config
修改内容:去掉下图中的local文件层次
安装nginx
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
./configure --add-module=/wjw/fastdfs/ fastdfs-nginx-module/src/
make
make install
启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx #启动
./nginx -s stop #此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程
./nginx -s quit #:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s reload
8. 配置fastdfs-nginx-module 和 Nginx
1. 配置mod-fastdfs.conf,并拷贝到/etc/fdfs文件目录下
cd /wjw/fastdfs/fastdfs-nginx-module/src
vi mod_fastdfs.conf
对conf文件作以下修改
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=116.196.117.183:22122
# default value is false
url_have_group_name = true
# must same as storage.conf
store_path0=/wjw/fastdfs/storage
#store_path1=/home/yuqing/fastdfs1
复制文件到/etc/fdfs目录
cp mod_fastdfs.conf /etc/fdfs
拷贝以下文件到/etc/fdfs
1. 进入fastdfs conf目录下
cd/wjw/fastdfs/fastdfs-5.05/conf
2. 拷贝anti-steal.jpg http.conf mime.types 到 /etc/fdfs
cp anti-steal.jpg http.conf mime.types /etc/fdfs/
3.配置Nginx,编辑nginx.config
加入
location /group1/M00 {
root /wjw/fastdfs/storage/;
ngx_fastdfs_module;
}
由于我们配置了group1/M00的访问,我们需要建立一个group1文件夹,并建立M00到data的软链接。
mkdir /wjw/fastdfs/storage/data/group1
ln -s /wjw/fastdfs/storage/data /wjw/fastdfs/storage/data/group1/M00

参考地址
https://www.cnblogs.com/Leo_wl/p/6731647.html

    推荐阅读