安装 fastDFS 教程——在 storage 服务器上配置 FastDFS-Nginx-Module
创始人
2024-09-25 14:53:42
0

在 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-简书教程

相关内容

热门资讯

安卓系统为什么不封闭,揭秘安卓... 你有没有想过,为什么安卓系统那么开放,却不像苹果iOS那样封闭呢?这背后可是有着不少有趣的故事和原因...
安卓系统更新包多大,解析不同版... 你有没有发现,每次安卓系统更新,手机里都会多出那么几个G的文件?这可真是让人好奇,安卓系统更新包究竟...
安卓手机安装双系统吗,安卓手机... 你有没有想过,你的安卓手机是不是也能像电脑一样,装上两个系统,一个用来工作,一个用来娱乐?没错,这就...
oppo会升级安卓系统,畅享最... 你知道吗?最近有个大消息在手机圈里炸开了锅,那就是OPPO要升级安卓系统啦!这可不是什么小打小闹的更...
安卓系统上安装windows,... 你有没有想过,在安卓手机上安装Windows系统?听起来是不是有点不可思议?但你知道吗,这竟然是可能...
安卓系统怎么进运行框,安卓系统... 你有没有想过,你的安卓手机里有一个超级实用的功能,那就是运行框!它就像是一个小助手,帮你快速找到正在...
安卓系统电视无图像设置,安卓电... 你家的安卓系统电视突然没图像了?别急,让我来给你支个招,让你轻松解决这个问题!一、检查电源和连接线首...
安卓机建议升级系统吗,提升性能 你有没有发现,你的安卓手机最近有点儿慢吞吞的?是不是在犹豫要不要升级系统呢?别急,让我来给你好好分析...
升级不了安卓系统升级,探寻升级... 你有没有遇到过这种情况?手机里的安卓系统突然告诉你,它需要升级,但你左等右等,就是升不上去。这可真是...
备用安卓系统手机推荐,盘点热门... 你有没有想过,如果你的手机突然罢工了,你会怎么办?别担心,今天我就要给你安利几款备用安卓系统手机,让...
旧安卓系统ipad无法更新系统... 你有没有遇到过这种情况?你的旧安卓系统iPad突然告诉你,它无法更新系统了!是不是瞬间感觉心里有点小...
运行安卓6系统命令大全,全面掌... 你有没有想过,你的安卓手机里隐藏着无数强大的功能,只等着你去发现和探索呢?今天,就让我带你走进安卓6...
安卓系统简笔画教程下载,轻松绘... 你有没有想过,用简单的线条就能把复杂的安卓系统画出来?没错,就是那种一看就懂,一画就上手的感觉!今天...
华为如何鸿蒙转安卓系统,轻松实... 你知道吗?最近华为的大动作可是让整个科技圈都沸腾了!他们竟然把鸿蒙系统转到了安卓系统上,这可真是让人...
安卓10系统的问题,安卓10系... 你有没有发现,自从你的手机升级到安卓10系统后,好像有点不对劲呢?别急,让我来给你细细道来,看看安卓...
安卓系统苹果搞笑视频,苹果搞笑... 你知道吗?在互联网的世界里,搞笑视频可是个永恒的热门话题。尤其是那些结合了安卓系统和苹果手机的搞笑片...
卡片机改造安卓系统,探索改造之... 你有没有想过,那些曾经陪伴我们记录美好时光的卡片机,现在竟然也能焕发第二春呢?没错,就是那些小巧便携...
装安卓系统倒车出不来,智能科技... 你有没有遇到过这样的事情:手机装了个安卓系统,结果倒车的时候出不来啦?这可不是闹着玩的,简直让人抓狂...
定制安卓系统哪家好点儿,哪家服... 你有没有想过,手机系统就像是个人的衣服,每个人都需要找到最适合自己的那一款?今天,咱们就来聊聊定制安...
台电用回安卓系统吗,开启智能新... 最近有个话题在科技圈里炒得挺热的,那就是台电是不是要用回安卓系统了?你有没有想过,这个小小的决定背后...