FastDFS集成Nginx模块

一、安装Nginx组件

Nginx 组件安装在storage结点所在服务器,可以使用 HTTP 协议直接访问 Storage 服务中存储的文件资源;
组件版本:fastdfs-nginx-module_v1.16.tar.gz

1.1、解压

[root@localhost temp]# tar -zxf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/fastdfs

1.2、配置修改

[root@localhost temp]# cd /usr/local/fastdfs/fastdfs-nginx-module/src
[root@localhost src]# vi /usr/local/fastdfs/fastdfs-nginx-module/src/config

CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
改为
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/include/fastcommon/"

二、安装Nginx

2.1、安装依赖

[root@localhost src]# yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel

2.2、解压

[root@localhost temp]# tar -zxf nginx-1.8.0.tar.gz -C /usr/local/fastdfs/

2.3、配置

cd /usr/local/fastdfs/nginx-1.8.0/

未安装Nginx方式

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs/fastdfs-nginx-module/src

mkdir -p /var/temp/nginx
make
make install

如果已经安装nginx,则只需添加模块

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

make

cp objs/nginx /usr/local/nginx/sbin/nginx

2.4、配置模块

[root@localhost sbin]# cp /usr/local/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@localhost sbin]# cd /etc/fdfs/
[root@localhost fdfs]# vi mod_fastdfs.conf

参考修改项:
connect_timeout=10
tracker_server=192.168.48.128:22122
url_have_group_name = true #URL 中是否包含 group 名称
store_path0=/fastdfs/storage/store

2.5、提供HTTP配置文件

复制 FastDFS 安装包中的两个配置文件(http.conf 和 mime.types)到/etc/fdfs 目录中

[root@localhost fdfs]# cp /usr/local/fastdfs/FastDFS/conf/http.conf /etc/fdfs/
[root@localhost fdfs]# cp /usr/local/fastdfs/FastDFS/conf/mime.types /etc/fdfs/

2.6、创建软连接

nginx启动软连接:ln -s /usr/local/lib64/libfdfsclient.so /usr/lib64/libfdfsclient.so
创建网络访问存储服务的软连接:ln -s /fastdfs/storage/store/data/ /fastdfs/storage/store/data/M00

2.7、修改Nginx配置

cd /usr/local/nginx/conf
vi nginx.conf
server{
    
    
	listen 8888; # storage 配置中,有 http.server_port=8888 的配置信息,必须 一致。配置文件是/etc/fdfs/storaged.conf 
	server_name localhost; 
	location ~/group([0-9])/M00{
    
    
		ngx_fastdfs_module; 
	}
}

三、访问测试

启动nginx,访问资源http://192.168.48.129:8888/group1/M00/00/00/wKgwgV8xbS6AZBBPAADW-MWxcrw515.jpg
在这里插入图片描述
确保8888端口已开墙

[root@localhost conf]# firewall-cmd --zone=public --add-port=8888/tcp --permanent
success
[root@localhost conf]# firewall-cmd --reload
success

猜你喜欢

转载自blog.csdn.net/shaixinxin/article/details/107926321