一、软件包准备:
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
三、部署详细步骤
执行: yum install -y gcc gcc-c++
(如果服务器没有联互联网,需要离线下载安装)
执行:yum -y install libevent
libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库
tar -zxvf libfastcommonV1.0.7.tar.gz -C /usr/local/
cd /usr/local/libfastcommon-1.0.7/
./make.sh #编译
./make.sh install #安装
cp libfastcommon.so /usr/lib
tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local
cd /usr/local/FastDFS/
./make.sh && ./make.sh install #编译安装
cp /usr/local/FastDFS/conf/* /etc/fdfs/
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
# 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服务器还有很大的存储空间
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
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
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local
cd /usr/local/fastdfs-nginx-module/src/
vim config
cp mod_fastdfs.conf /etc/fdfs/
(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
tar -zxvf nginx-1.8.0.tar.gz -C /usr/local/
yum install pcreyum install pcre-develyum install zlibyum install zlib-develyum install opensslyum install openssl-devel
./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
cd /usr/local/FastDFS/conf
cp http.conf mime.types /etc/fdfs/
(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