Fastdfs + Nginx 部署

本文详细介绍了FastDFS的安装步骤及配置方法,包括依赖安装、tracker与storage服务配置、Nginx集成等关键技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

yum代理

vi /etc/yum.conf

proxy=http://ip:host/ 

 

### FastDFS 安装配置

安装包

```

fastdfs-5.11.tar.gz

libfastcommon

```

 

**安装**

```

#安装依赖软件

yum -y install gcc gcc-c++ libstdc++-devel pcre-develzlib-devel wget make

```

 

* 安装libfastcommon类库

```

命令: yum list |grep zip/unzip   #获取安装列表

安装命令: yum install zip   #提示输入时,请输入y;

安装命令:yum install unzip #提示输入时,请输入y;

 

unzip libfastcommon-1.0.36.zip  -d /usr/local

cd /usr/local/libfastcommon-1.0.36

./make.sh

./make.sh install

```

 

* 安装FastDFS

```

tar -xvzf fastdfs-5.11.tar.gz -C /usr/local

cd /usr/local/fastdfs-5.11

./make.sh

./make.sh install

```

 

安装好之后,在/usr/bin目录下,可以看fdfs开头的命令工具

FastDFS安装完成之后,所有配置文件在/etc/fdfs目录下,tracker需要tracker.conf配置文件,storage需要storage.conf配置文件

 

**安装tracker**

将tracker.conf.sample文件重命名为tracker.conf,然后修改配置文件/etc/fdfs/tracker.conf

```

# 存储日志和数据的根目录

mkdir /data/fastdfs

cd /etc/fdfs

cp tracker.conf.sample tracker.conf

```

只需要修改 base_pash路径(文件存储路径)

```

vi tracker.conf

base_path=/root/fastdfs

```

配置文件中有这几个参数需要注意:

```

#启用配置文件

disabled=false

#设置tracker的端口号

port=22122

#设置tracker的数据文件和日志目录(需手动创建)

base_path=/root/fastdfs

#设置http端口号

http.server_port=9090

```

使用/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start尝试启动tracker

 

 

**安装storage**

```

make /data/fastdfs

cd /etc/fdfs

cp storage.conf.sample storage.conf

```

修改配置

storage主要完成base_path,store_path以及tracker的连接地址以及storage的http服务端口配置等。

主要有如下几个参数:

```

vi /etc/fdfs/storage.conf

# 内容

group_name=group1                   # 组名(第一组为group1,第二组为group2,依次类推...)

base_path=/root/fastdfs             # 数据和日志文件存储根目录

store_path0=/root/fastdfs           #第一个存储目录,第二个存储目录起名为:store_path1=xxx,其它存储目录名依次类推...

store_path_count=1                  # 存储路径个数,需要和store_path个数匹配

tracker_server=192.168.53.85:22122          # tracker服务器IP和端口

tracker_server=192.168.53.86:22122          # tracker服务器IP和端口

```

启动Storage

启动storage,会根据配置文件的设置自动创建多级存储目录,查看端口23000是否开始监听,确认启动是否成功。

```

fdfs_storaged /etc/fdfs/storage.conf restart

 

yum -y installnet-tools

 

netstat -unltp | grep fdfs

```

也可以查看storage的日志是否启动成功。

```

cat /data/fastdfs/logs/storaged.log

```

验证storage是否登记到tracker服务器

使用fdfs_monitor /etc/fdfs/storage.conf,运行fdfs_monitor查看storage服务器是否已经登记到tracker服务器

可以在任一存储节点上使用如下命令查看集群的状态信息

```

fdfs_monitor /etc/fdfs/storage.conf

```

 

如果出现ip_addr = Active, 则表明storage服务器已经登记到tracker服务器,如下:

```

Storage 1:

       id = 192.168.53.90

       ip_addr = 192.168.53.90 (localhost) ACTIVE

```

至此,tracker、storage等配置都完成并成功启动

 

接下来,继续完成Nginx和fastdfs-nginx-module的安装和配置

 

### 在storage上安装nginx

* 注意:fastdfs-nginx-module模块只需要安装到storage上。

 

yum install pcre pcre-devel opensslopenssl-devel –y

 

安装Nginx

tar –zxvf nginx.tar.gz

1. 进入目录: cd nginx-1.11.2

2. 执行命令: ./configure

3. 执行命令: make

4. 执行命令: sudo make install,   安装成功之后,默认会在/usr/local下创建nginx 目录

5. 修改目录权限:

chmod a+rwx -R /usr/local/nginx/logs/

chmod a+rwx -R /usr/local/nginx/

6. 检测配置文件是否正确

检测命令:/usr/local/nginx/sbin/nginx -t

[root@bogon picture_server]# /usr/local/nginx/sbin/nginx-t

nginx: the configuration file/usr/local/nginx/conf/nginx.confsyntax is ok

nginx: configuration file/usr/local/nginx/conf/nginx.conf test issuccessful

启动Nginx

启动命令:

/usr/local/nginx/sbin/nginx

[root@bogon picture_server]#/usr/local/nginx/sbin/nginx

ngx_http_fastdfs_set pid=25060

浏览器中输入: localhost, nginx 监听的89 端口(默认监听80)

安装fastdfs-nginx-module

下载地址:https://github.com/happyfish100/fastdfs-nginx-module/

fastdfs-nginx_module作用:在storage之间同步数据时候,还没同步完全时候就发生下载时,直接从源数据storage下载

将fastdfs-nginx-module压缩包解压,并记录下它的路径,因为安装的时候要用到

进入nginx的安装包的源目录,然后编译和安装fastdfs-nginx-module

命令如下:

注意:要先关闭所有的nginx进程,在进行下面这一步骤

cd nginx

./configure--add-module=/home/ningqijun/fastdfs-nginx-module/src

(/home/ningqijun/fastdfs-nginx-module/src根据自己的文件目录来配)

make

make install

配置nginx.conf

(默认nginx.conf是在目录/usr/local/nginx/conf/ 里面的)

命令:

cd /usr/local/nginx/conf/

vi nginx.conf

只有一个group默认配置

最简单的配置:当mod_fastdfs.conf 配置文件中只有一个group1, 且配置了 url_have_group_name = false 时,即访问地址不使用分组名称,那么只需在nginx的配置文件中增加以下配置即可:

在nginx.conf里面的server{里面添加location /M00……},添加下面的几行:

location /M00 {

      root/home/ningqijun/fastdfs/data;

      ngx_fastdfs_module;

}

多个group的配置

当配置多个组,且mod_fastdfs.conf 里面指定了url_have_group_name= true 时,配置方式:

location ~  /group([0-9]) /M00 {

      root/home/ningqijun/fastdfs/data;

      ngx_fastdfs_module;

}

比如:在group1上的 nginx 的nginx.conf 配置是

location  /group1 /M00 {

      root /home/ningqijun/fastdfs/data;

      ngx_fastdfs_module;

}

比如:在group2上的 nginx 的nginx.conf 配置是

location   /group2 /M00 {

      root/home/ningqijun/fastdfs/data;

      ngx_fastdfs_module;

}

 

创建/M00软连接

命令:ln -s /home/ningqijun/fastdfs/data /home/ningqijun/fastdfs/data/M00

修改mod_fastdfs.conf

将/home/…/fastdfs-nginx-module-master/src(位置看自己将解压到哪里)

里面的mod_fastdfs.conf复制到/etc/fdfs/里面

1.       更改tracker_server的IP如:tracker_server=172.16.36.245:22122

2.       更改store_path0这个要与storaged的配置一致,如:

 url_have_group_name = true

store_path0=/home/ningqijun/fastdfs

重新启动Nginx

将FastDFS配置目录下的2个文件复制到/etc/fdfs目录下:

cp  /usr/local/fastdfs /conf/http.conf  /etc/fdfs/

cp  /usr/local/fastdfs/conf/mime.types  /etc/fdfs/

 

命令:

/usr/local/nginx/sbin/nginx -s stop

/usr/local/nginx/sbin/nginx

注意:要实现HTTP下载必须要求Nginx和fastdfs-nginx-module起来

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值