美文网首页
fastdfs nginx初步搭建

fastdfs nginx初步搭建

作者: 冰_茶 | 来源:发表于2016-07-27 16:42 被阅读0次

准备环境3台虚拟机

192.168.78.129 tracker

192.168.78.130 storage

192.168.78.131 storage

fastdfs程序

 https://github.com/happyfish100/fastdfs.git

https://github.com/happyfish100/libfastcommon.git

https://github.com/happyfish100/fastdfs-nginx-module.git

1、tracker 安装

1.1 环境配置

mkdir -p /data/software;cd /data/software

git clone https://github.com/happyfish100/libfastcommon.git

git clone https://github.com/happyfish100/fastdfs.git

git clone https://github.com/happyfish100/fastdfs-nginx-module.git

wget http://nginx.org/download/nginx-1.11.2.tar.gz

 安装fastdfs所需类库

cd libfastcommon

./make.sh && ./make.sh install

安装fastdfs

cd ../fastdfs

./make.sh && ./make.sh install

安装fastdfs nginx模块

cd ..

tar -zxvf nginx-1.11.2.tar.gz

cd nginx-1.11.2

./configure --add-module=../fastdfs-nginx-module/src

make && make install

参数设置

默认配置文件路径在/etc/fdfs目录下

cd /etc/fdfs

mv tracker.conf.sample tracker.conf

vim tracker.conf

bind_addr=192.168.78.129

port=22122

base_path=/data/fastdfs/tracker

nginx配置

vim /usr/local/nginx/conf/nginx.conf

http{

...

upstream server_g1{

server 192.168.78.130:80;

server 192.168.78.131:80;

}

server {

...

location / {

proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://server_g1;

}

}

}

启动

nginx -t

nginx

mkdir -p /data/fastdfs/tracker

/etc/init.d/fdfs_trackerd start

storage搭建

安装与tracker配置类似

配置storage 与nginx

mv /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

vim /etc/fdfs/storage.conf

group_name=g1

bind_addr=192.168.78.130

client_bind=true

port=23000

base_path=/data/fastdfs

store_path0=/data/fastdfs/storage

tracker_server=192.168.78.129:22122

vim /usr/local/nginx/conf/nginx.conf

server {

location /g1/M00{

root /data/fastdfs/storage/data;

ngx_fastdfs_module;

}

}

注意部分

1、需要把fastfds源码中conf目录下的http.conf mime.types 复制到/etc/fdfs目录中

2、需要把/data/software/fastdfs-nginx-module/src中的mod_fastdfs.conf 复制到/etc/fdfs目录中

vim /etc/fdfs/mod_fastdfs.conf

base_path=/data/fastdfs

tracker_server=192.168.78.129:22122

store_path0=/data/fastdfs/storage

192.168.78.131 配置与130 同

启动

mkdir -p /data/fastdfs/storage

/usr/local/nginx/sbin/nginx -t

/usr/local/nginx/sbin/nginx 

/etc/init.d/fdfs_storaged start

测试上传与下载 在192.168.78.129 服务器上

cd /etc/fdfs

cp client.conf.sample client.conf

vim client.conf

base_path=/data/fastdfs

tracker_server=192.168.78.129:22122

上传文件

fdfs_upload_file /etc/fdfs/client.conf /data/test.jpg

返回g1/M00/E3/C7/wKhOg1eYA3-AFFCpAAG-_tWFIpc680.jpg

则为成功 

下载文件

fdfs_download_file /etc/fdfs/client.conf g1/M00/E3/C7/wKhOg1eYA3-AFFCpAAG-_tWFIpc680.jpg

nginx访问路径

http://192.168.78.129/g1/M00/E3/C7/wKhOg1eYA3-AFFCpAAG-_tWFIpc680.jpg

http://192.168.78.130/g1/M00/E3/C7/wKhOg1eYA3-AFFCpAAG-_tWFIpc680.jpg

http://192.168.78.131/g1/M00/E3/C7/wKhOg1eYA3-AFFCpAAG-_tWFIpc680.jpg

成功则搭建成功

监控状态

fdfs_monitor /etc/fdfs/client.conf

相关文章

网友评论

      本文标题:fastdfs nginx初步搭建

      本文链接:https://www.haomeiwen.com/subject/zobojttx.html