一、准备环境
FastDFS需要两个服务,一个tracker跟踪器,一个storage存储节点,tracker做调度配置,storage完成文件存储上传等功能。
这里我们使用两台虚拟机服务器(centos 7)来部署,有条件的同学建议直接上云资源,区别就是云端服务器更安全,需要开放一下对应端口
二、下载所需资源包:
https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.42
https://codeload.github.com/happyfish100/fastdfs/tar.gz/V6.04
https://codeload.github.com/happyfish100/fastdfs-nginx-module/tar.gz/V1.22
下载好的资源上传到服务器,这里我放在/home/software/FastDFS里
因为FastDFS是C语言开发,所以需要安装之前构建服务器的C环境,执行命令:
yum -y install gcc-c++
yum -y install libevent
三、安装libfastcommon和fastdfs服务
1.解压
tar -zxvf libfastcommon-1.0.42.tar.gz
tar -zxvf fastdfs_.6.04.tar.gz
2.然后进到目录里,有一个make.sh文件,执行编译安装,两个都执行此步骤
./make.sh 编译
./make.sh install 安装
3.在安装fastdfs时,安装完成后会生成目录 /etc/fdfs ,里面会生成sample文件,我们需要将安装完成后的配置文件copy一份到目录下
cd /home/software/FastDFS/fastdfs-6.04/conf
cp * /etc/fdfs
以上步骤,需要在两台服务器上同步执行,同样的安装和复制配置文件,区别是在1主机上,作为tracker服务,修改tracker的配置文件,2主机修改storage文件的配置文件
四、修改配置文件,启动服务
1.安装完成并copy配置文件到指定目录后,修改tracker的配置文件,这里port是tracker服务的端口,base_path是要存储数据的目录,可以自定义
# bind an address of this host
# empty for bind all addresses of this host
bind_addr=
# the tracker server port
port=22122
# connect timeout in seconds
# default value is 30
# Note: in the intranet network (LAN), 2 seconds is enough.
connect_timeout=10
# network timeout in seconds for send and recv
# default value is 30
network_timeout=60
# the base path to store data and log files
base_path=/usr/local/fastdfs/tracker
2.启动服务试一下,使用/etc/fdfs/下的tracker.conf配置文件启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
3.查一下服务状态
ps -ef | grep tracker
4.tracker启动后,我们配置一下storage
# the storage server port
port=23000
# the base path to store data and log files
# NOTE: the binlog files maybe are large, make sure
# the base path has enough disk space
base_path=/usr/local/fastdfs/storage
# store_path#, based on 0, to configure the store paths to store file
# if store_path0 not exists, it's value is base_path (NOT recommended)
# the paths must be exist
#
# IMPORTANT NOTE:
# the store paths' order is very important, don't mess up!!!
# the base_path should be independent (different) of the store paths
store_path0=/usr/local/fastdfs/storage
#store_path1=/home/yuqing/fastdfs2
# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
# the HOST can be hostname or ip address,
# and the HOST can be dual IPs or hostnames seperated by comma,
# the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
# or two different types of inner (intranet) IPs.
# for example: 192.168.2.100,122.244.141.46:22122
# another eg.: 192.168.1.10,172.17.4.21:22122
tracker_server=192.168.98.131:22122
# tracker_server=192.168.209.122:22122
port:服务端口,云服务器的同学需要开通一下23000的端口
base_path:storage的存储路径,自定义
store_path0:建议同base_path配置成相同路径
tracker_server:关联调度中心,也就是tracker的服务ip和端口
5.然后保存,启动一下
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
6.查一下服务状态
ps -ef | grep storage
五、测试文件上传
调度和执行器都完成后,我们来测试一下,fastdfs提供了一个客户端client,在服务器上可以直接使用client测试文件上传
1. 修改执行器storage上的 client.conf ,base_path 依旧自定义,tracker_server关联调度中心
base_path=/usr/local/fastdfs/client
# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
# the HOST can be hostname or ip address,
# and the HOST can be dual IPs or hostnames seperated by comma,
# the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
# or two different types of inner (intranet) IPs.
# for example: 192.168.2.100,122.244.141.46:22122
# another eg.: 192.168.1.10,172.17.4.21:22122
tracker_server=192.168.98.131:22122
# tracker_server=192.168.0.197:22122
2.我们进到 /usr/bin 下找到服务自带的fdfs_test应用程序,使用刚刚修改的client.conf 配置上传,这里我找了服务器上一个图片做测试
cd /usr/bin/
ls fdfs*
./fdfs_test /etc/fdfs/client.conf upload /home/2bpp63hc1.jpg
上传结果:
[root@hrs-node2 bin]# ./fdfs_test /etc/fdfs/client.conf upload /home/2bpp63hc1.jpg
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.
[2022-12-05 18:17:08] DEBUG - base_path=/usr/local/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.98.133, port=23000
group_name=imooc, ip_addr=192.168.98.133, port=23000
storage_upload_by_filename
group_name=imooc, remote_filename=M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599.jpg
source ip address: 192.168.98.133
file timestamp=2022-12-05 18:17:08
file size=255034
file crc32=2007384531
example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599.jpg
storage_upload_slave_by_filename
group_name=imooc, remote_filename=M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg
source ip address: 192.168.98.133
file timestamp=2022-12-05 18:17:08
file size=255034
file crc32=2007384531
example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg
访问地址:
example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg
Ng 待更新