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

[复制链接]
发表于 2026-2-5 18:06:00 | 显示全部楼层 |阅读模式
在 storage 服务器上设置 FastDFS-Nginx-Module

可与这篇文章一起食用 CentOS7 安装 fastDFS 教程。
Nginx 是一个高性能的开源Web服务器软件,在 fastDFS 体系中摆设在 storage 上,Nginx 可以将客户端的文件上传哀求分发给多个FastDFS存储节点,实现负载均衡,进步体系的性能和可靠性。
一、 准备工作

将 storage 服务器的一些设置文件复制到 /etc/fdfs/目次下
  1. cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/
  2. cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/
复制代码
我们须要使用 Wget 下载 Nginx 源码包,假如体系没有预装,实行下令安装即可。
  1. yum install --assumeyes wget
复制代码
二、下载 Nginx 和 FastDFS-Nginx 模块

进入 /usr/local/src 目次(fastDFS的安装目次),实行以下下令下载 Nginx 源码压缩包:(可在官网选择本身想要的版本)和克隆 FastDFS-Nginx-moudule:
  1. cd /usr/local/src
  2. wget http://nginx.org/download/nginx-1.9.9.tar.gz
  3. git clone https://gitee.com/fastdfs100/fastdfs-nginx-module.git  # gitee源(推荐)
复制代码
下载完成之后,解压 Nginx ,选择模块版本
  1. tar -zxvf nginx-1.9.9.tar.gz
  2. cd /usr/local/src/fastdfs-nginx-module
  3. git checkout V1.22                #将fastdfs-nginx-module切换到版本 V1.22
复制代码
进入 nginx-1.9.9 目次,设置安装文件举行安装,实行以下下令。
  1. cd /usr/local/src/nginx-1.9.9/
  2. ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/       
  3. make && make install
  4. #make[1]: Leaving directory `/usr/local/src/nginx-1.9.9' ,安装成功则出现这句
复制代码
三、修改设置文件

3.1 修改 nginx.conf 设置文件

起首备份一下 nginx.conf 文件(.bak文件通常是备份文件的扩展名,用于存储原始文件的备份副本),然后再新建一份并编辑这份设置文件
  1. mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
  2. vi /usr/local/nginx/conf/nginx.conf
复制代码
在文件中添加以下内容,添加一个监听 8888 端口的 server 用作转发服务,实现静态映射
  1. #user  nobody;
  2. worker_processes  1;
  3. #error_log  logs/error.log;
  4. #error_log  logs/error.log  notice;
  5. #error_log  logs/error.log  info;
  6. #pid        logs/nginx.pid;
  7. pid     /var/run/nginx.pid;
  8. events {
  9.     worker_connections  1024;
  10. }
  11. http {
  12.     include       mime.types;
  13.     default_type  application/octet-stream;
  14.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  15.     #                  '$status $body_bytes_sent "$http_referer" '
  16.     #                  '"$http_user_agent" "$http_x_forwarded_for"';
  17.     #access_log  logs/access.log  main;
  18.     sendfile        on;
  19.     #tcp_nopush     on;
  20.     #keepalive_timeout  0;
  21.     keepalive_timeout  65;
  22.     #gzip  on;
  23.     #添加这个 server 用作转发服务,实现静态映射
  24.     server {
  25.         listen 8888;
  26.         server_name localhost;
  27.         location ~/group[0-9]/ {
  28.             ngx_fastdfs_module;
  29.         }
  30.         error_page 500 502 503 504 /50x.html;
  31.         location = /50x.html {
  32.             root html;
  33.         }
  34.     }
  35.     server {
  36.         listen       80;
  37.         server_name  localhost;
  38.         #charset koi8-r;
  39.         #access_log  logs/host.access.log  main;
  40.         location / {
  41.             root   html;
  42.             index  index.html index.htm;
  43.         }
  44.         #error_page  404              /404.html;
  45.         # redirect server error pages to the static page /50x.html
  46.         #
  47.         error_page   500 502 503 504  /50x.html;
  48.         location = /50x.html {
  49.             root   html;
  50.         }
  51.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  52.         #
  53.         #location ~ \.php$ {
  54.         #    proxy_pass   http://127.0.0.1;
  55.         #}
  56.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  57.         #
  58.         #location ~ \.php$ {
  59.         #    root           html;
  60.         #    fastcgi_pass   127.0.0.1:9000;
  61.         #    fastcgi_index  index.php;
  62.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  63.         #    include        fastcgi_params;
  64.         #}
  65.         # deny access to .htaccess files, if Apache's document root
  66.         # concurs with nginx's one
  67.         #
  68.         #location ~ /\.ht {
  69.         #    deny  all;
  70.         #}
  71.     }
  72.     # another virtual host using mix of IP-, name-, and port-based configuration
  73.     #
  74.     #server {
  75.     #    listen       8000;
  76.     #    listen       somename:8080;
  77.     #    server_name  somename  alias  another.alias;
  78.     #    location / {
  79.     #        root   html;
  80.     #        index  index.html index.htm;
  81.     #    }
  82.     #}
  83.     # HTTPS server
  84.     #
  85.     #server {
  86.     #    listen       443 ssl;
  87.     #    server_name  localhost;
  88.     #    ssl_certificate      cert.pem;
  89.     #    ssl_certificate_key  cert.key;
  90.     #    ssl_session_cache    shared:SSL:1m;
  91.     #    ssl_session_timeout  5m;
  92.     #    ssl_ciphers  HIGH:!aNULL:!MD5;
  93.     #    ssl_prefer_server_ciphers  on;
  94.     #    location / {
  95.     #        root   html;
  96.     #        index  index.html index.htm;
  97.     #    }
  98.     #}
  99. }  
复制代码
在 iptables 中增长服务端口 80 和 8888,并重启服务
  1. sed -i "10 a -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT" /etc/sysconfig/iptables
  2. sed -i "10 a -A INPUT -p tcp -m state --state NEW -m tcp --dport 8888 -j ACCEPT" /etc/sysconfig/iptables
  3. service iptables restart
复制代码
3.2 修改 mod_fastdfs.conf 设置文件

将模块中的 mod_fastdfs.conf 设置文件复制一份到 /etc/fdfs 目次中。
  1. cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
复制代码
然后修改 mod_fastdfs.conf 文件中的路径:
  1. sed -i 's?store_path0=/home/yuqing/fastdfs?store_path0=/home/fastdfs/storage?g' /etc/fdfs/mod_fastdfs.conf
  2. sed -i 's/url_have_group_name = false/url_have_group_name = true/g' /etc/fdfs/mod_fastdfs.conf
复制代码
修改 tracker_server 的 ip:
  1. vi /etc/fdfs/mod_fastdfs.conf
复制代码

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

切换到 /lib/systemd/system/ 目次
  1. cd /lib/systemd/system/
复制代码
新建并编辑 nginx.service 文件
  1. touch nginx.service
  2. vi nginx.service
复制代码
在文件追加以下内容
  1. [Unit]
  2. Description=A high performance web server and a reverse proxy server
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. PIDFile=/var/run/nginx.pid
  7. ExecStartPre=/usr/local/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
  8. ExecStart=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;'
  9. ExecReload=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload
  10. ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /var/run/nginx.pid
  11. TimeoutStopSec=5
  12. KillMode=mixed
  13. [Install]
  14. WantedBy=multi-user.target
复制代码
把文件设置开机主动启动,而且启动 Ngnix 服务
  1. systemctl enable nginx.service
  2. service nginx start
复制代码
查抄历程是否启动乐成
  1. ps -ef | grep nginx
复制代码

四、通过网址检察文件

上传文件得到 file_id
  1. /usr/bin/fdfs_upload_file /etc/fdfs/client.conf 文件
复制代码
网址格式,8888 端口在之前设置为转发服务端口。
  1. #http://IP地址:8888/file_id , 如下
  2. http://192.168.112.23:8888/group1/M00/00/00/wKhwF2Yk8eyAfb9tABsECAXge8216.png
复制代码
通过 Chorme 大概 Edge 欣赏器即可检察。

参考链接:
CentOS 安装 FastDFS
CentOS 7 - 安装 FastDFS
CentOS 7 - 从源码安装 Nginx
fastDFS-简书教程

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表