nginx安装fastdfs-nginx-module和配置常见问题

安装理由通过nginx查看和下载文件

准备资源: fastdfs-5.11.tar.gz和fastdfs-nginx-module_v1.16.tar.gz和nginx

使用到的nginx的常见命令:

        到nginx目录:cd /usr/local/nginx/sbin

        启动nginx: ./nginx -t

        重启nginx: ./nginx -s reload

马上开始安装:

nginx依赖包安装

                     [root@fastdfs2 fdfs]# cd /opt

                     [root@fastdfs2 opt]# yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

              解压nginx

                     [root@fastdfs2 opt]# tar -zxvf nginx-1.13.12.tar.gz

              安装nginx并添加fastdfs模块

                     [root@fastdfs2 opt]# cd nginx-1.13.12

                     [root@fastdfs2 nginx-1.13.12]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src

                     [root@fastdfs2 nginx-1.13.12]# make

                     [root@fastdfs2 nginx-1.13.12]# make install

              检查nginx模块

                     [root@fastdfs2 nginx-1.13.12]# cd /usr/local/nginx/sbin/

                     [root@fastdfs2 sbin]# ./nginx -V

显示:

nginx version: nginx/1.13.12
uilt by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
configure arguments: --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src

已经把fastdfs模块添加进去了。

              配置nginx配置文件

                     [root@fastdfs2 sbin]# cd /usr/local/nginx/conf

                     [root@fastdfs2 conf]# vi nginx.conf

                     内容如下,ip注意改成自己的:

events {
    use epoll;

    worker_connections  1024;
}
http {
    server {
        listen       80;
        server_name  192.168.1.207;

        location /group1/M00/{
                #root /home/FastDFS/fdfs_storage/data;
                ngx_fastdfs_module;
        }
    }
    server {
        listen 8888;
    server_name 192.168.1.207;
        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

      

 启动nginx

                     [root@fastdfs2 conf]# cd /usr/local/nginx/sbin/

                     [root@fastdfs2 sbin]# ./nginx -c /usr/local/nginx/conf/nginx-fdfs.conf

        

下面我们来说说安装过程中遇到的坑:

 端口被占用这就不多说了

 找不到http.cong文件

启动nginx

sudo nginx

然后用【ps aux | grep nginx】,确认nginx进程是否成功启动

root      9126  0.0  0.0  32980   436 ?        Ss   20:52   0:00 nginx: master process nginx

发现结果如上,发现只有master进程,而没有worker进程,说明启动出了问题。

解决办法:去看nginx的log文件【/usr/local/nginx/logs/error.log】,log内容如下

2019/09/02 20:52:26 [notice] 8956#0: signal process started
ngx_http_fastdfs_process_init pid=9127
[2019-09-02 20:52:41] ERROR - file: shared_func.c, line: 968, file /etc/fdfs/mod_fastdfs.conf not exist
[2019-09-02 20:52:41] ERROR - file: /home/ys2/fastdfs/fastdfs-nginx-module-1.20/src/common.c, line: 163, load con\
f file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
2019/09/02 20:52:41 [alert] 9126#0: worker process 9127 exited with fatal code 2 and cannot be respawned

发现没有找到/etc/fdfs/mod_fastdfs.conf 文件。mod_fastdfs.conf 文件在解压后的src文件夹里,所以拷贝到/etc/fdfs目录下。

STEP6:编辑/etc/fdfs/mod_fastdfs.conf 文件。发现此文件和storage.conf文件十分类似。所以照着storage.conf文件修改此文件。

  • 修改base_path=,让值和storage.conf一样。

  • 修改tracker_server=,让值和storage.conf一样。

  • 修改storage_server_port=,让值和storage.conf里的port一样。

  • 修改group_name=,让值和storage.conf一样。

  • 修改url_have_group_name ,让值为true。目的是在浏览器的URL里,显示group_name的值,也就是能看到访问的storage的哪个group。

  • 修改store_path_count=,让值和storage.conf一样。

  • 修改store_path0=,让值和storage.conf一样。

  • 修改group_count =,fastdfs文件系统里有几个组就写几,只有一个组就写1.

  • 如果group_count =1,则必须设置[group1],如果group_count =2,则必须设置[group1]和[group2],以此类推。

    然后,再把[group1]下的所以设置,再写一遍。

把上面都修改好后,再次启动nginx,发现还是没有worker进程,再去看log内容,发现log内容和上一次不一样了,就说明上面的问题已经修改好了,又有别的问题了,已经在向成功迈进了。

[2019-09-02 23:37:19] ERROR - file: ini_file_reader.c, line: 824, include file "http.conf" not exists, line: "#include http.conf"
[2019-09-02 23:37:19] ERROR - file: /home/ys2/fastdfs/fastdfs-nginx-module-1.20/src/common.c, line: 163, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
2019/09/02 23:37:19 [alert] 9383#0: worker process 9384 exited with fatal code 2 and cannot be respawned

说明没找到http.conf文件,

解决办法:拷贝fastdfs源码安装包里的http.conf文件(在conf文件夹里),到/etc/fdfs/文件夹里。

修改好后,再次启动nginx,发现还是没有worker进程,再去看log内容,发现log内容和上一次不一样了,就说明上面的问题已经修改好了,又有别的问题了,已经在向成功迈进了。

2019/09/02 23:53:59 [notice] 9532#0: signal process started
ngx_http_fastdfs_process_exit pid=9497
ngx_http_fastdfs_process_init pid=9536
[2019-09-02 23:54:05] ERROR - file: shared_func.c, line: 968, file /etc/fdfs/mime.types not exist
2019/09/02 23:54:05 [alert] 9535#0: worker process 9536 exited with fatal code 2 and cannot be respawned

说明没找到/etc/fdfs/mime.types文件

解决办法:拷贝nginx源码安装包里的mime.types文件(在conf文件夹里),到/etc/fdfs/文件夹里。

修改好后,再次启动nginx,发现有worker进程了,说明nginx启动成功了。

修改nginx.conf文件,添加下面

location /group1/M00 {
    root   /home/ys2/fastdfs/data;
    ngx_fastdfs_module;
}

最后,在浏览器里直接访问storage节点下的某个文件,比如下面,如果能成功显示在浏览器中,则说明配置成功了。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值