1 安装FastDFS-nginx-module

  • FastDFS-nginx-module_v1.16.tar.gz传至fastDFS的storage服务器的/usr/local/下,执行如下命令
cd /usr/local
tar -zxvf FastDFS-nginx-module_v1.16.tar.gz
  • 进入FastDFS-nginx-module/src,修改config文件将/usr/local/路径改为/usr/
cd fastdfs-nginx-module/src
vim config

  • fastdfs-nginx-module/src下的mod_fastdfs.conf拷贝至/etc/fdfs/

  • 修改mod_fastdfs.conf的内容
vim /etc/fdfs/mod_fastdfs.conf
base_path=/home/fastdfs
tracker_server=192.168.0.103:22122 #有多个就配置多个
url_have_group_name=true #url中包含group名称
store_path0=/home/fastdfs/fdfs_storage #指定文件存储路径 有多个就配置多个
#store_path1=...
#store_path2=...
  • libfdfsclient.so拷贝至/usr/lib
cp /usr/lib64/libfdfsclient.so /usr/lib/
  • 创建nginx/client目录
mkdir -p /var/temp/nginx/client

2 安装nginx

  • nginx-1.8.0.tar.gz拷贝到/usr/local
  • 解压nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
  • 进入nginx-1.8.0目录,执行命令,下边红色部分表示<font color="red">添加Fastdfs-nginx-module模块</font>
cd /usr/local/nginx-1.8.0
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs-nginx-module/src
  • 编译,安装
make
make install

3 nginx配置文件

  • 利用/usr/local/nginx/conf/nginx.conf,创建一个新的nginx配置文件nginx-fdfs.conf,添加虚拟主机
    server {
        listen       80;
        server_name  192.168.0.103;

        location /group1/M00 {
            root   /home/fastdfs/fdfs_storage/data;
            ngx_fastdfs_module;
        }
    }
  • 说明

    • server_name:指定storage本机ip
    • location /group1/M00/

      • group1为nginx 服务FastDFS的分组名称;
      • <font color="red">M00是FastDFS自动生成编号,对应store_path0=/home/FastDFS/fdfs_storage,如果FastDFS定义store_path1,这里就是M01</font>

4 启动storage服务器的nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx-fdfs.conf

5 tracker storage nginx 启动命令

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx-fdfs.conf

6 问题记录

6.1 nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

  • 原因:虚拟机创建/var/run/nginx/目录存放nginx.pid,每次重启后,/var/run目录下都会清空!
  • 解决:放开对pid的注释,并创建/usr/local/nginx/logs目录

mkdir /usr/local/nginx/logs

参考文章:

https://my.oschina.net/u/2464371/blog/2875089

https://blog.csdn.net/weixin_39148512/article/details/80196533

Last modification:February 9th, 2020 at 08:43 pm