一 存储(storage)节点安装Nginx和fastdfs-nginx-module模块
在storage服务上安装nginx和fastdfs-nginx-module模块
主要目的是为了提供 http 的访问服务,同时解决 group 中 storage服务器的同步延迟问题。
nginx中需要添加fastdfs-nginx-module模块。
fastdfs-nginx-module的下载地址:
http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
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时候报错:
/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 world
这里我上传一个window图片测试看下
[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.png