分佈式文件系統FastDFS+nginx的使用配置

一 存儲(storage)節點安裝Nginx和fastdfs-nginx-module模塊

在storage服務上安裝nginx和fastdfs-nginx-module模塊

主要目的是爲了提供 http 的訪問服務,同時解決 group 中 storage服務器的同步延遲問題。
nginx中須要添加fastdfs-nginx-module模塊。html

fastdfs-nginx-module的下載地址:nginx

http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gzc++

1下載fastdfs-nginx-module而且安裝nginx

[root@localhost tools]# wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
--2017-09-07 08:35:43--  http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
Resolving nchc.dl.sourceforge.net... 211.79.60.17, 2001:e10:ffff:1f02::17
Connecting to nchc.dl.sourceforge.net|211.79.60.17|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17510 (17K) [application/x-gzip]
Saving to: 「fastdfs-nginx-module_v1.16.tar.gz」

100%[===============================================================================================================================================================>] 17,510      42.3K/s   in 0.4s    

2017-09-07 08:35:45 (42.3 KB/s) - 「fastdfs-nginx-module_v1.16.tar.gz」 saved [17510/17510]
## 安裝nginx所需的依賴包
shell> yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
## 編譯安裝nginx(添加fastdfs-nginx-module模塊)
shell> cd /usr/local/src
shell> tar -zxvf nginx-1.8.1.tar.gz
shell> tar -zxvf fastdfs-nginx-module-master.zip
shell> cd nginx-1.10.0
shell> ./configure --prefix=/usr/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src
shell> make && make install

make時候報錯:shell

/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:882: error: ‘struct fdfs_http_context’ has no member named ‘arg’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:883: error: ‘struct fdfs_http_context’ has no member named ‘header_only’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:884: error: ‘struct fdfs_http_context’ has no member named ‘url’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:885: error: ‘struct fdfs_http_context’ has no member named ‘output_headers’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:886: error: ‘struct fdfs_http_context’ has no member named ‘send_file’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:887: error: ‘struct fdfs_http_context’ has no member named ‘send_reply_chunk’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:887: error: ‘fdfs_send_reply_chunk’ undeclared (first use in this function)
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:888: error: ‘struct fdfs_http_context’ has no member named ‘proxy_handler’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:894: error: ‘struct fdfs_http_context’ has no member named ‘if_modified_since’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:897: error: ‘struct fdfs_http_context’ has no member named ‘if_modified_since’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:927: error: ‘struct fdfs_http_context’ has no member named ‘range’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:933: error: ‘struct fdfs_http_context’ has no member named ‘if_range’
/usr/tools/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:933: error: ‘true’ undeclared (first use in this function)
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] Error 1
make[1]: Leaving directory `/usr/tools/nginx-1.8.1'
make: *** [install] Error 2

解決辦法:
執行如下2條命令,而後從新make&make install瀏覽器

# ln -sv /usr/include/fastcommon /usr/local/include/fastcommon
# ln -sv /usr/include/fastdfs /usr/local/include/fastdfs

2 複製 fastdfs-nginx-module 源碼中的配置文件到/etc/fdfs 目錄,並修改

cp /usr/tools/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
connect_timeout=10
base_path=/tmp
tracker_server=192.168.184.132:22122
storage_server_port=23000
group_name=group1                      
url_have_group_name=true
store_path0=/fastdfs/storage

3 複製FastDFS源文件目錄中HTTP相關的配置文件到/etc/fdfs目錄

cd /usr/tools/FastDFS/conf
cp http.conf mime.types /etc/fdfs/

4 建立數據存放目錄的軟連接

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

5 配置fastdfs-nginx-module

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

         # FastDFS 文件訪問配置(fastdfs-nginx-module模塊)
        location ~/group([0-9])/M00 {
            ngx_fastdfs_module;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

Storage 對應有多個 group 的狀況下,訪問路徑帶 group 名,如:http://xxxx/group1/M00/00/00/xxx, 對應的 Nginx 配置爲:服務器

location ~/group([0-9])/M00 {
    ngx_fastdfs_module;
}

 

 6啓動nginx 

[root@localhost sbin]# ./nginx
ngx_http_fastdfs_set pid=5930

 

7 瀏覽器訪問文件測試

http://192.168.184.132:8080/group1/M00/00/00/wKi4hFmxZJ6AYqyCAAAADFmwwCQ352.txt

這是上篇內容上傳的某個txt測試文件,內容爲hello worldapp

這裏我上傳一個window圖片測試看下tcp

[root@localhost bin]# fdfs_upload_file /etc/fdfs/client.conf /usr/tools/window.png 
group1/M00/00/00/wKi4hFmxdpuAbAwtAAdXoefn-Kg866.png
[root@localhost bin]#

而後瀏覽器訪問測試

http://192.168.184.132:8080/group1/M00/00/00/wKi4hFmxdpuAbAwtAAdXoefn-Kg866.pngthis

相關文章
相關標籤/搜索