单机版Fastdfs安装部署
一、软件包准备:
1、FastDFS_v5.05.tar.gz
2、libfastcommonV1.0.7.tar.gz
3、 fastdfs-nginx-module_v1.16.tar.gz
4、nginx-1.10.2.tar.gz
二、确认环境端口是否可用,也可更换fastdfs默认端口
tracker使用:22122
storage使用:23000
远程连接端口(xshell):80 、22
三、部署详细步骤
1、安装gcc(编译时需要)
执行: yum install -y gcc gcc-c++
(如果服务器没有联互联网,需要离线下载安装)
2、安装libevent(运行时需求)
执行:yum -y install libevent
3、 安装libfastcommon
libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库
- 将 libfastcommonV1.0.7.tar.gz解压至/usr/local/下
tar -zxvf libfastcommonV1.0.7.tar.gz -C /usr/local/
cd /usr/local/libfastcommon-1.0.7/
./make.sh #编译
./make.sh install #安装
- libfastcommon安装好后会在/usr/lib64 目录下生成 libfastcommon.so 库文件;
- 在/usr/include/fastcommon 生成fastdfs 的基础工具包(不用验证,知道即可)
- 由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下
cp libfastcommon.so /usr/lib
4、安装Fastdfs 程序包(tracker、storage)
- 将FastDFS_v5.05.tar.gz 解压至/usr/local/下
tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local
- 编译和安装
cd /usr/local/FastDFS/
./make.sh && ./make.sh install #编译安装
- 安装成功将安装目录下的conf下的文件拷贝到/etc/fdfs/下
cp /usr/local/FastDFS/conf/* /etc/fdfs/
5、配置并启动tracker
- 修改tracker.conf
vim tracker.conf
- 配置几个核心参数,目录可根据服务器情况新建目录(目录必须已经存在)
(1)base_path=/data/fastdfs/tracker
# 存放track 数据及日志文件目录
# the base path to store data and log files
(2)port=22122
#服务端口
# the tracker server port
(3)(重要) store_lookup=1
# 上传文件选择哪个一个group 的 策略:0:轮询;1:指定组 ; 2: 负载均衡,选择剩余存储空间最大的组group 上传文件
# the method of selecting group to upload files
# 0: round robin
# 1: specify group
# 2: load balance, select the max free space group to upload file
(4)(重要) store_path=0
# 应用场景:选择具体一个组的那一条存储路径(一个group有多条存储路径,一般一个服务器有两块大硬盘挂载到了两个路径下,专门用来存放文件),~0:轮询,2:负载均衡,选择剩余空间最大的路径
(逻辑~重要) 通过上面的配置参数确定了3件事的基础上,该配置才会起作用:
(1)确定了要存储在那个group上,例如group1;(2)确定上传文件要保存在那一台storage 中的group1,假如是192.168.0.171;(3) 此时如果 192.168.0.171 上的storage server中group1 有两个存储路径,即store_path0,store_path1,(对应的文件路径即M00,M01)
(5)reserved_storage_space = 10%
# 给系统或其他应用程序预留存储空间设置
#(重要)场景:某一个group所在某一个storage服务器(可能存在多个服务器上)剩余的存储空间小于等于这个阀值时,则文件不能被保存,即使该group的其他storage服务器还有很大的存储空间
- 启动tracker,运行如下命令
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
6、配置和启动storage
- 切换目录到: /etc/fdfs/ 目录下
- 拷贝一份新的storage配置文件
- 修改storage.conf 配置核心参数
vim storage.conf
(1)base_path=/usr/local/fastdfs/fdfs_storage
#存放storage 服务的数据和日志
# the base path to store data and log files
(2)store_path0=/usr/local/fastdfs/fdfs_storage
# 存储路径配置,可以配置多个,对应的 store_path_count=1 参数需要累加
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
#store_path1=/home/yuqing/fastdfs2
(3)tracker_server=192.168.0.171:22122
#tracker 服务的 ip和端口, ip替换为域名也可以,可以配置多个
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
(4)file_distribute_path_mode=0
# 分布式存储文件策略: 当storage下有多个存储路径时,该配置起作用 ~ # 0: 轮询 # 1: 根据文件名hash结果随机存储
# the mode of the files distributed to the data path
# 0: round robin(default)
# 1: random, distributted by hash code
- 启动storage, 运行命令如下:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
注:至此fastdfs 两个核心组件 tracker、storage 已经安装好了,通过fastdfs自带测试工具可进行测试文件上传(本篇省略),fastdfs在实际项目中往往借助web服务器提供多tracker负载及http文件下载服务,例如nginx,apache等,而fastdfs和nginx的集合最为常用。
7、安装fastdfs-nginx-module_v1.16.tar.gz
- fastdfs-nginx-module 是fastdfs基于nginx提供http服务的附加模块
- 解压 fastdfs-nginx-module_v1.16.tar.gz 到 /usr/local目录下
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local
- 修改 fastdfs-nginx-module 的启动配置文件config
cd /usr/local/fastdfs-nginx-module/src/
vim config
- (重要)修改config文件,将文件中的所有 /usr/local/ 路径改为 /usr/, 因为在安装fastdfs基础模块时,已经将路径设为/usr/include、/usr/lib了
- 将fastdfs-nginx-module/src下的mod_fastdfs.conf拷贝至/etc/fdfs/下,在config文件中已经指定配置文件到/etc/fdfs 目录下读取
cp mod_fastdfs.conf /etc/fdfs/
- 配置 /etc/fdfs/mod_fastdfs.conf 核心参数 (vi /etc/fdfs/mod_fastdfs.conf)
(1)base_path=/tmp #数据及日志目录
(2)tracker_server=192.168.172.20:22122 #tracker_server=192.168.172.20:22122 #(多个tracker配置多行)
(3)url_have_group_name=true #url中包含group名称 store_path0=/home/fdfs_storage #指定文件存储路径(上面配置的store路径)
(4)组名:group_name=group1/group2 #多个用/区分开 (该种配置只支持本机上有多个group)
(5)设置组个数:group_count = 4
(6)设置各group信息:
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/usr/local/fastdfs/storage
[group2]
group_name=group2
storage_server_port=23010
store_path_count=1
store_path0=/usr/local/fastdfs/storage
8、 Nginx安装
- 解压 nginx-1.8.0.tar.gz 到 /usr/local目录下
tar -zxvf nginx-1.8.0.tar.gz -C /usr/local/
- 安装nginx的依赖库
yum install pcreyum install pcre-develyum install zlibyum install zlib-develyum install opensslyum install openssl-devel
- 进入nginx解压的目录下:cd /usr/local/nginx-1.8.0/
- 编译安装前 配置nginx 参数 (已经安装了nginx,需要添加fastdfs模块可参考博文 https://blog.csdn.net/suoyanming/article/details/88691089)
./configure \--prefix=/usr/local/nginx \--pid-path=/var/run/nginx/nginx.pid \--lock-path=/var/lock/nginx.lock \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--with-http_gzip_static_module \--http-client-body-temp-path=/var/temp/nginx/client \--http-proxy-temp-path=/var/temp/nginx/proxy \--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \--http-scgi-temp-path=/var/temp/nginx/scgi \--add-module=/usr/local/project/fastdfs-nginx-module/src
- make && make install #编译并安装
- 拷贝配置文件到 /etc/fdfs 下(fastdfs-nginx-module 要调用)
cd /usr/local/FastDFS/conf
cp http.conf mime.types /etc/fdfs/
- 修改nginx.conf 配置
(1) server_name指定本机ip;
(2) location /group1/M00/:group1为nginx 服务FastDFS的分组名称,M00是FastDFS自动生成编号,对应store_path0=/home/fdfs_storage,如果FastDFS定义store_path1,这里就是M01
(3)nginx的启动 (路径要指定到安装路径,sbin找不到就指定到/usr/local/nginx/sbin/nginx下,conf必须指定到安装目录下)
/usr/local/public/nginx-1.12.2/sbin/nginx -c /usr/local/public/nginx-1.12.2/conf/nginx.conf