1. 程式人生 > >Centos7上Glusterfs叢集安裝

Centos7上Glusterfs叢集安裝

    如下List-1所示三臺機器,hostname分別是node1/node2/node3,之後將List-1的內容寫入/etc/hosts

    List-1

192.168.33.20 node1
192.168.33.21 node2
192.168.33.22 node3

    安裝glusterfs(三臺都要執行)

    List-2

#安裝glusterfs
yum install centos-release-gluster
yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

#啟動gluster服務
systemctl start glusterd.service
systemctl enable glusterd.service

#關閉防火牆
systemctl stop firewalld.service
systemctl disable firewalld.service

    在node1上執行如下List-3,將node2、node3加入叢集

    List-3

gluster peer probe node2
gluster peer probe node3

    在node1上看叢集狀態,如下List-4

    List-4

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

Hostname: node2
Uuid: ab8dac2f-e5fb-4752-b70d-b0103a40f8ea
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: f13b4732-ae12-4b6c-b4eb-65fd7886588c
State: Peer in Cluster (Connected)

    之後在node1/node2/node3上手動建立目錄/data_gluster。

    之後在node1上,用如下List-5命令建立卷,卷名稱是db_volume:

    List-5

gluster volume create db_volume \
 replica 3 node1:/data_gluster node2:/data_gluster node3:/data_gluster force

    啟用卷,如下List-6

    List-6

gluster start db_volume

    到這裡,可以將db_volume掛載出來就直接使用了,但是我們想將db_volume掛載到分割槽中,所以還需要額外的操作。如下List-7,卷/dev/sdb是我新增的裸磁碟——virtualbox上通過UI新增的。

    List-7

[root@node1 db]# fdisk -l

Disk /dev/sda: 10.5 GB, 10485760000 bytes, 20480000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000927b6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    20479999     9726976   8e  Linux LVM

Disk /dev/sdb: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

...

    如下List-8,由於/dev/sdb是3G的,所以我申請2G

    List-8

vgcreate vg_gluster /dev/sdb
lvcreate -n lv_gluster -L 2G vg_gluster
#格式化
mkfs.ext4 /dev/vg_gluster/lv_gluster

    將/data_gluster掛載到我們建立的盤,如下List-9,

    List-9

echo "/dev/vg_gluster/lv_gluster              /data_gluster                  ext4    defaults        0 0" >> /etc/fstab
mount -a
mount -l | grep gluster

    List-5中我們雖然建立了卷db_volume,但是還不能直接使用,要將其掛載出來,如下List-10,將卷db_volume掛載到/mnt/gluster/db目錄下,我們只能往/mnt/gluster/db裡面寫資料,不能直接操作/data_gluster

    List-10

mkdir -p /mnt/gluster/db
mount -t glusterfs node1:/db_volume /mnt/gluster/db

Reference

  1. https://blog.csdn.net/phn_csdn/article/details