fastdfs在4.06版本以后,就不再支持自带的http服务了,如果需要使用http服务来访问文件,则可以与nginx结合部署,实现http服务。
硬件环境:
tracker:192.168.189.146
storage:192.168.189.145 (group1)
storage:192.168.189.144 (group2)
软件环境:
Tengine_2.0.3
fastdfs-nginx-module_v1.15
假设fastdfs集群已经搭建完成,现开始进行nginx的整合。
一:Fastdfs与nginx的集群整合,本试验使用Tengine代替nginx:
注意:4.0.6版本之后,fastdfs已经删除了http web的服务,因此需要与nginx整合,tracker与storage都需要配置nginx,其中storage需要结合nginx_fastdfs模块,tracker不需要,tracker上的nginx主要起代理调度作用。
1:下载tengine与nginx_fastdfs模块到/usr/local/src目录
tengine下载地址:http://tengine.taobao.org/
fastdfs-nginx-module下载地址:https://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz
2:解压,安装tengine。
# cd /usr/local/src && tar -zxvf tengine-2.0.3.tar.gz&& tar -zxvf fastdfs-nginx-module_v1.15.tar.gz 编辑fastdfs-nginx-module的编译文件,修改fastdfs路径 # vi fastdfs-nginx-module/src/config ngx_addon_name=ngx_http_fastdfs_module 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/local/fastdfs/include/fastdfs/usr/local/fastdfs/include/fastcommon/" CORE_LIBS="$CORE_LIBS -L/usr/local/fastdfs/lib -lfastcommon -lfdfsclient" CFLAGS="$CFLAGS-D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024'-DFDFS_MOD_CONF_FILENAME='\"/usr/local/fastdfs/conf/mod_fastdfs.conf\"'" 复制mod_fastdfs.conf到/usr/local/fastdfs/conf/目录下 # cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /usr/local/fastdfs/conf 编译tengine # cd tengine-2.0.3 # ./configure --prefix=/usr/local/tengine--add-module=/usr/local/src/fastdfs-nginx-module/src/ (tracker服务器无需添加此模块) # make && makeinstall
注:与fastdfs时,nginx开启可能失败,错误信息:error while loading sharedlibraries: libfastcommon.so: cannot open shared object file: No such file ordirectory,将/usr/local/fastdfs/lib 加入系统文件/etc/ld.so.conf中即可:
# vi vim/etc/ld.so.conf # /usr/local/fastdfs/lib # /sbin/ldconfig -v
二:mod_fastdfs.conf与tengine的配置:
1:配置tracker的nginx:192.168.189.146
#vi/usr/local/tengine/conf/nginx.conf (部分) upstream fastdfs_group1{ server 192.168.189.145:80; } upstream fastdfs_group2{ server 192.168.189.144:80; } server { listen 80; server_name 192.168.189.146; location /group1 { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://fastdfs_group1; } location /group2 { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://fastdfs_group2; }
2:配置storage group1的mod_fastdfs与nginx:192.168.189.145
配置mod_fastdfs.conf # vi/usr/local/fastdfs/conf/mod_fastdfs.conf base_path=/tmp (日志存放路径) load_fdfs_parameters_from_tracker=true tracker_server=192.168.189.146:22122 (指定tracker) group_name=group1 (指定本机group) url_have_group_name = true (允许在url中出现group名) store_path0=/data/fastdfs/storage (数据路径)
配置nginx.conf #vi/usr/local/tengine/conf/tengine (部分) server { listen 80; server_name 192.168.189.145; location /group1/M00 { root /data/fastdfs/storage/data; ngx_fastdfs_module; }
3:配置storage group2的mod_fastdfs与nginx:192.168.189.144
配置mod_fastdfs.conf # vi/usr/local/fastdfs/conf/mod_fastdfs.conf base_path=/tmp load_fdfs_parameters_from_tracker=true tracker_server=192.168.189.146:22122 group_name=group2 url_have_group_name = true store_path0=/data/fastdfs/storage
配置nginx.conf #vi/usr/local/tengine/conf/tengine (部分) server { listen 80; server_name 192.168.189.144; location /group2/M00 { root /data/fastdfs/storage/data; ngx_fastdfs_module; }
三:启动tracker与storage的nginx:
Tracker(146): # /usr/local/tengine/sbin/nginx -c /usr/local/tengine/conf/nginx.conf Storagegroup1(145): # /usr/local/tengine/sbin/nginx -c /usr/local/tengine/conf/nginx.conf Storage group1(144): # /usr/local/tengine/sbin/nginx -c /usr/local/tengine/conf/nginx.conf
四:测试文件上传、下载:(在146上)
1:测试上传:
2:下载文件:
从上可以看到文件上传至goup1,在本实验中即145服务器,可以直接访问145服务器或者访问146tracker服务器获得文件:
http://192.168.189.145/group1/M00/00/00/oYYBAFP7cHCAdhXQAByq1ZoT93o438.JPG
or
http://192.168.189.146/group1/M00/00/00/oYYBAFP7cHCAdhXQAByq1ZoT93o438.JPG