在上一篇《CentOS7上安装FastDFS服务》当中介绍了如何安装FastDFS服务,这里接着在Nginx上安装FastDFS模块。
1、安装fastdfs-nginx-module模块
首先下载fastdfs-nginx-module模块:
http://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz/download
[root@fastdfs-storage tools]# tar xf fastdfs-nginx-module_v1.16.tar.gz [root@fastdfs-storage tools]# cd fastdfs-nginx-module/src/ [root@fastdfs-storage src]# vim config PS:修改文件内容如下(如果在后面编译nginx模块时失败了,可修改config文件内容如下): ngx_addon_name=ngx_http_fastdfs_module if test -n "${ngx_module_link}"; then ngx_module_type=HTTP ngx_module_name=$ngx_addon_name ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/" ngx_module_libs="-lfastcommon -lfdfsclient" ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c" ngx_module_deps= CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='2561024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'" . auto/module else 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/include/fastdfs /usr/include/fastcommon/" CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient" CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='2561024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'" fi
2、拷贝fastdfs-nginx-module模块中配置文件到/etc/fdfs目录中并编辑
[root@fastdfs-storage ~]# cp /data/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ [root@fastdfs-storage ~]# vim /etc/fdfs/mod_fastdfs.conf 修改内容如下: connect_timeout=10 base_path=/tmp(默认为/tmp) tracker_server=192.168.211.136:22122 storage_server_port=23000(默认配置为23000) url_have_group_name = true store_path0=/data/fastdfs/storage group_name=group1(默认配置为group1)
3、安装nginx依赖库
[root@fastdfs-storage nginx-1.8.1]# yum install -y pcre-devel zlib-devel
4、安装nginx(注意版本)
[root@fastdfs-storage tools]# tar xf nginx-1.8.1.tar.gz [root@fastdfs-storage tools]# cd nginx-1.8.1 [root@fastdfs-storage nginx-1.8.1]# ./configure --prefix=/data/nginx-1.8.1/nginx/ --add-module=../fastdfs-nginx-module/src/ [root@fastdfs-storage nginx-1.8.1]# make && make install
5、配置nginx,如下所示:
[root@fastdfs-storage ~]# vim /nginx-1.8.1/nginx/conf/nginx.conf user root; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8888;#这里注意端口访问的时候要加上 server_name localhost; location ~/group[0-9]/ { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
说明:
a、"user root"是解决下载操作时报404的问题
b、8888端口号与/etc/fdfs/storage.conf中的http.server_port=8888相对应
c、storage对应有多个group的情况下,访问路径带group名称,例如:/group1/M00/00/00/**,对应nginx配置:
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
然后启动Nginx:
[root@localhost nginx-1.8.1]# ./sbin/nginx ngx_http_fastdfs_set pid=68343
如果看到这个页面就说明安装成功:
然后上传一张图片进行测试:
成功之后,可看到图片地址,然后浏览器访问:
成功!
安装相关问题:
1、启动tracker时出现了如下错误:
启动命令: /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf 错误如下: /usr/bin/fdfs_trackerd: symbol lookup error: /usr/bin/fdfs_trackerd: undefined symbol: g_current_time
解决方式:
ldd /usr/bin/fdfs_trackerd ll /usr/local/lib/libfastcommon.so ll /usr/lib/libfastcommon.so rm -rf /usr/local/lib/libfastcommon.so.1 ldd /usr/bin/fdfs_trackerd
2、编译Nginx时出现如下错误:
[root@localhost nginx-1.8.1]# make install make -f objs/Makefile install make[1]: 进入目录“/data/nginx-1.8.1” test -d '/data/nginx-1.8.1' || mkdir -p '/data/nginx-1.8.1' test -d '/data/nginx-1.8.1/sbin' || mkdir -p '/data/nginx-1.8.1/sbin' test ! -f '/data/nginx-1.8.1/sbin/nginx' || mv '/data/nginx-1.8.1/sbin/nginx' '/data/nginx-1.8.1/sbin/nginx.old' cp objs/nginx '/data/nginx-1.8.1/sbin/nginx' test -d '/data/nginx-1.8.1/conf' || mkdir -p '/data/nginx-1.8.1/conf' cp conf/koi-win '/data/nginx-1.8.1/conf' cp: "conf/koi-win" 与"/data/nginx-1.8.1/conf/koi-win" 为同一文件 make[1]: *** [install] 错误 1 make[1]: 离开目录“/data/nginx-1.8.1” make: *** [install] 错误 2
解决方法:
[root@localhost nginx-1.8.1]# ./configure --prefix=/data/nginx-1.8.1 --add-module=../fastdfs-nginx-module/src/ --conf-path=/data/nginx-1.8.1/nginx.conf
3、如果Nginx启动失败,检查端口是否被占用,然后kill掉之后重新启动
4、Ngins启动报错如下:
[root@localhost sbin]# ./nginx nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] still could not bind()
解决方法,找到nginx的进程然后kill掉:
[root@localhost sbin]# ps -ef | grep nginx root 1632 1625 0 14:05 ? 00:00:00 runsv nginx root 1683 1632 0 14:05 ? 00:00:00 svlogd -tt /var/log/gitlab/nginx root 1684 1632 0 14:05 ? 00:00:00 nginx: master process /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx gitlab-+ 1751 1684 0 14:05 ? 00:00:00 nginx: worker process gitlab-+ 1752 1684 0 14:05 ? 00:00:00 nginx: worker process gitlab-+ 1753 1684 0 14:05 ? 00:00:00 nginx: worker process gitlab-+ 1754 1684 0 14:05 ? 00:00:00 nginx: worker process gitlab-+ 1755 1684 0 14:05 ? 00:00:00 nginx: cache manager process root 10634 1 0 14:50 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 10635 10634 0 14:50 ? 00:00:00 nginx: worker process root 57494 2761 0 16:45 pts/1 00:00:00 grep --color=auto nginx [root@localhost sbin]# kill 10634