特点
1.高可靠性(无单点故障)
2.高吞吐量(只要group足够多,数据流量是足够分散的)
流程
先安装下面的东西,新系统需要
//安装了一大堆必要的命令
yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
把相关软件传送至linux:linux软件的一般存放位置 /usr/local
在zq的笔记本中 D:\sorftware\fastdfs 有相关的软件
fastdfs-nginx-module,fastDFS,libfastcommon
nginx 要在线安装
解压libfastcommon
tar -zxvf libfastcommon
安装libfastcommon
进到解压后的文件路径里面
./make.sh //编译
./make.sh install //安装
将/usr/lib64 中的libfastcommon.so 拷贝到 /usr/lib下
cp /usr/lib64/libfastcommon.so /usr/lib
安装fastDFS
tar -zxvf fastdfs-6.04.tar.gz
cd fastdfs-6.04
./make.sh
./make.sh install
# 如果安装出错了执行 ./make.sh clean
将/usr/local/fastdfs/fastdfd-6.04/conf 下面的所有的配置文件都复制到 /etc/fdfs/下 ,拷贝过去都是一些配置文件
1.进入到fastdfs 解压目录,进入到config目录,一定要注意日后等你看笔记的时候,一定不要照抄路径,fastdfs-6.04这个文件夹的名称会根据版本号发生变化
# 进入到 /usr/local/fastdfs/fastdfd-6.04/conf
cp * /etc/fdfs/
开始配置服务
打开端口 创建目录
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=81/tcp --permanent
firewall-cmd --zone=public --add-port=22122/tcp --permanent
firewall-cmd --zone=public --add-port=23000/tcp --permanent
firewall-cmd --zone=public --add-port=8888/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
mkdir -p /home/yuqing/fastdfs/client
mkdir -p /home/yuqing/fastdfs/tracker
mkdir -p /home/yuqing/fastdfs/storage
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
配置tracker
client上传图片之前要先找tracker,tracker找到合适的storage service把路径返回给client,然后client再开始向storage service上传文件
这个tracker在运行的过程中也会产生一些文件(日志文件...),需要一个指定的地址,这个base_path就是来指定这个地址的
我创建了一个新的文件夹 /home/yuqing/fastdfs/tracker 让tracker产生的文件存放在这个文件夹下面
注意:这里说一下文件夹的问题
client,tracker-service,storage_servicee 都需要指定一个base_path,他们运行都会产生一些文件
vim /etc/fdfs/tracker.conf //打开这个文件
# 找到bath_path这个变量,改成自己设置的一个路径
# 保存退出
启动刚才配置好得文件,启动tracker服务
# /usr/bin/fdfs_trackerd :这是一个指令
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
# 可以把上面这个指令加入到开机启动中
vim /etc/rc.d/rc.local
安装storage服务
打开storage服务的配置文件
注意:the store_path must be diffent from base_path
tracker_server:这个服务跑在那个服务器上就是哪个服务器的地址
vim /etc/fdfs/storage.conf
# 如下变量更改
base_path=/home/yuqing/fastdfs/storage
store_path0=/home/yuqing/fastdfs/storage
tracker_server=192.168.31.154:22122
# base_path,store_path0 的路径取决于 人为设置
# tracker_server 取决于你的tracker_server服务器的ip地址是多少,以及端口是多少
配置好之后,重启storageServer服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
# 在storage.conf里面配置好的路径,创建了好多目录
# 可以把上面这个指令加入到开机启动中
vim /etc/rc.d/rc.local
配置client.conf
libfdfsclient.so就是一个linux端的client,它运行也要产生一些文件,所以需要一个文件夹
/usr/local/fastdfs/FastDFS/client 我创建了一个文件夹
fasedfs 解压目录有一个client目录进入到里面
cp libfdfsclient.so /usr/lib #
vim /etc/fdfs/client.conf
# 设置base_path
# 设置tracker_server地址:tarcker_server地址是多少,就写多少
测试上传菜单
注意:如果不是虚拟机,如果是真的服务器,现在或者将来要运行项目,你不应该关闭所有的防火墙,一定要使用哪些端口,就开启那些端口,切记
上传文件之前,查看一下 fastdfs 所需要的端口是否都开启
tracker:22122
storage:23000
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /hi.html
上传成功
This is FastDFS client test program v6.04
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.fastken.com/
for more detail.
[2019-12-15 16:12:12] DEBUG - base_path=/usr/local/fastdfs/fastDFS/client, connect_timeout=10, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.31.154, port=23000
group_name=group1, ip_addr=192.168.31.154, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgfml316tyAG1TOAAAAC27fW3w57.html
source ip address: 192.168.31.154
file timestamp=2019-12-15 16:12:12
file size=11
file crc32=1860131708
example file url: http://192.168.31.154/group1/M00/00/00/wKgfml316tyAG1TOAAAAC27fW3w57.html
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgfml316tyAG1TOAAAAC27fW3w57_big.html
source ip address: 192.168.31.154
file timestamp=2019-12-15 16:12:12
file size=11
file crc32=1860131708
example file url: http://192.168.31.154/group1/M00/00/00/wKgfml316tyAG1TOAAAAC27fW3w57_big.html
修改防火墙配置 - centeros7
# 添加80端口为允许
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 重新载入防火墙规则
firewall-cmd --reload
安装nginx
# nginx依赖这些
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
#进入到解压缩的目录 进到src目录
vim config # 把里面的路径 /local去掉
cp mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
# 需要修改的地方
这里的store_path0 must be same as storage.config's store_path0
store_path0=/usr/local/fastdfs/fastDFS/storage
url_have_group_name = true //是否包含组的名称:group
tracker_server=192.168.31.154:22122
nginx
解压nginx
进入到nginx目录
tar -zxvf nginx-1.9.9
配置nginx和fastdfs-nginx-module的关系
1.找到 /usr/local/fastdfs/fastdfs-nginx-module-1.22/src
在nginx的解压目录 执行
./configure --add-module=/usr/local/fastdfs/fastdfs-nginx-module-1.22/src
make //编译nginx
make install //安装nginx
配置nginx
进入 /usr/local/fastdfs/nginx-1.9.9/conf
vim nginx.conf //
server 做如下配置
server {
//这个nginx监听的端口,也是在这里修改端口.端口修改后服务器的端口也要打开
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
##要添加的部分
# 如果访问地址中包含这个路径 ngxin就不要处理了交给ngx_fastdfs_module去处理
location /group1/M00/ {
ngx_fastdfs_module;
}
##要添加的部分
location / {
root html;
index index.html index.htm;
}
启动nginx
不同版本的nginx目录结构不一样 ,nginx所在的目录也不一样,仔细找一找
./nginx
ps -aux | grep nginx #查看nginx是否跑起来了
注意:
http://49.234.116.125:81/group1/M00/00/00/Mep0fV6C0_iAFBpbAAAAB2bk0EM97_big.html
你的nginx服务器端口多少,这个图片访问路径的端口就是多少,80可以省略
如果nginx也用80,会和tocmat冲突.
一般域名默认对应80端口,图片路径最好不要使用80端口,除非这个服务器专门用来存储图片.
fastdht安装
1.安装berkeleyDB
进入到解压缩目录
cd duild_unix/
./../dist/configure
make
make install
2.安装fastdht
解压fastdht 进入到安装目录
cd FastDHT
./make.sh
./make.sh install
3.配置fastdht
1.修改fdhtd.conf
fastdht运行会产生一些文件,这个路径告诉fastdht这些文件放在什么位置
base_path=/usr/local/fastdfs/fastdht
2.修改fdht_servers.conf(用来配置fastdht集群,这里面的group_count 和 groupX 和 fastTracker,fastStorage 中的group_count 不是一回事,注意区分)
group_count=1 # fastdht组的数量
group0 = 49.234.116.125:11411 //有一个叫group0的fastdht组在49.234.116.125上的11411端口运行
3.配置storage.conf
找到这个文件
vim storage.conf
check_file_duplicate=1 # 开启文件去重
keep_alive=1 # 去重服务和存储服务保持连接
#include /etc/fdhtd/fdht_servers.conf # 告诉存储服务去重服务是怎么配置的
4.重启服务 有顺序
fastdht --> fastTracker --> fastStorage
/usr/local/bin/fdhtd /etc/fdht/fdhtd.conf start
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
网友评论