https://hub.docker.com/r/jerry6290/fastcfs
https://gitee.com/fastdfs100/FastCFS
https://github.com/happyfish100/FastCFS
docker run --privileged -d --name=fastcfs --restart=always -v /data/site:/data/site -v /data/file:/data/file jerry6290/fastcfs:v3.1.0
---验证fastCFS
docker exec -it fastCFS sh
-执行 df -h ,应该能看到 fastCFS的fs pool 被挂载到 /opt/fastcfs/fuse 目录
df -h
Filesystem Size Used Avail Use% Mounted on
overlay 500G 110G 391G 22% /
tmpfs 64M 0 64M 0% /dev
tmpfs 12G 0 12G 0% /sys/fs/cgroup
shm 64M 0 64M 0% /dev/shm
/dev/mapper/centos-root 500G 110G 391G 22% /etc/hosts
/dev/fuse 342G 0 342G 0% /opt/fastcfs/fuse
-写文件
echo 'Hello FastCFS' > /opt/fastcfs/fuse/FastCFS.txt
-查看文件内容
cat /opt/fastcfs/fuse/FastCFS.txt
Hello FastCFS
基于块存储的高性能通用分布式文件系统 FastCFS,可以作为数据库(MySQL、PostgresSQL、Oracle等)以及k8s和虚拟机(KVM等)的后端存储。
FastDFS是轻量级的对象存储,只能通过专有API访问,为互联网应用量身定制,适合存放图片、视频、文档等等;而FastCFS是通用的分布式文件系统,可以mount到本机通过标准文件接口访问,为云平台量身定制,完全支持数据库。一句话总结:FastCFS是云原生分布式文件系统,保证数据强一致,比FastDFS更加通用和可靠。
一. 单机部署
1.一键部署
如果你打算快速体验一下FastCFS,可以一键搭建(包括部署和运行)单节点(需要root身份执行):
git clone https://gitee.com/fastdfs100/FastCFS.git; cd FastCFS/
./helloWorld.sh
# 注意:helloWorld.sh将更改FastCFS相关配置文件,请不要在多节点集群上执行!
上述操作完成后,执行命令:
df -h /opt/fastcfs/fuse | grep fuse
可以看到FastCFS挂载的文件目录,你可以当作本地文件系统访问该目录。
2.查看安装的文件目录
安装成功后,通过df -h 可以看到新增一个/dev/fuse的设备
3.停止服务 使用fashcfs.sh为管理脚本,可以停止、重启服务
[first@192.168.126.50 ~/FastCFS] $ sudo ./fastcfs.sh stop [sudo] password for first: waiting for pid [2364] exit ... pid [2364] exit. waiting for pid [2379] exit ... pid [2379] exit. waiting for pid [2383] exit ... pid [2383] exit. waiting for pid [2400] exit ... pid [2400] exit.
4.使用:在新挂载的目录/opt/fastcfs/fuse 中,
可以进行标准的文件创建/编辑/删除操作
[first@192.168.126.50 /opt/fastcfs/fuse] $ pwd /opt/fastcfs/fuse [first@192.168.126.50 /opt/fastcfs/fuse] $ touch abc // 创建文件 [first@192.168.126.50 /opt/fastcfs/fuse] $ ll total 0 -rw-rw-r--. 1 first first 0 May 14 17:06 abc [first@192.168.126.50 /opt/fastcfs/fuse] $ rm abc // 删除文件 [first@192.168.126.50 /opt/fastcfs/fuse] $ mkdir -p d1/d2/d3 // 创建目录 [first@192.168.126.50 /opt/fastcfs/fuse] $ ll total 0 drwxrwxr-x. 2 first first 0 May 14 17:06 d1 [first@192.168.126.50 /opt/fastcfs/fuse] $ touch d1/d2/d3/123 // 创建文件 [first@192.168.126.50 /opt/fastcfs/fuse] $ ll d1/d2/d3/123 -rw-rw-r--. 1 first first 0 May 14 17:06 d1/d2/d3/123 [first@192.168.126.50 /opt/fastcfs/fuse] $ rm -rf d1 // 删除目录 [first@192.168.126.50 /opt/fastcfs/fuse] $ ll total 0
5.移除安装包恢复初始环境
yum remove FastCFS-auth-server FastCFS-fused fastDIR-server faststore-server -y
rm -rf /etc/fastcfs /opt/fastcfs /opt/faststore
二. 集群部署
fcfs.sh 是一个用于快速部署和管理 FastCFS 集群的脚本工具。
注: 该脚本工具目前仅适用于 Centos 7, Centos 8。
1. 这个工具能做什么?
它能快速构建 FastCFS 集群,包括安装软件、分发配置文件,以及管理集群服务和查看集群日志。
它也能对 FastCFS 单节点或整个集群的相关软件进行升级或降级。
它能重新安装软件或者重新分发配置文件。
2. 这个工具不能做什么?
它不是一个通用的部署工具, 仅适用于 FastCFS 集群。除了将配置文件分发到集群的各个服务器节点以外,它不对集群配置做任何处理。你必须为它提供可用的集群配置文件。
3. 获取 fcfs.sh
从以下地址下载 fcfs.sh,并将其放置在工作站机器的bin目录下,以便命令行能够找到:
http://fastcfs.net/fastcfs/ops/fcfs.sh
获取命令:
curl -o /usr/bin/fcfs.sh http://fastcfs.net/fastcfs/ops/fcfs.sh && sudo chmod +x /usr/bin/fcfs.sh
下载完成后可通过命令 which fcfs.sh 测试工具是否生效。
使用工具的前置条件
- fcfs.settings -- 集群运维配置,放置在当前工作目录中
- conf -- 集群配置文件目录,放置在当前工作目录中
- 远程服务器 SSH 免密登录
你必须为每个集群创建一个独立的工作目录(例如:fastcfs-ops),将 fcfs.settings 和 conf 放入其中。然后所有针对该集群的后续命令操作,都必须在该工作目录中执行。
4.1. fcfs.settings
fcfs.settings 包括两个字段 fastcfs_version 和 fuseclient_ips,fastcfs_version 用于指定 FastCFS 主版本号,fuseclient_ips 用于指定要部署 fuse client 的服务器主机。当需要对 FastCFS 集群软件进行升级或降级操作时,你需要先修改 fastcfs_version 对应的版本号为你期望的版本。
fcfs.settings 配置文件内容举例:
# 要安装的集群版本号(例如:2.2.0) fastcfs_version=2.2.0 # 要安装 fuseclient 客户端的IP列表,多个ip以英文逗号分隔 fuseclient_ips=10.0.1.14
注:推荐使用 2.2.0 及以后的版本用于集群部署。
4.2. conf
FastCFS集群的所有配置文件必须提前放置在工作目录中的 conf 目录,conf 包含以下四个子目录:
- fdir -- fdir 服务器的配置文件
- fstore -- fstore 服务器的配置文件
- auth -- fauth 服务器的配置文件
- fcfs -- fuseclient 客户端的配置文件
获取配置文件样例
mkdir fastcfs-ops cd fastcfs-ops/ curl -o fcfs-config-sample.tar.gz http://fastcfs.net/fastcfs/ops/fcfs-config-sample.tar.gz tar -xzvf fcfs-config-sample.tar.gz
5. SSH 免密登录
fcfs.sh 将通过 SSH 连接所有集群主机。它需要工作站机器可以通过 SSH 在远程主机上执行脚本,执行命令的用户身份可以是 root 或带 sudo的用户,并且必须支持免密登录。
为了开启免密登录,你需要先为 SSH 生成 rsa 公钥/私钥对:
ssh-keygen -t rsa -C cfs -f cfs-ssh-key
将生成密钥文件:
- cfs-ssh-key -- 私钥文件
- cfs-ssh-key.pub -- 公钥文件
5.1. 部署私钥
将私钥文件 cfs-ssh-key 拷贝到工作站机器的当前用户home目录 "~/.ssh/",然后将下面的配置片段加入配置文件 ~/.ssh/config(每个集群主机一份):
Host [node ip] HostName [node host name] User [ssh user] Port 22 PubkeyAuthentication yes IdentityFile ~/.ssh/cfs-ssh-key
5.2. 部署公钥
将公钥文件内容加入到每个节点服务器sudo 用户的home目录下 .ssh/authorized_keys 文件中:
ssh-copy-id -i cfs-ssh-key.pub [user name]@[node server ip]
并确保服务器上sshd的配置文件中开启了以下配置参数:
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys
6. 工具命令介绍
fcfs.sh工具的命令包括三部分:command,module 和 node。Command 是必须的,module 和 node 是可选的。
用法:
fcfs.sh command [module] [node]
Commands:
- setup -- 安装并运行 FastCFS 软件的快捷命令,组合了 install、config 和 restart三个命令
- install -- 安装 FastCFS 软件
- reinstall -- 重新安装 FastCFS 软件
- remove -- 移除 FastCFS 软件,功能与 erase 命令相同
- erase -- 移除 FastCFS 软件
- config -- 将集群配置文件拷贝到目标主机目录
- start -- 启动集群中的所有或单个模块服务
- restart -- 重启集群中的所有或单个模块服务
- stop -- 停止集群中的所有或单个模块服务
- tail -- 查看指定模块日志的最后一部分内容(等同于远程服务器的tail命令)
- help -- 查看命令的详细说明和样例
Modules:
- fdir -- fastDIR 服务器
- fstore -- faststore 服务器
- fauth -- FastCFS auth 服务器
- fuseclient -- FastCFS fuse 客户端
Node:
可以用于指定要执行命令的单个集群节点主机名或IP,如果不指定,命令将在所有节点上执行。node 参数必须在使用了 module 参数的情况下使用,不能单独直接使用。
6.1. FastCFS 一键安装
你可以使用命令 setup 在集群节点上快速安装 FastCFS 软件,并自动配置和启动模块服务.
样例
安装并启动整个 FastCFS 集群:
fcfs.sh setup
在所有 fdir 节点上安装并启动 fdir 服务器:
fcfs.sh setup fdir
在节点 10.0.1.11 上安装 fdir 服务器:
fcfs.sh setup fdir 10.0.1.11
节点 10.0.1.11 必须属于 fdir 集群,否则命令将失败。
6.2. FastCFS 软件安装
你可以使用命令 install 只安装 FastCFS 软件。这个命令是 setup 命令的一部分。
第一次执行该命令时,必须在所有节点上安装所有软件(也就是说,此时不能指定module和node)。之后,当需要增加新节点时,可以携带 module 和 node 参数使用。
样例
在所有节点安装所需的 FastCFS 软件:
fcfs.sh install
在所有 fdir 节点上安装 fdir 服务器:
fcfs.sh install fdir
在 10.0.1.11 节点上安装 fdir 服务器:
fcfs.sh install fdir 10.0.1.11
6.3. FastCFS 软件升级
当你想升级 FastCFS 软件时,你需要先将配置文件 fcfs.settings 中的 fastcfs_version 字段的值修改为新的版本号,然后执行 install 命令:
fcfs.sh install
6.4. FastCFS 软件降级
如果你确实需要将 FastCFS 软件降级为旧的版本,你必须先执行 remove 命令:
fcfs.sh remove
或:
fcfs.sh erase
并将字段 fastcfs_version 的值修改为旧的版本号,然后执行 install 命令:
fcfs.sh install
6.5. FastCFS 软件卸载
可以使用命令 remove 或 erase 卸载 FastCFS 软件。
样例
移除所有节点上的所有软件:
fcfs.sh remove
移除所有 fdir 节点上的 fdir 服务器:
fcfs.sh remove fdir
移除节点10.0.1.11上的 fdir 服务器:
fcfs.sh remove fdir 10.0.1.11
6.6. FastCFS 配置文件分发
成功安装 FastCFS 软件之后,你必须通过执行命令 config 来将配置文件分发到各个集群节点。如果节点上的目标配置文件目录不存在,它将会自动创建它们。
样例
将所有模块的配置文件分发到所有相应的节点上:
fcfs.sh config
将 fdir 服务器的配置文件分发到所有 fdir 节点上:
fcfs.sh config fdir
将 fdir 服务器的配置文件分发到 fdir 节点 10.0.1.11 上:
fcfs.sh config fdir 10.0.1.11
6.7. 集群管理
管理集群的命令包括 start, stop, restart。你可以同时操作所有模块的所有节点,也可以同时操作某一模块的所有节点,也可以单独操作某一模块的某一个节点。
如果想操作单个节点,你必须在 module 参数后指定 node(host)参数(也就是说,你不能同时操作某一节点上的所有模块)。
样例
启动所有节点上的所有服务:
fcfs.sh start
重启所有 fdir 节点上的 fdir 服务:
fcfs.sh restart fdir
停止 节点10.0.1.11上的 fdir 服务:
fcfs.sh stop fdir 10.0.1.11
6.8. 查看集群日志
当你想查看 FastCFS 服务的最新日志时,你可以使用命令 tail 来显示指定模块日志文件的最后一部分。
样例
显示 10.0.1.11节点上 fdir 服务日志文件的最后 100 行:
fcfs.sh tail fdir 10.0.1.11 -n 100
或:
fcfs.sh tail fdir 10.0.1.11 -100
显示每个 fdir 服务器日志的最后 10 行:
fcfs.sh tail fdir
配置及运行
本文档以FastCFS RPM包设定的路径(配置文件目录和程序工作目录等)进行说明,如果你采用自助编译安装方式的话,请自行对应。
配置文件目录结构
/etc/fastcfs/ | |__ fcfs: fused服务 | |__ fuse.conf: fcfs_fused对应的配置文件 | |__ fdir: FastDIR目录服务 | |__ cluster.conf: 服务器列表,配置服务器ID、IP和端口 | |__ server.conf: fdir_serverd对应的配置文件 | |__ client.conf: 客户端配置文件 | |__ fstore: faststore存储服务 |__ cluster.conf: 服务器列表(配置服务器ID、IP和端口),并配置服务器分组及数据分组之间的对应关系 |__ storage.conf: 存储路径及空间分配和回收配置 |__ server.conf: fs_serverd对应的配置文件 |__ client.conf: 客户端配置文件
程序工作目录
/opt/fastcfs/ | |__ fcfs | |__ fused.pid: 服务进程fcfs_fused的pid文件 | |__ logs: 日志文件目录 | |__ fcfs_fused.log: 错误日志 | |__ fdir | |__ serverd.pid: 服务进程fdir_serverd的pid文件 | |__ data: 系统数据文件目录,包含集群拓扑结构和binlog | |__ logs: 日志文件目录 | |__ fdir_serverd.log: 错误日志 | |__ slow.log: 慢查询日志 | |__ fstore |__ serverd.pid: 服务进程fs_serverd的pid文件 |__ data: 系统数据文件目录,包含集群拓扑结构和binlog |__ logs: 日志文件目录 |__ fs_serverd.log: 错误日志 |__ slow.log: 慢查询日志
FastCFS集群配置包含如下四部分:
1. fastDIR server(服务实例)配置
配置文件路径:/etc/fastcfs/fdir
fastDIR集群内各个server配置的cluster.conf必须完全一样。
建议配置一次,分发到集群中的所有服务器和客户端即可。
1.1 把fastDIR集群中的所有服务实例配置到cluster.conf中;
每个fastDIR服务实例包含2个服务端口:cluster 和 service
cluster.conf中配置集群所有实例,一个实例由IP + 端口(包括 cluster和service 2个端口 )组成
一个fastDIR服务实例需要配置一个[server-
如果一台服务器上启动了多个实例,因端口与全局配置的不一致,此时必须指定端口。
一个服务实例的配置示例如下:
[server-3] cluster-port = 11015 service-port = 11016 host = 172.16.168.128
1.2 配置 server.conf
如果需要修改数据存放路径,修改配置项 data_path 为绝对路径
本机端口包含cluster和service 2个端口,分配在[cluster] 和 [service] 中配置
本机IP + 本机端口必须配置在cluster.conf的一个实例中,否则启动时会出现类似的出错信息:
ERROR - file: cluster_info.c, line: 119, cluster config file: /etc/fastcfs/fdir/cluster.conf, can't find myself by my local ip and listen port
fastDIR重启:
/usr/bin/fdir_serverd /etc/fastcfs/fdir/server.conf restart或者:
sudo systemctl restart fastdir查看日志:
tail /opt/fastcfs/fdir/logs/fdir_serverd.log2. faststore server(服务实例)配置
配置文件路径:/etc/fastcfs/fstore
faststore集群各个服务实例配置的cluster.conf必须完全一样。
建议把cluster.conf一次性配置好,然后分发到集群中的所有服务器和客户端。
2.1 把faststore集群中的所有服务实例配置到cluster.conf中;
每个faststore服务实例包含3个服务端口:cluster、replica 和 service
和fastDIR的cluster.conf相比,多了一个replica端口,二者配置方式完全相同。
2.2 在cluster.conf中配置服务器分组和数据分组对应关系;
对于生产环境,为了便于今后扩容,建议数据分组数目至少为64,最好不要超过1024(视业务未来5年发展规模而定)
2.3 在storage.conf 中配置存储路径等参数;
支持配置多个存储路径。为了充分发挥出硬盘性能,建议挂载单盘,每块盘作为一个存储路径。
配置示例:
store_path_count = 1 [store-path-1] path = /opt/faststore/data
2.4 配置 server.conf
如果需要修改binlog存放路径,修改配置项 data_path 为绝对路径
本机端口包含cluster、replica和service 3个端口,分配在[cluster]、[replica] 和 [service] 中配置
本机IP + 本机端口必须配置在cluster.conf的一个实例中,否则启动时会出现类似的出错信息:
ERROR - file: server_group_info.c, line: 347, cluster config file: /etc/fastcfs/fstore/cluster.conf, can't find myself by my local ip and listen port
faststore重启:
/usr/bin/fs_serverd /etc/fastcfs/fstore/server.conf restart或者:
sudo systemctl restart faststore查看日志:
tail /opt/fastcfs/fstore/logs/fs_serverd.log3. FastCFS客户端配置
fused 配置文件路径:/etc/fastcfs/fcfs
3.1 复制faststore server上的如下配置文件到 /etc/fastcfs/fstore/
/etc/fastcfs/fstore/cluster.conf3.2 复制fastDIR server上的如下配置文件到 /etc/fastcfs/fdir/
/etc/fastcfs/fdir/cluster.conf3.3 如有必要,修改fuse.conf 中的mountpoint(可选)
mountpoint = /opt/fastcfs/fusefused 重启:
/usr/bin/fcfs_fused /etc/fastcfs/fcfs/fuse.conf restart或者:
sudo systemctl restart fastcfs查看日志:
tail /opt/fastcfs/fcfs/logs/fcfs_fused.log查看fastDIR集群状态:
fdir_cluster_stat查看单台fastDIR 服务状态:
fdir_service_stat $IP:$port
友情提示:可以拷贝fdir_cluster_stat 输出的IP和服务端口查看faststore集群状态:
fs_cluster_stat
查看非ACTIVE的服务列表,使用:fs_cluster_stat -N
使用 -h 查看更多选项查看FastCFS磁盘使用情况:
df -h /opt/fastcfs/fuse | grep fuse至此,mountpoint(如:/opt/fastcfs/fuse)可以作为本地文件目录访问了。
4. 认证配置(可选)
如果需要开启存储池或访问权限控制
祝顺利! have a nice day!
uth (认证模块)配置及运行
如果你不需要使用存储池或访问权限控制,可以跳过本文档。
本文档以FastCFS RPM包设定的路径(配置文件目录和程序工作目录等)进行说明,如果你采用自助编译安装方式的话,请自行对应。
Auth配置文件目录结构
/etc/fastcfs/ | |__ auth: 认证中心 |__ keys: 存放用户密钥文件,每个用户对应一个密钥文件,例如 admin.key | |__ session_validate.key: 用于FastDIR和FastStore请求auth服务验证session和权限 |__ cluster.conf: 服务器列表,配置服务器ID、IP和端口 |__ server.conf: fcfs_authd对应的配置文件 |__ client.conf: 客户端配置文件 |__ auth.conf: 认证相关的公共配置文件,在FastDIR和FastStore的cluster.conf中引用 |__ session.conf: session相关配置文件,在Auth、FastDIR和FastStore的server.conf中引用
authd程序工作目录
/opt/fastcfs/ | |__ auth |__ authd.pid: 服务进程fcfs_authd的pid文件 |__ logs: 日志文件目录 |__ fcfs_authd.log: 错误日志 |__ slow.log: 慢查询日志
开启认证功能需要设置认证中心、FastDIR server、FastStore server和FastCFS客户端。
1. 认证中心(authd server)配置
配置文件路径:/etc/fastcfs/auth
Auth集群内各个server配置的cluster.conf必须完全一样。
建议配置一次,分发到其他服务器即可。
1.1 把Auth集群中的所有服务实例配置到cluster.conf中;
每个Auth服务实例包含2个服务端口:cluster 和 service
一个Auth服务实例需要配置一个[server-
- 注:目前仅支持一个服务实例,后续版本将支持多服务实例。
1.2 配置 server.conf
- [cluster] 和 [service] 配置的端口(port)必须与cluster.conf中本机的一致,否则启动会报错
1.3 配置 auth.conf
将 auth_enabled 设置为 true 以开启认证功能
1.4 复制FastDIR server上的如下配置文件到 /etc/fastcfs/fdir/
/etc/fastcfs/fdir/client.conf /etc/fastcfs/fdir/cluster.conf
1.5 启动authd
authd重启:
/usr/bin/fcfs_authd /etc/fastcfs/auth/server.conf restart
或者:
sudo systemctl restart fcfs_authd查看日志:
tail /opt/fastcfs/auth/logs/fcfs_authd.log- 第一次运行将自动创建 admin 用户,默认生成的密钥文件名为 /etc/fastcfs/auth/keys/admin.key
1.6 创建存储池
创建名为 fs 的存储池,配额无限制:
fcfs_pool create fs unlimited注:存储池名称必须和FastCFS fuse客户端配置文件fuse.conf中的命名空间一致(缺省配置为fs,可按需修改)
2. FastDIR server
2.1 复制auth server上的如下配置文件到 /etc/fastcfs/auth/
/etc/fastcfs/auth/auth.conf /etc/fastcfs/auth/session.conf /etc/fastcfs/auth/cluster.conf /etc/fastcfs/auth/client.conf
2.2 复制auth server上的如下密钥文件到 /etc/fastcfs/auth/keys
/etc/fastcfs/auth/keys/admin.key
/etc/fastcfs/auth/keys/session_validate.key拷贝完成后重启FastDIR服务(fdir_serverd)
3. FastStore server
参见 2. FastDIR server 部分 拷贝完成后重启FastStore服务(fs_serverd)
4. FastCFS客户端(fused)
参见 2. FastDIR server 部分
拷贝完成后重启fuse服务(fcfs_fused)
命令行工具
fcfs_user:用户管理
fcfs_pool:储存池管理
注意事项
- Auth server依赖FastDIR server,需要先启动FastDIR server,然后启动Auth server。
三. yum安装方式
yum 安装方式主要用于测试和生产环境搭建。
1. 安装FastOS.repo
先安装FastOS.repo yum源,然后就可以安装FastCFS相关软件包了。
CentOS 7
rpm -ivh http://www.fastken.com/yumrepo/el7/x86_64/FastOSrepo-1.0.0-1.el7.centos.x86_64.rpm
CentOS 8
rpm -ivh http://www.fastken.com/yumrepo/el8/x86_64/FastOSrepo-1.0.0-1.el8.x86_64.rpm
2. fastDIR server安装
在需要运行 fastDIR server的服务器上执行:
yum install fastDIR-server -y
3. faststore server安装
在需要运行 faststore server的服务器上执行:
yum install faststore-server -y
4. FastCFS客户端安装
在需要使用FastCFS存储服务的机器(即FastCFS客户端)上执行:
yum remove fuse -y yum install FastCFS-fused -y 注: * fuse为老版本的包(fuse2.x),需要卸载才可以成功安装FastCFS-fused依赖的fuse3; * 第一次安装才需要卸载fuse包,以后就不用执行了。
5. Auth server安装(可选)
如果需要存储池或访问控制,则需要安装本模块。
在需要运行 Auth server的服务器上执行:
yum install FastCFS-auth-server -y
安装完成后,需要修改对应的配置文件,服务才可以正常启动。请参阅配置指南
FastDFS后台程序可通过systemd管理。systemd服务名称如下:
* fastdir: 目录服务,对应程序为 fdir_serverd
* faststore:存储服务,对应程序为 fs_serverd
* fastcfs: FUSE后台服务,对应程序为 fcfs_fused
* fcfs_authd: 认证服务,对应程序为 fcfs_authd
可以使用标准的systemd命令对上述4个服务进行管理,例如:
systemctl restart fastdir systemctl restart faststore systemctl restart fastcfs systemctl restart fcfs_authd