Fastdfs+Nginx部署整合

1、上传需要的安装包
[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
-rw-r--r-- 1 root root 1039530 Mar 25 15:10 nginx-1.18.0.tar.gz
2、安装依赖
[root@test-10 src]# yum install gcc gcc-c++ libevent

image-202103251506

3、安装libfastcommon
# 解压缩
[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
.....
4、安装Fastdfs
# 切到/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/
5、配置并启动tracker
# 创建需要用到的目录
[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
6、配置并启动storage
# 编辑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
7、上传测试
# 使用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
8、Nginx整合
# 解压并配置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
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
9、访问之前测试上传返回的url路径,查看图片是否存在

image-20210326101359319

10、常见故障
1、上传图片正常,在浏览器里面无法访问,现象是页面一直在加载无任何报错显示,检查nginx error日志,发现如下报错:
[2022-02-24 11:28:52] ERROR - file: shared_func.c, line: 974, stat /etc/fdfs/mod_fastdfs.conf fail, errno: 13, error info: Permission denied
[2022-02-24 11:28:52] ERROR - file: /usr/local/fastdfs-nginx-module/src/common.c, line: 155, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 13
解决办法:vim  nginx.conf
# 第一行的启动用户改为 root
user root;
# 重启nginx后检查error日志,没有报错即可


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值