由于fdfs是应用的fdfs协议,当用web访问时,需要提供http协议的接口,所以要在storage节点上编译安装nginx
git clone https://github.com/happyfish100/fastdfs-nginx-module.git tar xf nginx-1.8.0.tar.gz cd nginx-1.8.0 yum install -y pcre yum install -y pcre-devel ./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/src make && make install groupadd -r nginx useradd -g nginx -r nginx
nginx编译安装完毕
设置fastdfs-nginx-module:
ln -sv /data/fdfs/storage/data/ /data/fdfs/storage/data/M00
靠谱模块的配置文件:
cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
编写配置文件:
[root@node2 ~]# cat /etc/fdfs/mod_fastdfs.conf connect_timeout=2 network_timeout=30 base_path=/data/fdfs/storage load_fdfs_parameters_from_tracker=true storage_sync_file_max_delay = 86400 use_storage_id = false storage_ids_filename = storage_ids.conf tracker_server=192.168.145.93:22122 //此处为tracker的地址和端口 storage_server_port=23000 group_name=group1 url_have_group_name = true //默认为false,要改为true store_path_count=1 store_path0=/data/fdfa/storage log_level=info log_filename= response_mode=proxy if_alias_prefix= flv_support = true flv_extension = flv group_count = 1 //启用存储节点,有几个配置几个 [group1] //节点相关信息配置 group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/data/fdfs/storage
之前使用rpm包的方式安装的fdfs,所以需要拷贝配置文件到/etc/fdfs
cp /root/fastdfs-5.0.11/conf/http.conf /etc/fdfs/ cp /root/fastdfs-5.0.11/conf/mime.types /etc/fdfs/
配置nginx.conf,添加location
location ~ /group[0-9]+/M00/ { root /data/fdfs/storage/data/; ngx_fastdfs_module; }
重启fdfs的存储节点,并启动nginx
service fdfs_storaged restart /usr/local/ngins/sbin/nginx
上传图片并测试
fdfs_upload_file /etc/fdfs/storage.conf /tmp/a.jpg 存储信息:group1/M00/00/00/wKiRXVi-rhOAWDyBAAJOvgO1aMA061.jpg
通过web访问成功
原文地址:http://landanhero.blog.51cto.com/788351/1951195