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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NettyBoy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值