首页 > 系统相关 >Nginx:代理FastDFS实现文件访问

Nginx:代理FastDFS实现文件访问

时间:2022-11-09 19:00:32浏览次数:68  
标签:11 rw Nginx 访问 storage FastDFS nginx --. root


搭建​​FastDFS​​分布式文件系统参考下面这篇博客:

  • ​​分布式:搭建FastDFS分布式文件系统​​

安装fastdfs-nginx-module

安装​​fastdfs-nginx-module​​​也是只在​​storage​​​上进行,先解压​​fastdfs-nginx-module​​。

[root@storage 00]# cd /usr/local/FastDFS
[root@storage FastDFS]# ll
总用量 1020
drwxr-xr-x. 2 root root 6 1月 9 10:31 client
drwxrwxr-x. 12 root root 4096 12月 31 11:18 fastdfs-6.07
-rw-r--r--. 1 root root 809381 1月 8 23:30 fastdfs-6.07.tar.gz
-rw-r--r--. 1 root root 19952 1月 8 23:30 fastdfs-nginx-module-1.22.tar.gz
drwxrwxr-x. 5 root root 168 1月 8 23:40 libfastcommon-1.0.45
-rw-r--r--. 1 root root 206348 1月 8 23:30 libfastcommon-1.0.45.tar.gz
drwxr-xr-x. 4 root root 30 1月 9 09:32 storage_base
drwxr-xr-x. 3 root root 18 1月 9 10:34 storage_store
drwxr-xr-x. 2 root root 21 1月 9 10:25 test
[root@storage FastDFS]# tar -zxvf fastdfs-nginx-module-1.22.tar.gz
fastdfs-nginx-module-1.22/
fastdfs-nginx-module-1.22/HISTORY
fastdfs-nginx-module-1.22/INSTALL
fastdfs-nginx-module-1.22/src/
fastdfs-nginx-module-1.22/src/common.c
fastdfs-nginx-module-1.22/src/common.h
fastdfs-nginx-module-1.22/src/config
fastdfs-nginx-module-1.22/src/mod_fastdfs.conf
fastdfs-nginx-module-1.22/src/ngx_http_fastdfs_module.c

修改配置文件​​config​​。

[root@storage FastDFS]# cd fastdfs-nginx-module-1.22
[root@storage fastdfs-nginx-module-1.22]# ll
总用量 8
-rw-rw-r--. 1 root root 3036 11月 19 2019 HISTORY
-rw-rw-r--. 1 root root 2001 11月 19 2019 INSTALL
drwxrwxr-x. 2 root root 109 11月 19 2019 src
[root@storage fastdfs-nginx-module-1.22]# cd src
[root@storage src]# ll
总用量 84
-rw-rw-r--. 1 root root 43507 11月 19 2019 common.c
-rw-rw-r--. 1 root root 3995 11月 19 2019 common.h
-rw-rw-r--. 1 root root 848 11月 19 2019 config
-rw-rw-r--. 1 root root 3725 11月 19 2019 mod_fastdfs.conf
-rw-rw-r--. 1 root root 28668 11月 19 2019 ngx_http_fastdfs_module.c
[root@storage src]# vi config

修改如下(就是将两个这路径​​/usr/local/include​​​都修改成​​/usr/include​​):

Nginx:代理FastDFS实现文件访问_配置文件


修改配置文件​​mod_fastdfs.conf​​。

[root@storage src]# vi mod_fastdfs.conf

修改​​base_path​​,用于存储日志文件。

Nginx:代理FastDFS实现文件访问_配置文件_02


修改​​tracker​​服务地址。

Nginx:代理FastDFS实现文件访问_nginx_03


修改组名,与之前的配置保持一致即可,并且将​​url_have_group_name​​​设置为​​true​​​,即​​url​​中会出现组名。

Nginx:代理FastDFS实现文件访问_nginx_04


修改​​store_path0​​​,设置和​​storage​​​配置文件中的​​store_path0​​一样即可。

Nginx:代理FastDFS实现文件访问_配置文件_05

创建​​base_path​​。

[root@storage src]# mkdir /usr/local/FastDFS/tmp

​copy​​​这个配置文件到​​/etc/fdfs/​​​下供​​Nginx​​​结合​​fastdfs-nginx-module​​访问使用。

[root@storage src]# cp /usr/local/FastDFS/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/

安装Nginx

只需要在​​storage​​​上安装​​Nginx​​​即可,因为文件都是存储在​​storage​​​上,​​Nginx​​下载地址:

下载稳定版(​​Linux​​操作系统)。

Nginx:代理FastDFS实现文件访问_nginx_06


下载好后,使用​​Xftp​​​将该压缩文件放到​​storage​​虚拟机中。

Nginx:代理FastDFS实现文件访问_运维_07

解压Nginx

​/usr/local/FastDFS/fastdfs-nginx-module-1.22/src​​​,该路径是有用的,大家也输出一下,不然又得​​cd​​过去查。

[root@storage src]# pwd
/usr/local/FastDFS/fastdfs-nginx-module-1.22/src
[root@storage src]# cd /usr/local
[root@storage local]# ll
总用量 1016
drwxr-xr-x. 2 root root 6 4月 11 2018 bin
drwxr-xr-x. 2 root root 6 4月 11 2018 etc
drwxr-xr-x. 2 root root 6 4月 11 2018 games
drwxr-xr-x. 2 root root 6 4月 11 2018 include
drwxr-xr-x. 2 root root 6 4月 11 2018 lib
drwxr-xr-x. 2 root root 6 4月 11 2018 lib64
drwxr-xr-x. 2 root root 6 4月 11 2018 libexec
-rw-r--r--. 1 root root 1039530 1月 7 16:08 nginx-1.18.0.tar.gz
drwxr-xr-x. 2 root root 6 4月 11 2018 sbin
drwxr-xr-x. 5 root root 49 1月 7 15:44 share
drwxr-xr-x. 2 root root 6 4月 11 2018 src
[root@storage local]# tar -zxvf nginx-1.18.0.tar.gz

编译和安装Nginx

[root@storage local]# cd nginx-1.18.0
[root@storage nginx-1.18.0]# ll
总用量 764
drwxr-xr-x. 6 1001 1001 4096 1月 7 16:24 auto
-rw-r--r--. 1 1001 1001 302863 4月 21 2020 CHANGES
-rw-r--r--. 1 1001 1001 462213 4月 21 2020 CHANGES.ru
drwxr-xr-x. 2 1001 1001 168 1月 7 16:24 conf
-rwxr-xr-x. 1 1001 1001 2502 4月 21 2020 configure
drwxr-xr-x. 4 1001 1001 72 1月 7 16:24 contrib
drwxr-xr-x. 2 1001 1001 40 1月 7 16:24 html
-rw-r--r--. 1 1001 1001 1397 4月 21 2020 LICENSE
drwxr-xr-x. 2 1001 1001 21 1月 7 16:24 man
-rw-r--r--. 1 1001 1001 49 4月 21 2020 README
drwxr-xr-x. 9 1001 1001 91 1月 7 16:24 src

先进行配置,使用​​--add-module​​​选项给​​Nginx​​​添加​​module​​​,其实就是将​​FastDFS​​​(​​fastdfs-nginx-module​​​)与​​Nginx​​进行结合。

[root@storage nginx-1.18.0]# ./configure  --add-module=/usr/local/FastDFS/fastdfs-nginx-module-1.22/src

编译与安装。

[root@storage nginx-1.18.0]# make
...
[root@storage nginx-1.18.0]# make install

修改Nginx配置

[root@storage nginx-1.18.0]# cd /usr/local/nginx/conf
[root@storage conf]# ll
总用量 68
-rw-r--r--. 1 root root 1077 1月 9 11:41 fastcgi.conf
-rw-r--r--. 1 root root 1077 1月 9 11:41 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 1月 9 11:41 fastcgi_params
-rw-r--r--. 1 root root 1007 1月 9 11:41 fastcgi_params.default
-rw-r--r--. 1 root root 2837 1月 9 11:41 koi-utf
-rw-r--r--. 1 root root 2223 1月 9 11:41 koi-win
-rw-r--r--. 1 root root 5231 1月 9 11:41 mime.types
-rw-r--r--. 1 root root 5231 1月 9 11:41 mime.types.default
-rw-r--r--. 1 root root 2656 1月 9 11:41 nginx.conf
-rw-r--r--. 1 root root 2656 1月 9 11:41 nginx.conf.default
-rw-r--r--. 1 root root 636 1月 9 11:41 scgi_params
-rw-r--r--. 1 root root 636 1月 9 11:41 scgi_params.default
-rw-r--r--. 1 root root 664 1月 9 11:41 uwsgi_params
-rw-r--r--. 1 root root 664 1月 9 11:41 uwsgi_params.default
-rw-r--r--. 1 root root 3610 1月 9 11:41 win-utf
[root@storage conf]# vi nginx.conf

添加一个​​serve​​,如下所示。

server {
listen 8888; ## 该端口要与storage.conf中的http.server_port相同
server_name localhost;
location /kaven1/M00 { ## 组名kaven1和M00是虚拟的路径,所以这里需要配置一下
ngx_fastdfs_module;
}
}

Nginx:代理FastDFS实现文件访问_zookeeper_08

启动Nginx

检查​​Nginx​​配置文件是否符合要求,很显然是符合要求的。

[root@storage conf]# cd ..
[root@storage nginx]# cd sbin
[root@storage sbin]# ./nginx -t
ngx_http_fastdfs_set pid=12499
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动​​Nginx​​​,可以看到​​ngx_http_fastdfs_set​​进程也启动了。

[root@storage sbin]# ./nginx
ngx_http_fastdfs_set pid=12508

现在就可以使用​​Nginx​​​访问​​FastDFS​​上的文件了。

记得加上设置的端口​​8888​​。

http://192.168.1.106:8888/kaven1/M00/00/00/wKgBal_5FneAK_TfAAAOi5813CQ7747410

Nginx:代理FastDFS实现文件访问_配置文件_09


​Nginx​​​代理​​FastDFS​​实现访问服务就介绍到这里。写博客是博主记录自己的学习过程,如果有错误,请指正,谢谢!


标签:11,rw,Nginx,访问,storage,FastDFS,nginx,--.,root
From: https://blog.51cto.com/u_15870611/5838305

相关文章