34补3-4 rhcs之gfs2和clvm

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了34补3-4 rhcs之gfs2和clvm相关的知识,希望对你有一定的参考价值。

04 rhcs之gfs2和clvm


使用共享存储创建高可用集群


[[email protected] ~]# yum -y install scsi-target-utils

[[email protected] ~]# vim /etc/tgt/targets.conf 

在末尾添加

<target iqn.2015-01.com.magedu:node4.t1>

backing-store /dev/sda4

initiator-address 192.168.1.0/24

</target>

[[email protected] ~]# fdisk /dev/sda #创建sda4,并分配50Gp分区

[[email protected] ~]# partx -a /dev/sda

[[email protected] ~]# service tgtd start

[[email protected] ~]# tgtadm -L iscsi -m target -o show

#安装软件

[[email protected] ~]# yum -y install iscsi-initiator-utils;echo "InitiatorName=`iscsi-iname -p iqn.2015-01.com.magedu`" >/etc/iscsi/initiatorname.iscsi

[[email protected] ~]# yum -y install iscsi-initiator-utils;echo "InitiatorName=`iscsi-iname -p iqn.2015-01.com.magedu`" >/etc/iscsi/initiatorname.iscsi

[[email protected] ~]# yum -y install iscsi-initiator-utils;echo "InitiatorName=`iscsi-iname -p iqn.2015-01.com.magedu`" >/etc/iscsi/initiatorname.iscsi

#启动服务

[[email protected] ~]# service iscsi start ;service iscsid start

[[email protected] ~]# service iscsi start ;service iscsid start

[[email protected] ~]# service iscsi start ;service iscsid start

#发现存储设备

[[email protected] ~]# iscsiadm -m discovery -t st -p 192.168.1.154

[[email protected] ~]# iscsiadm -m discovery -t st -p 192.168.1.154

[[email protected] ~]# iscsiadm -m discovery -t st -p 192.168.1.154

#登录

[[email protected] ~]# iscsiadm -m node -T iqn.2015-01.com.magedu:node4.t1 -p 192.168.1.154 -l

[[email protected] ~]# iscsiadm -m node -T iqn.2015-01.com.magedu:node4.t1 -p 192.168.1.154 -l

[[email protected] ~]# iscsiadm -m node -T iqn.2015-01.com.magedu:node4.t1 -p 192.168.1.154 -l

#安装GFS2

[[email protected] ~]# yum -y install gfs2-utils

[[email protected] ~]# yum -y install gfs2-utils

[[email protected] ~]# yum -y install gfs2-utils

装载gfs2

[[email protected] ~]# modprobe gfs2

[[email protected] ~]# lsmod | grep gfs2

gfs2                  548432  0 

dlm                   148231  22 gfs2

[[email protected] ~]# fdisk /dev/sdb #创建两个20G的分区

[[email protected] ~]# fdisk -l /dev/sdb


Disk /dev/sdb: 53.7 GB, 53691549696 bytes

64 heads, 32 sectors/track, 51204 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xabd7f733


  Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1       20481    20972528   83  Linux

/dev/sdb2           20482       40962    20972544   83  Linux

#创建gfs2集群文件系统

[[email protected] ~]# mkfs.gfs2 -j 2 -p lock_dlm -t tcluster:sdb1 /dev/sdb1

This will destroy any data on /dev/sdb1.

It appears to contain: data


Are you sure you want to proceed? [y/n] y


Device:                    /dev/sdb1

Blocksize:                 4096

Device Size                20.00 GB (5243132 blocks)

Filesystem Size:           20.00 GB (5243131 blocks)

Journals:                  2

Resource Groups:           81

Locking Protocol:          "lock_dlm"

Lock Table:                "tcluster:sdb1"

UUID:                      aebcc094-7b50-3df9-da3c-537894310e47


[[email protected] ~]# tunegfs2 /dev/sdb1

[[email protected] ~]# tunegfs2 -l /dev/sdb1

tunegfs2 (May 11 2016 09:59:26)

Filesystem volume name: tcluster:sdb1

Filesystem UUID: aebcc094-7b50-3df9-da3c-537894310e47

Filesystem magic number: 0x1161970

Block size: 4096

Block shift: 12

Root inode: 22

Master inode: 23

Lock Protocol: lock_dlm

Lock table: tcluster:sdb1

#node1节点挂载gfs2分区

[[email protected] ~]# mkdir -p /cluster/data

[[email protected] ~]# mount -t gfs2 /dev/sdb1 /cluster/data/

[[email protected] ~]# mount

/dev/sda2 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

none on /sys/kernel/config type configfs (rw)

/dev/sdb1 on /cluster/data type gfs2 (rw,relatime,hostdata=jid=0)

#显示日志区域

[[email protected] ~]# gfs2_tool journals /dev/sdb1

journal1 - 128MB

journal0 - 128MB

2 journal(s) found.

#node2节点挂载gfs2分区

[[email protected] ~]# mkdir -p /cluster/data

[[email protected] ~]# partx -a /dev/sdb

[[email protected] ~]# mount -t gfs2 /dev/sdb1 /cluster/data/

[[email protected] ~]# mount

/dev/sda2 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

none on /sys/kernel/config type configfs (rw)

/dev/sdb1 on /cluster/data type gfs2 (rw,relatime,hostdata=jid=1)

#测试1:在node2结点中复制文件

[[email protected] ~]# cd /cluster/data/

[[email protected] data]# cp /etc/fstab .

[[email protected] ~]# cd /cluster/data/

[[email protected] data]# ls

fstab

结果:node2中gfs2分区中添加的文件在node1中可以同步查看

#测试2:在node1结点中删除node2结点中复制文件的内容

[[email protected] data]# vim fstab

删除最后四行

在node2结点查看该文件时发现其最后四行内容已被删除

#node3节点挂载gfs2分区

[[email protected] ~]# mkdir -p /cluster/data

[[email protected] ~]# partx -a /dev/sdb 

[[email protected] ~]# mount -t gfs2 /dev/sdb1 /cluster/data/

Too many nodes mounting filesystem, no free journals

#发现挂载点不够无法挂载

#解决办法,在其他已经挂载的结点上执行

[[email protected] data]# gfs2_jadd -j 1 /dev/sdb1

Filesystem:            /cluster/data

Old Journals           2

New Journals           3

#重新在node3结点上挂载

[[email protected] ~]# mount -t gfs2 /dev/sdb1 /cluster/data/

[[email protected] ~]# mount

/dev/sda2 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

none on /sys/kernel/config type configfs (rw)

/dev/sdb1 on /cluster/data type gfs2 (rw,relatime,hostdata=jid=2)

#挂载成功

#冻结GFS2结点

[[email protected] ~]# gfs2_tool freeze /cluster/data/

[[email protected] ~]# mount

/dev/sda2 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

none on /sys/kernel/config type configfs (rw)

/dev/sdb1 on /cluster/data type gfs2 (rw,relatime,hostdata=jid=1)

#结点被冻结后,该结点可以读数据,但无法向其写数据

#解冻被冻结的结点

[[email protected] ~]# gfs2_tool unfreeze /cluster/data/

[[email protected] data]# yum -y install lvm2-cluster

[[email protected] data]# yum -y install lvm2-cluster

[[email protected] data]# yum -y install lvm2-cluster

#启用逻辑卷的集群功能

[[email protected] data]# lvmconf --enable-cluster

[[email protected] data]# lvmconf --enable-cluster

[[email protected] data]# lvmconf --enable-cluster

#启动集群逻辑卷服务

[[email protected] ~]# service clvmd start

[[email protected] ~]# service clvmd start

[[email protected] ~]# service clvmd start

[[email protected] data]# fdisk /dev/sdb


WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to

switch off the mode (command ‘c‘) and change display units to

sectors (command ‘u‘).


Command (m for help): t

Partition number (1-4): 2

Hex code (type L to list codes): 8e

Changed system type of partition 2 to 8e (Linux LVM)


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[[email protected] data]# partx -a /dev/sdb

[[email protected] data]# pvcreate /dev/sdb2

[[email protected] data]# vgcreate cvg /dev/sdb2

[[email protected] data]# lvcreate -L 10G -n clv cvg

[[email protected] data]# mkfs.gfs2 -j 3 -t tcluster:clv -p lock_dlm /dev/cvg/clv

This will destroy any data on /dev/cvg/clv.

It appears to contain: symbolic link to `../dm-0‘


Are you sure you want to proceed? [y/n] y


Device:                    /dev/cvg/clv

Blocksize:                 4096

Device Size                10.00 GB (2621440 blocks)

Filesystem Size:           10.00 GB (2621438 blocks)

Journals:                  3

Resource Groups:           40

Locking Protocol:          "lock_dlm"

Lock Table:                "tcluster:clv"

UUID:                      1c42a8f1-5d14-5982-891f-3ce0faaa2123

[[email protected] ~]# mount -t gfs2 /dev/cvg/clv /mnt/

[[email protected] ~]# mount

/dev/sda2 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

none on /sys/kernel/config type configfs (rw)

/dev/sdb1 on /cluster/data type gfs2 (rw,relatime,hostdata=jid=2)

/dev/mapper/cvg-clv on /mnt type gfs2 (rw,relatime,hostdata=jid=0)

#扩展逻辑卷

#1)物理扩展

[[email protected] ~]# lvextend -L +5G /dev/cvg/clv 

#2)逻辑扩展

[[email protected] ~]# gfs2_grow  /dev/cvg/clv


本文出自 “追梦” 博客,请务必保留此出处http://sihua.blog.51cto.com/377227/1861954

以上是关于34补3-4 rhcs之gfs2和clvm的主要内容,如果未能解决你的问题,请参考以下文章

RHEL6+GFS2+MYSQL高可用

34补3-3 rhcs集群基础应用

34补3-3 rhcs集群基础应用

RHCS实验之openfiler存储配置

Elasticsearch之自动补全案例实战

管理和维护RHCS集群