安装部署GlusterFS集群

60 阅读3分钟

介绍

  • GlusterFS是一个开源的分布式文件系统
  • 具有强大的横向扩展能力
  • 通过扩展能够支持数PB存储容量和处理数千客户端
  • GlusterFS借助TCP/IP或InfiniBandRDMA网络将物理分布的存储资源聚集在一起,使用单一全局命名空间来管理数据。

环境

主机系统IP地址硬盘硬盘容量
node1alma linux 9192.168.202.201/dev/nvme0n220G
node2alma linux 9192.168.202.202/dev/nvme0n220G
node3alma linux 9192.168.202.203/dev/nvme0n220G

初始化配置

添加主机之间的解析

node1 node2 node3都配置上去

# 在/etc/hosts文件中添加
cat >> /etc/hosts <<EOF
192.168.202.201 node1
192.168.202.202 node2
192.168.202.203 node3
EOF

配置主机之间免密登录

生成密钥对

[root@node1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:bgixwc/OrDE+raagfvkjAnKkmb3XGI4sLntJXTEwlws root@node1
The key's randomart image is:
+---[RSA 3072]----+
|    o...         |
|   .Eo+          |
|    +. +         |
|  .  *o          |
| * .o.o S        |
|* + o= o         |
|++ =+== o        |
|+o*=*=o.         |
|**++*+.          |
+----[SHA256]-----+

主机之间公钥的复制

[root@node1 ~]# ssh-copy-id root@node1
[root@node1 ~]# ssh-copy-id root@node2
[root@node1 ~]# ssh-copy-id root@node3

硬盘配置

格式化硬盘

所有glusterfs节点都操作

[root@node1 ~]# mkfs.xfs /dev/nvme0n2
meta-data=/dev/nvme0n2           isize=512    agcount=4, agsize=1310720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1
data     =                       bsize=4096   blocks=5242880, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

配置磁盘挂载目录

三台节点上都操作

mkdir /glusterfs

修改/etc/fstab使磁盘自动挂载

cat >> /etc/fstab <<EOF
/dev/nvme0n2   /glusterfs xfs defaults 0 0
EOF

挂载磁盘并查看

# 挂载
[root@node2 ~]# mount -a
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.
       
# 查看磁盘
[root@node2 ~]# lsblk
NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0                     11:0    1  1.7G  0 rom  
nvme0n1                259:0    0   60G  0 disk 
├─nvme0n1p1            259:1    0    1G  0 part /boot
└─nvme0n1p2            259:2    0   59G  0 part 
  ├─almalinux_192-root 253:0    0 55.1G  0 lvm  /
  └─almalinux_192-swap 253:1    0  3.9G  0 lvm  [SWAP]
nvme0n2                259:3    0   20G  0 disk /glusterfs

安装GlusterFS

安装所需依赖包

dnf install lvm2 -y

安装软件源

dnf install centos-release-gluster9 -y

安装GlusterFS服务

dnf install glusterfs glusterfs-libs glusterfs-server -y

启动服务

systemctl enable glusterfsd.service glusterd.service
systemctl start glusterfsd.service glusterd.service

将节点添加到相同的pool中

gluster peer probe node2
gluster peer probe node3

查看状态

[root@node1 ~]# gluster peer status
Number of Peers: 2

Hostname: node3
Uuid: 32342c43-ca1c-4fee-8dca-0ba54e584349
State: Peer in Cluster (Connected)

Hostname: node2
Uuid: 31628e38-e6c2-4c0c-bee2-17b14eba5fed
State: Peer in Cluster (Connected)

参考文档