前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Fastdfs + Nginx整合部署

Fastdfs + Nginx整合部署

作者头像
染指流年
发布2023-03-13 16:01:53
4170
发布2023-03-13 16:01:53
举报
文章被收录于专栏:Mr.WangMr.Wang
  • 记一次Fastdfs + Nginx整合部署

1、环境介绍

  • 操作系统:CentOS Linux release 7.6.1810 (Core)
  • Nginx编译安装,版本-nginx/1.18.0
  • Fastdfs编译安装,版本-fastdfs-5.11

server

ip

用途

Nginx

10.110.10.110

Nginx/1.18.0

Fastdfs

10.110.10.110

Fastdfs/5.11

2、上传需要的安装包

代码语言:javascript
复制
[root@test-10 src]# pwd
/usr/local/src
[root@test-10 src]# ll
-rw-r--r-- 1 root root  336939 Mar 25 15:08 fastdfs-5.11.tar.gz
-rw-r--r-- 1 root root   17494 Mar 25 15:08 fastdfs_client_java_v1.10.tar.gz
-rw-r--r-- 1 root root   17510 Mar 25 15:08 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r-- 1 root root  478888 Mar 25 15:08 libfastcommon-1.0.36.zip

3、安装依赖

代码语言:javascript
复制
[root@test-10 src]# yum install gcc gcc-c++ libenent
image20210325150601256.png
image20210325150601256.png

4、安装libfastcommon

代码语言:javascript
复制
# 解压缩
[root@test-10 ~]# cd /usr/local/src/
[root@test-10 src]# unzip  libfastcommon-1.0.36.zip
# 移动到/usr/local/下
[root@test-10 src]# mv libfastcommon-1.0.36 /usr/local/
[root@test-10 src]# cd /usr/local/libfastcommon-1.0.36/
[root@test-10 libfastcommon-1.0.36]# ll
total 36
drwxr-xr-x 2 root root 4096 Apr  5  2017 doc
-rw-r--r-- 1 root root 8005 Apr  5  2017 HISTORY
-rw-r--r-- 1 root root  566 Apr  5  2017 INSTALL
-rw-r--r-- 1 root root 1606 Apr  5  2017 libfastcommon.spec
-rwxr-xr-x 1 root root 3099 Apr  5  2017 make.sh
drwxr-xr-x 2 root root 4096 Apr  5  2017 php-fastcommon
-rw-r--r-- 1 root root 2763 Apr  5  2017 README
drwxr-xr-x 3 root root 4096 Mar 25 15:15 src
# 编译
[root@test-10 libfastcommon-1.0.36]# ./make.sh
.....
# 安装
[root@test-10 libfastcommon-1.0.36]# ./make.sh  install
.....

5、安装Fastdfs

代码语言:javascript
复制
# 切到/usr/local/src/ 目录下
[root@test-10 src]# pwd
/usr/local/src
[root@test-10 src]# ll
total 1856
-rw-r--r-- 1 root root  336939 Mar 25 15:08 fastdfs-5.11.tar.gz
-rw-r--r-- 1 root root   17494 Mar 25 15:08 fastdfs_client_java_v1.10.tar.gz
-rw-r--r-- 1 root root   17510 Mar 25 15:08 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r-- 1 root root  478888 Mar 25 15:08 libfastcommon-1.0.36.zip
-rw-r--r-- 1 root root 1039530 Mar 25 15:10 nginx-1.18.0.tar.gz
# 解压fastdfs安装包到 /usr/local/目录下
[root@test-10 src]# tar zxvf fastdfs-5.11.tar.gz -C /usr/local/
[root@test-10 local]# cd /usr/local/fastdfs-5.11/
[root@test-10 fastdfs-5.11]# ll
total 136
drwxrwxr-x 3 root root  4096 Jun  3  2017 client
drwxrwxr-x 2 root root  4096 Jun  3  2017 common
drwxrwxr-x 2 root root  4096 Jun  3  2017 conf
-rw-rw-r-- 1 root root 35067 Jun  3  2017 COPYING-3_0.txt
-rw-rw-r-- 1 root root  3171 Jun  3  2017 fastdfs.spec
-rw-rw-r-- 1 root root 33100 Jun  3  2017 HISTORY
drwxrwxr-x 2 root root  4096 Jun  3  2017 init.d
-rw-rw-r-- 1 root root  7755 Jun  3  2017 INSTALL
-rwxrwxr-x 1 root root  5548 Jun  3  2017 make.sh
drwxrwxr-x 2 root root  4096 Jun  3  2017 php_client
-rw-rw-r-- 1 root root  2380 Jun  3  2017 README.md
-rwxrwxr-x 1 root root  1768 Jun  3  2017 restart.sh
-rwxrwxr-x 1 root root  1680 Jun  3  2017 stop.sh
drwxrwxr-x 4 root root  4096 Jun  3  2017 storage
drwxrwxr-x 2 root root  4096 Jun  3  2017 test
drwxrwxr-x 2 root root  4096 Jun  3  2017 tracker
# 编译
[root@test-10 fastdfs-5.11]# ./make.sh
.....
# 安装
[root@test-10 fastdfs-5.11]# ./make.sh  install
.....
# 拷贝conf下的文件
[root@test-10 fastdfs-5.11]# cp -rfp conf/* /etc/fdfs/

6、配置并启动tracker

代码语言:javascript
复制
# 创建需要用到的目录
[root@test-10 fdfs]# mkdir -p /opt/fastdfs/tracker
[root@test-10 fdfs]# mkdir -p /opt/fastdfs/storage
[root@test-10 fdfs]# mkdir -p /opt/fastdfs/fdfs_storage
# 编辑tracker配置文件,改为如下参数:
[root@test-10 ~]# vim /etc/fdfs/tracker.conf
base_path=/opt/fastdfs/tracker
http.server_port=80
# 启动tracker
[root@test-10 ~]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf  start
# 验证
[root@test-10 ~]# netstat -ntpl | grep trackerd
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      26814/fdfs_trackerd

7、配置并启动storage

代码语言:javascript
复制
# 编辑storage配置文件,改为如下参数:
[root@test-10 ~]# vim /etc/fdfs/storage.conf
base_path=/opt/fastdfs/storage
store_path0=/opt/fastdfs/fdfs_storage
tracker_server=10.110.10.110:22122
http.server_port=80
# 启动storage
[root@test-10 ~]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
# 验证
[root@test-10 ~]# netstat -ntpl | grep storaged
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      28779/fdfs_storaged
# 启动成功后查看fdfs_storage/data/ 目录下应该有如下目录:
[root@test-10 fastdfs]# ls /opt/fastdfs/fdfs_storage/data/
00  07  0E  15  1C  23  2A  31  38  3F  46  4D  54  5B  62  69  70  77  7E  85  8C  93  9A  A1  A8  AF  B6  BD  C4  CB  D2  D9  E0  E7  EE  F5  FC
01  08  0F  16  1D  24  2B  32  39  40  47  4E  55  5C  63  6A  71  78  7F  86  8D  94  9B  A2  A9  B0  B7  BE  C5  CC  D3  DA  E1  E8  EF  F6  FD
02  09  10  17  1E  25  2C  33  3A  41  48  4F  56  5D  64  6B  72  79  80  87  8E  95  9C  A3  AA  B1  B8  BF  C6  CD  D4  DB  E2  E9  F0  F7  FE
03  0A  11  18  1F  26  2D  34  3B  42  49  50  57  5E  65  6C  73  7A  81  88  8F  96  9D  A4  AB  B2  B9  C0  C7  CE  D5  DC  E3  EA  F1  F8  FF
04  0B  12  19  20  27  2E  35  3C  43  4A  51  58  5F  66  6D  74  7B  82  89  90  97  9E  A5  AC  B3  BA  C1  C8  CF  D6  DD  E4  EB  F2  F9
05  0C  13  1A  21  28  2F  36  3D  44  4B  52  59  60  67  6E  75  7C  83  8A  91  98  9F  A6  AD  B4  BB  C2  C9  D0  D7  DE  E5  EC  F3  FA
06  0D  14  1B  22  29  30  37  3E  45  4C  53  5A  61  68  6F  76  7D  84  8B  92  99  A0  A7  AE  B5  BC  C3  CA  D1  D8  DF  E6  ED  F4  FB

8、上传测试

代码语言:javascript
复制
# 使用fastdfs自带测试工具测试
# 编辑测试配置文件
[root@test-10 fastdfs]# vim /etc/fdfs/client.conf
base_path=/opt/fastdfs
tracker_server=10.110.10.110:22122
# 执行测试命令,使用程序自带测试图片/etc/fdfs/anti-steal.jpg
[root@test-10 fastdfs]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/anti-steal.jpg
# 执行测试命令后回显信息中主要看以下两条参数即可判定是否上传成功
group_name=group1, remote_filename=M00/00/00/Ct0BJ2BcWYOAcviMAABdrZgsqUU032.jpg
example file url: http://10.110.10.110/group1/M00/00/00/Ct0BJ2BcWYOAcviMAABdrZgsqUU032_big.jpg

9、Nginx整合

代码语言:javascript
复制
# 解压并配置fastdfs-nginx-module模块
[root@test-10 ~]# cd /usr/local/src/
[root@test-10 src]# ll
total 1856
-rw-r--r-- 1 root root  336939 Mar 25 15:08 fastdfs-5.11.tar.gz
-rw-r--r-- 1 root root   17494 Mar 25 15:08 fastdfs_client_java_v1.10.tar.gz
-rw-r--r-- 1 root root   17510 Mar 25 15:08 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r-- 1 root root  478888 Mar 25 15:08 libfastcommon-1.0.36.zip
-rw-r--r-- 1 root root 1039530 Mar 25 15:10 nginx-1.18.0.tar.gz
[root@test-10 src]# tar zxvf fastdfs-nginx-module_v1.16.tar.gz  -C /usr/local/
[root@test-10 local]# cd  /usr/local/fastdfs-nginx-module/
[root@test-10 fastdfs-nginx-module]# ll
total 12
-rw-rw-r-- 1 500 500 2342 May  4  2014 HISTORY
-rw-rw-r-- 1 500 500 1733 May  4  2014 INSTALL
drwxrwxr-x 2 500 500 4096 May  4  2014 src
# 修改 config文件里面的 /usr/local/ 为 /usr/ 如下:
[root@test-10 nginx-1.18.0]# vim /usr/local/fastdfs-nginx-module/src/config
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
# 拷贝 mod_fastdfs.conf 文件到 /etc/fdfs/目录下并修改内容如下:
[root@test-10 fastdfs-nginx-module]# cp src/mod_fastdfs.conf  /etc/fdfs/
[root@test-10 fastdfs-nginx-module]# vim /etc/fdfs/mod_fastdfs.conf
base_path=/opt/fastdfs
tracker_server=10.110.10.110:22122
url_have_group_name = true
store_path0=/opt/fastdfs/fdfs_storage
# 安装依赖
[root@test-10 ~]# yum install pcre
[root@test-10 ~]# yum install pcre-devel
[root@test-10 ~]# yum install zlib
[root@test-10 ~]# yum install zlib-devel
[root@test-10 ~]# yum install openssl
[root@test-10 ~]# yum install openssl-devel
# 解压Nginx
[root@test-10 src]# tar zxvf /usr/local/src/nginx-1.18.0.tar.gz  
[root@test-10 src]# cd /usr/local/src/nginx-1.18.0
# 配置
[root@test-10 nginx-1.18.0]# ./configure  --prefix=/opt/nginx  --sbin-path=/opt/nginx/sbin/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --http-client-body-temp-path=/opt/nginx/client --http-proxy-temp-path=/opt/nginx/proxy --http-fastcgi-temp-path=/opt/nginx/fastcgi --http-uwsgi-temp-path=/opt/nginx/uwsgi  --http-scgi-temp-path=/opt/nginx/scgi --add-module=/usr/local/fastdfs-nginx-module/src
.....
# 编译
[root@test-10 nginx-1.18.0]# make
.....
# 安装
[root@test-10 nginx-1.18.0]# make install
.....
# 安装成功后nginx目录下会生成如下内容:
[root@test-10 nginx-1.18.0]# ll /opt/nginx/
total 16
drwxr-xr-x 2 root root 4096 Mar 26 09:55 conf
drwxr-xr-x 2 root root 4096 Mar 26 09:55 html
drwxr-xr-x 2 root root 4096 Mar 26 09:55 sbin
# 编辑nginx配置文件
[root@test-10 conf]# vim /opt/nginx/conf/nginx.conf
user root;
worker_processes  auto;
error_log  logs/error.log  info;
pid        logs/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;
    keepalive_timeout  65;
    gzip  on;
    server {
        listen       80;
        server_name  localhost;
        location /group1/M00/ {
            root   /opt/fastdfs/fdfs_storage/data;
            ngx_fastdfs_module;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
# 启动nginx
[root@test-10 conf]# /opt/nginx/sbin/nginx

10、访问之前测试上传返回的url路径,查看图片是否存在

QQ截图20210329153932
QQ截图20210329153932

11、防火墙规则配置

代码语言:javascript
复制
# 允许访问nginx端口
[root@test-10 ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
# 允许访问Fastdfs端口
[root@test-10 ~]# firewall-cmd --zone=public --add-port=22122/tcp --permanent
# 重载firewalld
[root@test-10 ~]# firewall-cmd --reload

12、自启动配置

代码语言:javascript
复制
# 修改rc.local文件的可执行权限
[root@test-10 ~]# chmod 755 /etc/rc.d/rc.local
# 写入自启动
[root@test-10 ~]# echo "/opt/nginx/sbin/nginx" >> /etc/rc.d/rc.local
[root@test-10 ~]# echo "/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf  start" >> /etc/rc.d/rc.local
[root@test-10 ~]# echo "/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start" >> /etc/rc.d/rc.local
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-03-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2、上传需要的安装包
  • 3、安装依赖
  • 4、安装libfastcommon
  • 5、安装Fastdfs
  • 6、配置并启动tracker
  • 7、配置并启动storage
  • 8、上传测试
  • 9、Nginx整合
  • 10、访问之前测试上传返回的url路径,查看图片是否存在
  • 11、防火墙规则配置
  • 12、自启动配置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档