在storage上安装nginx
简介:
为每个storage节点安装nginx,使其能够通过http协议,展示文件
nginx此时作为storage节点的客户端
仍然使用上一篇的环境,此时tracker,storage,client都已然配置完成
只需要在storage节点上,安装nginx即可
配置nginx为storage server提供http访问接口:
1、下载fastdfs-nginx-module-master (github站点)
fastdfs-nginx-module-master.zip unzip fastdfs-nginx-module-master.zip
2、下载nginx源码,并编译支持使用fastdfs-nginx-module-master(此处我们使用nginx-1.8.0)
# tar xf nginx-1.8.0.tar.gz # cd nginx-1.8.0 # useradd -r nginx # ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf \ > --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log > --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock > --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module > --with-pcre --add-module=../fastdfs-nginx-module-master/src # make && make install
3、复制配置文件
# cp fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/ # cp fastdfs-master/conf/http.conf /etc/fdfs/ # cp fastdfs-master/conf/mime.types /etc/fdfs/ fastdfs-master为fastdfs源码目录(详情可以参考上篇博客)
4、配置/etc/fdfs/mod_fastdfs.conf配置文件,部分指令类似如下所示
base_path=/fdfs/storage tracker_server=10.1.249.125:22122 storage_server_port=23000 group_name=group1 url_have_group_name = true store_path_count=1 store_path0=/fdfs/storage [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/fdfs/storage
5、配置nginx,编辑nginx.conf,在server中添加类似如下内容:
location ~ /group[0-9]+/M00/ { root /fdfs/storage/data/; ngx_fastdfs_module; }
6、为存储文件路径创建链接至M00,此示例中使用的storage_path0为/fdfs/storage/;
# ln -sv /fdfs/storage /fdfs/storage/M00
7、启动nginx服务即可;
8、上传文件,测试 #(注意:上传文件时,需要为文件带上后缀名)
# fdfs_upload_file /etc/fdfs/client.conf /root/1.jpg group1/M00/00/00/CgH5fVhCPIuAZdmyAAAdK1iq5wc145.jpg
9.测试 #在浏览器中访问类似如下路径即可,后面的URL为fid:
http://10.1.249.125/group1/M00/00/00/CgH5fVhCPIuAZdmyAAAdK1iq5wc145.jpg
10.查看文件真实路径
# ls /fdfs/storage/data/00/00/CgH5fVhCPIuAZdmyAAAdK1iq5wc145.jpg /fdfs/storage/data/00/00/CgH5fVhCPIuAZdmyAAAdK1iq5wc145.jpg
时间: 2024-10-01 22:40:10