一:前言GlusterFS是Scale-Out存储解决方案Gluster的核心,它是一个开源的分布式文件系统,具有强大的横向扩展能力,通过扩展能够支持数PB存储容量和处理数千客户端。GlusterFS借助TCP/IP或InfiniBand RDMA网络将物理分布的存储资源聚集在一起,使用单一全局命名空间来管理数据。GlusterFS基于可堆叠的用户空间设计,可为各种不同的数据负载提供优异的性能。
服务器:
10.116.137.196 k8s_master
10.116.82.28 k8s_node1
10.116.36.57 k8s_node2
二:安装glusterfs我们直接在物理机上使用yum安装,在三台服务器上分别执行以下安装命令。
1.先安装 gluster 源yum install centos-release-gluster -y
2.安装 glusterfs 组件yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma glusterfs-geo-replication glusterfs-devel
3.创建 glusterfs 目录mkdir /mnt/glusterd
4.修改 glusterd 目录 点击(此处)折叠或打开
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、做网站、成都外贸网站建设公司、稷山网络推广、重庆小程序开发、稷山网络营销、稷山企业策划、稷山品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供稷山建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com
-
volume management
-
type mgmt/glusterd
-
option working-directory /mnt/glusterd
-
option transport-type socket,rdma
-
option transport.socket.keepalive-time 10
-
option transport.socket.keepalive-interval 2
-
option transport.socket.read-fail-log off
-
option ping-timeout 0
-
option event-threads 1
-
#option lock-timer 180
-
#option transport.address-family inet6
-
#option base-port 49152
-
end-volume
5.启动glusterfssystemctl enable glusterd.service
systemctl start glusterd.service
systemctl status glusterd.service
三:配置 glusterfs1.开放端口iptables -I INPUT -p tcp --dport 24007 -j ACCEPT
2.创建存储目录mkdir /opt/gfs_data
3.添加节点到集群在10.116.137.196上执行以下操作:
gluster peer probe 10.116.82.28
gluster peer probe 10.116.36.57
4.查看集群状态gluster peer status
-
Number of Peers: 2
-
-
Hostname: 10.116.82.28
-
Uuid: f73138ca-e32e-4d87-a99d-cf842fc29447
-
State: Peer in Cluster(Connected)
-
-
Hostname: 10.116.36.57
-
Uuid: 18e22d2c-049b-4b0c-8cc7-2560319e6c05
-
State: Peer in Cluster(Connected)
-
[root@iZwz95trb3stk6afg8oozuZ kubernetes]#clear
-
[root@iZwz95trb3stk6afg8oozuZ kubernetes]# glustervolume create k8s-volume transport tcp 10.116.137.196:/mnt/gfs_data 10.116.82.28:/mnt/gfs_data 10.116.36.57:/mnt/gfs_data force
-
volume create: k8s-volume: success: please start thevolume to access data
-
[root@iZwz95trb3stk6afg8oozuZ kubernetes]# glustervolume info
-
-
Volume Name: k8s-volume
-
Type: Distribute
-
Volume ID: 62900029-02c9-4870-951c-38fafd5f5d9b
-
Status: Created
-
Snapshot Count: 0
-
Number of Bricks: 3
-
Transport-type: tcp
-
Bricks:
-
Brick1: 10.116.137.196:/mnt/gfs_data
-
Brick2: 10.116.82.28:/mnt/gfs_data
-
Brick3: 10.116.36.57:/mnt/gfs_data
-
Options Reconfigured:
-
transport.address-family: inet
-
nfs.disable: on
四:配置 volume1.volume的模式a.分布卷(默认模式):即DHT, 也叫 分布卷: 将文件已hash算法随机分布到 一台服务器节点中存储。
b.复制模式:即AFR, 创建volume 时带 replica x 数量: 将文件复制到 replica x 个节点中。
c.条带模式:即Striped, 创建volume 时带 stripe x 数量: 将文件切割成数据块,分别存储到 stripe x 个节点中 ( 类似raid 0 )。
d.分布式条带模式:最少需要4台服务器才能创建。 创建volume 时 stripe 2 server = 4 个节点: 是DHT 与 Striped 的组合型。
e.分布式复制模式:最少需要4台服务器才能创建。 创建volume 时 replica 2 server = 4 个节点:是DHT 与 AFR 的组合型。
f.条带复制卷模式:最少需要4台服务器才能创建。 创建volume 时 stripe 2 replica 2 server = 4 个节点: 是 Striped 与 AFR 的组合型。
g.三种模式混合: 至少需要8台 服务器才能创建。 stripe 2 replica 2 , 每4个节点 组成一个 组。
2.创建分布卷gluster volume create k8s-volume transport tcp 10.116.137.196:/mnt/gfs_data 10.116.82.28:/mnt/gfs_data 10.116.36.57:/mnt/gfs_data force
3.查看volume状态gluster volume info
-
Volume Name: k8s-volume
-
Type: Distribute
-
Volume ID: 62900029-02c9-4870-951c-38fafd5f5d9b
-
Status: Created
-
Snapshot Count: 0
-
Number of Bricks: 3
-
Transport-type: tcp
-
Bricks:
-
Brick1: 10.116.137.196:/mnt/gfs_data
-
Brick2: 10.116.82.28:/mnt/gfs_data
-
Brick3: 10.116.36.57:/mnt/gfs_data
-
Options Reconfigured:
-
transport.address-family: inet
-
nfs.disable: on
4.启动分布卷gluster volume start k8s-volume
五:Glusterfs调优1.开启指定volume的配额gluster volume quota k8s-volume enable
2.限制指定volume的配额gluster volume quota k8s-volume limit-usage / 5GB
3.设置cache大小, 默认32MBgluster volume set k8s-volume performance.cache-size 64MB
4.设置io线程, 太大会导致进程崩溃gluster volume set k8s-volume performance.io-thread-count 16
5.设置网络检测时间, 默认42sgluster volume set k8s-volume network.ping-timeout 10
6.设置写缓冲区的大小, 默认1Mgluster volume set k8s-volume performance.write-behind-window-size 512MB
六:Kubernetes中配置glusterfs1.配置 endpoints(glusterfs-endpoints.json)
-
{
-
"kind": "Endpoints",
-
"apiVersion": "v1",
-
"metadata": {
-
"name": "glusterfs-cluster"
-
},
-
"subsets": [
-
{
-
"addresses": [
-
{
-
"ip": "10.116.137.196"
-
}
-
],
-
"ports": [
-
{
-
"port": 1990
-
}
-
]
-
}
-
]
-
}
kubectl apply -f glusterfs-endpoints.json
2.配置 service(glusterfs-service.json)
-
{
-
"kind": "Service",
-
"apiVersion": "v1",
-
"metadata": {
-
"name": "glusterfs-cluster"
-
},
-
"spec": {
-
"ports": [
-
{"port": 1990}
-
]
-
}
-
}
kubectl apply -f glusterfs-service.json
3.创建测试 pod
-
{
-
"apiVersion": "v1",
-
"kind": "Pod",
-
"metadata": {
-
"name": "glusterfs"
-
},
-
"spec": {
-
"containers": [
-
{
-
"name": "glusterfs",
-
"image": "registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0",
-
"volumeMounts": [
-
{
-
"mountPath": "/mnt/glusterfs",
-
"name": "glusterfsvol"
-
}
-
]
-
}
-
],
-
"volumes": [
-
{
-
"name": "glusterfsvol",
-
"glusterfs": {
-
"endpoints": "glusterfs-cluster",
-
"path": "k8s-volume",
-
"readOnly": true
-
}
-
}
-
]
-
}
-
}
kubectl apply -f glusterfs-pod.json 在Pod所在的Node节点上执行 df -h 可以查看k8s-volume挂载目录
4.配置PersistentVolume(glusterfs-pv.yaml)
-
apiVersion: v1
-
kind: PersistentVolume
-
metadata:
-
name: gluster-dev-volume
-
spec:
-
capacity:
-
storage: 1Gi
-
accessModes:
-
- ReadWriteMany
-
glusterfs:
-
endpoints: "glusterfs-cluster"
-
path: "k8s-volume"
-
readOnly: false
kubectl apply -f glusterfs-pv.yaml
5.配置PVC(glusterfs-pvc.yaml)
-
kind: PersistentVolumeClaim
-
apiVersion: v1
-
metadata:
-
name: glusterfs-nginx
-
spec:
-
accessModes:
-
- ReadWriteMany
-
resources:
-
requests:
-
storage: 1Gi
kubectl apply -f glusterfs-pvc.yaml
6.创建nginx deployment 挂载 volume(nginx-deployment.yaml)
-
apiVersion: extensions/v1beta1
-
kind: Deployment
-
metadata:
-
name: nginx-dm
-
spec:
-
replicas: 2
-
template:
-
metadata:
-
labels:
-
name: nginx
-
spec:
-
containers:
-
- name: nginx
-
image: nginx:latest
-
imagePullPolicy: IfNotPresent
-
ports:
-
- containerPort: 80
-
volumeMounts:
-
- name: gluster-dev-volume
-
mountPath: "/usr/share/nginx/html"
-
volumes:
-
- name: gluster-dev-volume
-
persistentVolumeClaim:
-
claimName: glusterfs-nginx
kubectl apply -f nginx-deployment.yaml
a.查看 deployment
kubectl get pods |grep nginx-dm
-
nginx-dm-64dcbb8d55-pp9vn 1/1 Running 0 1h
-
nginx-dm-64dcbb8d55-sclj6 1/1 Running 0 1h
b.查看挂载
kubectl exec -it nginx-dm-64dcbb8d55-pp9vn -- df -h
-
FilesystemSize Used Avail Use% Mounted on
-
overlay 40G 23G 16G 60% /
-
tmpfs 3.7G 0 3.7G 0% /dev
-
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
-
/dev/xvda1 40G 23G 16G 60% /etc/hosts
-
shm 64M 0 64M 0% /dev/shm
-
10.116.137.196:k8s-volume 5.0G 0 5.0G 0% /usr/share/nginx/html
-
tmpfs 3.7G 12K 3.7G 1% /run/secrets/kubernetes.io/serviceaccount
c.创建文件测试
kubectl exec -it nginx-dm-64dcbb8d55-pp9vn -- touch /usr/share/nginx/html/index.html
kubectl exec -it nginx-dm-64dcbb8d55-sclj6 -- ls -lt /usr/share/nginx/html/index.html
d.验证 glusterfs
因为我们使用分布卷,所以可以看到某个节点中有文件
ls /mnt/gfs_data/
index.html
网站题目:kubernetes实践之二十六:GlusterFS
网站地址:
http://cdxtjz.cn/article/pgpdie.html