安装 fastDFS 教程——在 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/

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

yum install --assumeyes wget

二、下载 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源(推荐)

下载完成之后,解压 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

进入 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' ,安装成功则出现这句

三、修改配置文件

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

在文件中添加以下内容,添加一个监听 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;
    #    }
    #}

}  

在 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

3.2 修改 mod_fastdfs.conf 配置文件

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

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

然后修改 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

修改 tracker_server 的 ip:

vi /etc/fdfs/mod_fastdfs.conf

在这里插入图片描述

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

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

cd /lib/systemd/system/

新建并编辑 nginx.service 文件

touch nginx.service
vi nginx.service

在文件追加以下内容

[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

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

systemctl enable nginx.service
service nginx start

检查进程是否启动成功

ps -ef | grep nginx

在这里插入图片描述

四、通过网址查看文件

上传文件获得 file_id

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

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

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

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


参考链接:

CentOS 安装 FastDFS

CentOS 7 - 安装 FastDFS

CentOS 7 - 从源码安装 Nginx

fastDFS-简书教程

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值