FastDFS + Nginx 安装

1、安装FastDFS依赖lib包

cd /usr/local/src/

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

cd libfastcommon/

./make.sh

./make.sh install

2、安装FastDFS

cd /usr/local/src

wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz

tar -zxvf FastDFS_v5.08.tar.gz

cd FastDFS

./make.sh

./make.sh install

3、tracker配置

sed -i 's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_trackerd

mkdir -p /data/fastdfs/tracker

cd /etc/fdfs/

cp tracker.conf.sample tracker.conf

vim tracker.conf

disabled=false                  #启用配置文件

port=22122                      #设置 tracker 的端口号

base_path=/data/fastdfs/tracker #设置 tracker 的数据文件和日志目录(需预先创建)

http.server_port=80           #设置 http 端口号

/etc/init.d/fdfs_trackerd start

4、storage配置

sed -i 's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_storaged

mkdir -p /data/fastdfs/base

mkdir -p /data/fastdfs/data

cd /etc/fdfs/

cp storage.conf.sample storage.conf

vim storage.conf

disabled=false                        #启用配置文件

group_name=group1                     #组名,根据实际情况修改

port=23000                            #设置 storage 的端口号

base_path=/data/fastdfs/base          #设置 storage 的日志目录(需预先创建)

store_path_count=1                    #存储路径个数,需要和 store_path 个数匹配

store_path0=/fastdfs/storage        #存储路径

tracker_server=10.10.10.81:22122      #tracker 服务器的 IP 地址和端口号

http.server_port=80                 #设置storage上启动的http服务的端口号,如安装的nginx的端口号<br><br>

/etc/init.d/fdfs_storage start

5、client配置

cp -r client.conf.sample cilent.conf

grep -Ev '^$|^#' /etc/fdfs/client.conf

mkdir /data/fastdfs/fdfs_client

vim cilent.conf

base_path=/data/fastdfs/fdfs_client      # 日志路径

tracker_server=172.16.1.40:22122         # 追踪服务器的IP,有多个服务器可以另一行

6、上传文件

[root@img01 fdfs]# fdfs_upload_file /etc/fdfs/client.conf /etc/passwd

G1/M00/00/00/rBABKVe79c-ATItLAAAETQvMt7M7741798

返回上面内容为上传成功 

7、下载文件

[root@img01 fdfs]# fdfs_download_file /etc/fdfs/client.conf

G1/M00/00/00/rBABKVe79c-ATItLAAAETQvMt7M7741798

查看客户端信息

fdfs_monitor /etc/fdfs/client.conf

8、安装Nginx(略)

9、安装fastdfs-nginx-module

fastdfs-nginx_module作用:在storage之间同步数据时候,还没同步完全时候就发生下载时,直接从源数据storage下载

将fastdfs-nginx-module压缩包解压,并记录下它的路径,因为安装的时候要用到

下载地址:https://github.com/happyfish100/fastdfs-nginx-module/

进入nginx的安装包的源目录,然后编译和安装fastdfs-nginx-module

命令如下:

注意:要先关闭所有的nginx进程,在进行下面这一步骤

cd nginx-1.9.15

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

(/usr/local/src/fastdfs-nginx-module/src根据自己的文件目录来配)

make

make install

 复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改

修改以下配置:

connect_timeout=10                  # 客户端访问文件连接超时时长(单位:秒)
base_path=/tmp                      # 临时目录
tracker_server=192.168.0.200:22122  # tracker服务IP和端口
storage_server_port=23000           # storage服务端口
group_name=group1                   # 组名
url_have_group_name=true            # 访问链接前缀加上组名
store_path0=/fastdfs/storage        # 文件存储路径

 复制 FastDFS 的部分配置文件到/etc/fdfs 目录

cp http.conf mime.types /etc/fdfs/

 

/fastdfs/storage文件存储目录下创建软连接,将其链接到实际存放数据的目录

ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00

配置nginx访问storage文件 

http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    server {
        listen 8888;
        server_name 112.74.53.234;
        location ~/group([0-9])/M00 {
            root /fastdfs/storage/data
            ngx_fastdfs_module;
        }
        error_page 500 502 503 504 /50x.html;
 
        location = /50x.html {
            root html;
        }
    }
}


启动nginx /usr/local/nginx/nginx


/etc/fdfs/storage.conf 的 store_path0=/fastdfs/storage 不用写/fastdfs/storage/data 会自动生成data
/etc/fdfs/mod_fastdfs.conf  的 store_path0=/fastdfs/storage 

nginx.conf
root /fastdfs/storage/data

以上路径要正确设置,不正确下载时会 404 ,还有就是 权限问题,nginx.conf 配置 user root;
 
原文地址:https://www.cnblogs.com/chenwh/p/6860814.html