Fastdfs文件存儲服務搭建-Storage安裝Nginx和fastdfs-nginx-module(四)

**

4.1 安裝nginx和fastdfs-nginx-module模塊

**
4.1.1 安裝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 /tmp
shell> tar -zxvf nginx-1.15.1.tar.gz -C /opt/local/
shell> unzip -o fastdfs-nginx-module-master.zip -d /opt/local/
shell> cd /opt/local/nginx-1.15.1
shell>./configure --prefix=/opt/local/nginx --add-module=/opt/local/fastdfs-nginx-module/src/
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src
shell> make && make install

4.1.2 Nginx編譯出現錯誤
In file included from /opt/local/fastdfs-nginx-module/src/common.c:31,
from /opt/local/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:6:
/usr/include/fastdfs/trunk_shared.h:18:20: error: base64.h: No such file or directory
In file included from /opt/local/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:6:
/opt/local/fastdfs-nginx-module/src/common.c: In function ‘fdfs_http_request_handler’:
/opt/local/fastdfs-nginx-module/src/common.c:1245: error: ‘FDFSHTTPParams’ has no member named ‘support_multi_range’
/opt/local/fastdfs-nginx-module/src/common.c:1349: error: ‘ConnectionInfo’ undeclared (first use in this function)
/opt/local/fastdfs-nginx-module/src/common.c:1349: error: (Each undeclared identifier is reported only once
/opt/local/fastdfs-nginx-module/src/common.c:1349: error: for each function it appears in.)
/opt/local/fastdfs-nginx-module/src/common.c:1349: error: expected ‘;’ before ‘storage_server’
/opt/local/fastdfs-nginx-module/src/common.c:1353: error: ‘storage_server’ undeclared (first use in this function)
cc1: warnings being treated as errors
/opt/local/fastdfs-nginx-module/src/common.c:1366: error: implicit declaration of function ‘storage_download_file_ex1’
make[1]: *** [objs/addon/src/ngx_http_fastdfs_module.o] Error 1
make[1]: Leaving directory `/opt/local/nginx-1.10.2’
make: *** [build] Error 2
首先升級Nginx版本nginx-1.15.1.tar.gz

解決辦法一
ithub fastdfs-nginx-module修改如下:
修改 fastdfs-nginx-module/src/config文件 整個文件改成如下

ngx_addon_name=ngx_http_fastdfs_module
if test -n "${ngx_module_link}"; then
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
else
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
fi

解決方式二
fastdfs-nginx-module-master config文件配置修改如下:

ngx_addon_name=ngx_http_fastdfs_module

if test -n "${ngx_module_link}"; then
    ngx_module_type=HTTP
    ngx_module_name=$ngx_addon_name
    ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
    ngx_module_libs="-lfastcommon -lfdfsclient"
    ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
    ngx_module_deps=
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
    . auto/module
else
    HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
    CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

修改完成之後重新編譯安裝Nginx

shell> make 
shell> make install

**

4.2 配置fastdfs-nginx-module模塊

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

shell> cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
shell> vi /etc/fdfs/mod_fastdfs.conf

第一組存儲服務器的mod_fastdfs.conf配置:

connect_timeout=10
base_path=/tmp
tracker_server=192.168.1.200:22122
tracker_server=192.168.1.201:22122
storage_server_port=23000
group_name=group1                       # 第一組storage的組名
url_have_group_name=true
store_path0=/fastdfs/storage
group_count=2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage

第二組存儲服務器的mod_fastdfs.conf配置:
第二組的mod_fastdfs.confg配置與第一組的配置只有group_name不同:
group_name=group2
4.2.2 拷貝fdfs關於http相關配置文件
複製FastDFS源文件目錄中HTTP相關的配置文件到/etc/fdfs目錄

shell> cd /usr/local/src/FastDFS/conf
shell> cp http.conf mime.types /etc/fdfs/

創建數據存放目錄的軟鏈接,否則Nginx下載文件報錯,找不到文件

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

啓動Nginx

shell>/opt/local/nginx/sbin/nginx

4.2.3 Nginx關於fastdfs-nginx-module樣例
配置fastdfs-nginx-module(Nginx簡潔版樣例)

shell> vi /opt/local/nginx/conf/nginx.conf
user nobody;
worker_processes 1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8888;
        server_name  localhost;

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

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root   html;
        }   
    }
}

如果沒有拷貝 /fastdfs/http.conf,mime.types啓動Nginx會報錯
[2019-07-19 18:01:14] ERROR - file: ini_file_reader.c, line: 1029, include file “http.conf” not exists, line: “#include http.conf”
[2019-07-19 18:01:14] ERROR - file: /opt/local/fastdfs-nginx-module-master/src/common.c, line: 163, load conf file “/etc/fdfs/mod_fastdfs.conf” fail, ret code: 2
ERROR - file: /opt/local/fastdfs-nginx-module-master/src/common.c, line: 188, config file: /etc/fdfs/mod_fastdfs.conf, you must set url_have_group_name to true to support multi-group!
2019/07/19 18:03:36 [alert] 22552#0: worker process 22563 exited with fatal code 2 and cannot be respawned
解決辦法:

# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true

注意:
A、8888 端口值要與/etc/fdfs/storage.conf 中的 http.server_port=8888 相對應,因爲 http.server_port 默認爲 8888,如果想改成 80,則要對應修改過來。
B、Storage 對應有多個 group 的情況下,訪問路徑帶 group 名,如:http://xxxx/group1/M00/00/00/xxx, 對應的 Nginx 配置爲:

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

C、如下載時如發現老報 404,將nginx.conf第一行user nobody;修改爲user root;後重新啓動。
**

4.3 文件下載測試

**
Tracker和storage都配置完成啓動後進行文件下載測試
group2/M00/00/00/Cm48rV01WbuAGBtfAAAQuSkpe6s43.conf
group1/M00/00/00/Cm48rF02ouyANnnfAABBg5TZsd8744.zip

#通過storage訪問
http://10.110.60.173:8888/group2/M00/00/00/Cm48rV01WbuAGBtfAAAQuSkpe6s43.conf
http://10.110.60.171:8888/group1/M00/00/00/Cm48rF02ouyANnnfAABBg5TZsd8744.zip

#通過tracker訪問
http://10.110.60.73:8000/group2/M00/00/00/Cm48rV01WbuAGBtfAAAQuSkpe6s43.conf
http://10.110.60.72:8000/group1/M00/00/00/Cm48rF02ouyANnnfAABBg5TZsd8744.zip

#通過keepalived vip訪問
http://10.110.60.166/dfs/group2/M00/00/00/Cm48rV01WbuAGBtfAAAQuSkpe6s43.conf
http://10.110.60.166/dfs/group1/M00/00/00/Cm48rF02ouyANnnfAABBg5TZsd8744.zip

需要通過安裝keepalived+Nginx通過VIP實現,具體見keepalived安裝與配置

**

4.4 服務開機啓動

**

shell> chkconfig fdfs_trakcerd on
shell> chkconfig fdfs_storaged on

**

4.5 防火牆設置

**
集羣內部需要打開具體的防火牆端口
Storage——23000,8888
Tracker——22122
Eg:
shell> vi /etc/sysconfig/iptables
添加如下端口行:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT 

重啓防火牆:

shell> service iptables restart
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章