安装Nginx作为服务器以支持Http方式访问文件,Nginx只需要安装到StorageServer所在的服务器即可,用于访问文件

配置Nginx 服务


  1. [Nginx 依赖安装]
  2. yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
  3. [Nginx]
  4. wget -c https://nginx.org/download/nginx-1.12.1.tar.gz
  5. tar -zxvf nginx-1.12.1.tar.gz && cd nginx-1.12.1
  6. :./configure && make && make install


[启动]

    :cd /usr/local/nginx/sbin/

  :./nginx 

# ./nginx -s stop
# ./nginx -s quit
# ./nginx -s reload

    :ln -s /usr/local/nginx/sbin/nginx /usr/local/bin

[root@localhost /]# nginx -V
nginx version: nginx/1.12.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments:

[开机启动]

    :vim /etc/rc.local -> 添加 /usr/local/nginx/sbin/nginx

  :chmod 755 rc.local

简单配置访问

[配置访问]

    :vim /usr/local/nginx/conf/nginx.conf

//添加如下行,将 /group1/M00 映射到 /ljzsg/fastdfs/file/data
location /group1/M00 {
    alias /opt/data/fastdfs/file/data;
}

[访问文件]

    :http://10.10.10.103/group1/M00/00/00/CgoKZ10n8kmAaB06AAEdvO0ZHFk.tar.gz

image.png

FastDFS 配置 Nginx 模块

// fastdfs-nginx-module 可以重定向文件链接到源服务器取文件,避免客户端由于复制延迟导致的文件无法访问错误

[]

    :wget https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip

  :yum install unzip -y

  :unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip

  :mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1  fastdfs-nginx-module-master

[配置Nginx]

# 先停掉nginx服务
# nginx -s stop

进入解压包目录
# cd nginx-1.12.1/

# 添加模块
# ./configure --add-module=/opt/fastdfs-nginx-module-master/src

重新编译、安装
# make && make install

[查看模块]

    :nginx -V

[root@localhost nginx-1.12.1]# nginx -V
nginx version: nginx/1.12.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments: --add-module=/opt/fastdfs-nginx-module-master/src

[配置]

    :cp /opt/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/

  :vim /etc/fdfs/mod_fastdfs.conf

# 连接超时时间
connect_timeout=10

# Tracker Server
tracker_server=file.thinxz.cn:22122

# 如果文件ID的uri中包含/group**,则要设置为true
url_have_group_name = true

# Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0=/opt/data/fastdfs/file

// 复制 FastDFS 的部分配置文件到/etc/fdfs 目录

    :cd /opt/fastdfs-5.05/conf/ && cp anti-steal.jpg http.conf mime.types /etc/fdfs/

[配置nginx,修改nginx.conf]

     :vim /usr/local/nginx/conf/nginx.conf

  // 添加fastdfs-nginx模块
  location ~/group([0-9])/M00 {
    ngx_fastdfs_module;
    }

image.png