当前位置:   article > 正文

安装 fastDFS 教程——在 storage 服务器上配置 FastDFS-Nginx-Module

在 storage 服务器上配置 fastdfs-nginx-module

在 storage 服务器上配置 FastDFS-Nginx-Module

可与这篇文章一起食用 CentOS7 安装 fastDFS 教程

Nginx 是一个高性能的开源Web服务器软件,在 fastDFS 系统中部署在 storage 上,Nginx 可以将客户端的文件上传请求分发给多个FastDFS存储节点,实现负载均衡,提高系统的性能和可靠性。

一、 准备工作

将 storage 服务器的一些配置文件复制到 /etc/fdfs/目录下

cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/
  • 1
  • 2

我们需要使用 Wget 下载 Nginx 源码包,如果系统没有预装,执行命令安装即可。

yum install --assumeyes wget
  • 1

二、下载 Nginx 和 FastDFS-Nginx 模块

进入 /usr/local/src 目录(fastDFS的安装目录),执行以下命令下载 Nginx 源码压缩包:(可在官网选择自己想要的版本)和克隆 FastDFS-Nginx-moudule:

cd /usr/local/src
wget http://nginx.org/download/nginx-1.9.9.tar.gz
git clone https://gitee.com/fastdfs100/fastdfs-nginx-module.git  # gitee源(推荐)
  • 1
  • 2
  • 3

下载完成之后,解压 Nginx ,选择模块版本

tar -zxvf nginx-1.9.9.tar.gz
cd /usr/local/src/fastdfs-nginx-module
git checkout V1.22		#将fastdfs-nginx-module切换到版本 V1.22
  • 1
  • 2
  • 3

进入 nginx-1.9.9 目录,配置安装文件进行安装,执行以下命令。

cd /usr/local/src/nginx-1.9.9/
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/	
make && make install
#make[1]: Leaving directory `/usr/local/src/nginx-1.9.9' ,安装成功则出现这句
  • 1
  • 2
  • 3
  • 4

三、修改配置文件

3.1 修改 nginx.conf 配置文件

首先备份一下 nginx.conf 文件(.bak文件通常是备份文件的扩展名,用于存储原始文件的备份副本),然后再新建一份并编辑这份配置文件

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vi /usr/local/nginx/conf/nginx.conf
  • 1
  • 2

在文件中添加以下内容,添加一个监听 8888 端口的 server 用作转发服务,实现静态映射

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
pid     /var/run/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    #添加这个 server 用作转发服务,实现静态映射
    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;
        }
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128

在 iptables 中增加服务端口 80 和 8888,并重启服务

sed -i "10 a -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT" /etc/sysconfig/iptables
sed -i "10 a -A INPUT -p tcp -m state --state NEW -m tcp --dport 8888 -j ACCEPT" /etc/sysconfig/iptables
service iptables restart
  • 1
  • 2
  • 3

3.2 修改 mod_fastdfs.conf 配置文件

将模块中的 mod_fastdfs.conf 配置文件复制一份到 /etc/fdfs 目录中。

cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
  • 1

然后修改 mod_fastdfs.conf 文件中的路径:

sed -i 's?store_path0=/home/yuqing/fastdfs?store_path0=/home/fastdfs/storage?g' /etc/fdfs/mod_fastdfs.conf
sed -i 's/url_have_group_name = false/url_have_group_name = true/g' /etc/fdfs/mod_fastdfs.conf
  • 1
  • 2

修改 tracker_server 的 ip:

vi /etc/fdfs/mod_fastdfs.conf
  • 1

在这里插入图片描述

3.3 增加 nginx.service 服务启动文件

切换到 /lib/systemd/system/ 目录

cd /lib/systemd/system/
  • 1

新建并编辑 nginx.service 文件

touch nginx.service
vi nginx.service
  • 1
  • 2

在文件追加以下内容

[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /var/run/nginx.pid
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

把文件设置开机自动启动,并且启动 Ngnix 服务

systemctl enable nginx.service
service nginx start
  • 1
  • 2

检查进程是否启动成功

ps -ef | grep nginx
  • 1

在这里插入图片描述

四、通过网址查看文件

上传文件获得 file_id

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf 文件
  • 1

网址格式,8888 端口在之前设置为转发服务端口。

#http://IP地址:8888/file_id , 如下
http://192.168.112.23:8888/group1/M00/00/00/wKhwF2Yk8eyAfb9tABsECAXge8216.png
  • 1
  • 2

通过 Chorme 或者 Edge 浏览器即可查看。


参考链接:

CentOS 安装 FastDFS

CentOS 7 - 安装 FastDFS

CentOS 7 - 从源码安装 Nginx

fastDFS-简书教程

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/731259
推荐阅读
相关标签
  

闽ICP备14008679号