一、centos系统使用
安装客户端组件
yum -y install glusterfs glusterfs-fuse
修改hosts文件
#增加glusterfs节点的解析,不然会挂载不上,即使直接使用ip地址也挂载不上
echo "10.1.60.126 ceph01" >> /etc/hosts
echo "10.1.60.127 ceph02" >> /etc/hosts
echo "10.1.60.128 ceph03" >> /etc/hosts
创建挂载目录
mkdir /glusterfs
直接挂载
mount -t glusterfs ceph01:nacos /glusterfs
mount -t glusterfs 节点名称或者ip:volume名称 挂载目录
#填写任意节点地址即可,节点故障会自动检测切换
更改fstab文件自动挂载
echo "ceph01:/nacos /glusterfs glusterfs defaults 0 0" >> /etc/fstab
使配置生效
mount -a
挂载时也可以增加一些客户端参数
backupvolfile-server=server-name:这个参数指定了备份 volfile 的服务器名称。Volfile 是 GlusterFS 卷的卷文件,包含有关卷的配置信息。指定 backupvolfile-server 可以使客户端在主服务器不可用时从备份服务器获取 volfile
volfile-max-fetch-attempts=number of attempts:这个参数指定了获取 volfile 的最大尝试次数。当客户端无法从主服务器或备份服务器获取 volfile 时,它将尝试多次获取,直到达到指定的尝试次数为止
log-level=loglevel:这个参数设置客户端的日志级别。loglevel 可以是各种日志级别,例如 DEBUG、INFO、WARNING、ERROR 等。通过设置适当的日志级别,可以控制日志的详细程度
log-file=logfile:这个参数指定了日志文件的路径和名称。当客户端启用了日志记录时,日志消息将被写入指定的日志文件中
transport=transport-type:这个参数指定了客户端与 GlusterFS 服务器之间的传输类型。transport-type 可以是 tcp、rdma 等。通过设置适当的传输类型,可以优化数据传输性能和网络连接
direct-io-mode=[enable|disable]:这个参数指定了是否启用直接 I/O 模式。直接 I/O 模式可以绕过客户端的缓存,直接读取和写入磁盘。启用直接 I/O 可以提高性能,特别是对于大型文件的读写操作
use-readdirp=[yes|no]:这个参数指定了是否启用 readdirp 协议来进行目录遍历。readdirp 协议允许客户端一次性获取多个目录项,从而减少与服务器的通信次数。启用 readdirp 可以提高目录遍历的性能
也可以参考官网:Setting Up Clients - Gluster Docs
以上参数使用mount时可以通过-o指定,多个参数用,间隔
mount -t glusterfs -o backupvolfile-server=ceph02,volfile-max-fetch-attempts=2 ceph01:/nacos /glusterfs
使用fstab方式挂载时指定参数
ceph01:/nacos /glusterfs glusterfs defaults,backupvolfile-server=ceph02,volfile-max-fetch-attempts=2 0 0
二、k8s使用
glusterfs在k8s中v1.25 版本中被弃用,然后在 v1.26 版本中被完全移除,只能在1.25之前的版本使用,使用glusterfs作为pv存储需要使用到endpoint、service、pv、pvc服务
在k8s所有节点安装基础环境
yum -y install glusterfs glusterfs-fuse
在k8s所有节点编辑hosts文件
echo "10.1.60.126 ceph01" >> /etc/hosts
echo "10.1.60.127 ceph02" >> /etc/hosts
echo "10.1.60.128 ceph03" >> /etc/hosts
endpoint.yaml
apiVersion: v1
kind: Endpoints
metadata:
name: glusterfs
subsets:
- addresses:
- ip: 10.1.60.126
ports:
- port: 1234 #根据官方文档所说填写1-65536任意端口都可以
- addresses:
- ip: 10.1.60.127
ports:
- port: 1234
- addresses:
- ip: 10.1.60.128
ports:
- port: 1234
service.yaml
apiVersion: v1
kind: Service
metadata:
name: glusterfs #与endpoint名称相同
spec:
ports:
- port: 1234
pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: glusterfs-pv
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: nacos
glusterfs:
endpoints: glusterfs
endpointsNamespace: default
path: nacos #glusterfs的卷名称
readOnly: false
pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: glusterfs-pvc
spec:
accessModes:
- ReadWriteMany
volumeMode: Filesystem
resources:
requests:
storage: 5Gi
storageClassName: nacos
使用glusterfs的pv
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: nginx
ports:
- name: nginx
containerPort: 80
volumeMounts:
- name: pvc-volume
mountPath: /var/log/nginx
volumes:
- name: pvc-volume
persistentVolumeClaim:
claimName: glusterfs-pvc
readOnly: false