linux 的RHCS实现共享储存

一、共享存储的iscsi

实验环境:

server1   172.25.37.1   

server2   172.25.37.2

server3   172.25.37.3      iscsi共享机

1.在server3上添加一块虚拟硬盘,大小为20G,并且在server1、server2上安装上iscsi服务。

linux 的RHCS实现共享储存_第1张图片

[root@server1 html]# yum install iscsi-* -y

[root@server2 html]# yum install iscsi-* -y

[root@server3 ~]# yum install scsi-* -y

server3:

[root@server3 ~]# vim /etc/tgt/targets.conf

 38 
 39     backing-store /dev/vda
 40     initiator-address 172.25.37.1
 41     initiator-address 172.25.37.2
 42 

[root@server3 ~]# tgt-admin -s

linux 的RHCS实现共享储存_第2张图片

2.server1、server2登陆iscsi服务

server1:

[root@server1 ~]# iscsiadm -m discovery -t st -p 172.25.37.3
Starting iscsid:                                           [  OK  ]
172.25.37.3:3260,1 iqn.2019-01.com.example:server.target1
[root@server1 ~]#
[root@server1 ~]# iscsiadm -m node -l
Logging in to [iface: default, target: iqn.2019-01.com.example:server.target1, portal: 172.25.37.3,3260] (multiple)
Login to [iface: default, target: iqn.2019-01.com.example:server.target1, portal: 172.25.37.3,3260] successful.
[root@server1 ~]# fdisk -l

linux 的RHCS实现共享储存_第3张图片

server2:

[root@server2 html]#  iscsiadm -m discovery -t st -p 172.25.37.3
Starting iscsid:                                           [  OK  ]
172.25.37.3:3260,1 iqn.2019-01.com.example:server.target1
[root@server2 html]#
[root@server2 html]#  iscsiadm -m node -l
Logging in to [iface: default, target: iqn.2019-01.com.example:server.target1, portal: 172.25.37.3,3260] (multiple)
Login to [iface: default, target: iqn.2019-01.com.example:server.target1, portal: 172.25.37.3,3260] successful.
[root@server2 html]# fdisk -l

linux 的RHCS实现共享储存_第4张图片

3.创建LVM

server1:

[root@server1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xbef61118.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-20480, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480): +8G

Command (m for help): t
Hex code (type L to list codes): l

 86  NTFS volume set da  Non-FS data    
 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   
 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt         

Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 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: 0xbef61118

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        8193     8389616   8e  Linux LVM

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@server1 ~]# partprobe 
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
[root@server1 ~]# fdisk -l
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 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: 0xbef61118

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        8193     8389616   8e  Linux LVM
[root@server1 ~]# 

linux 的RHCS实现共享储存_第5张图片

[root@server1 ~]# pvcreate /dev/sdb1
  dev_is_mpath: failed to get device for 8:17
  Physical volume "/dev/sdb1" successfully created
[root@server1 ~]# vgcreate vg0 /dev/sdb1 
  Clustered volume group "vg0" successfully created
[root@server1 ~]# lvcreate -L 5G -n lv0 vg0
Logical volume "lv_qq" created

4.格式化、挂载:

[root@server1 ~]# mkfs.ext4 /dev/vg0/lv_qq 
[root@server1 ~]# mount /dev/vg0/lv_qq /mnt/
[root@server1 ~]# cd /mnt 
[root@server1 ~]# ls
[root@server1 ~]#  lost+found
[root@server1 ~]#  vim index.html
www.westos.org

5.设置集群

linux 的RHCS实现共享储存_第6张图片

6.添加资源:(先添加ip、文件系统、脚本)

linux 的RHCS实现共享储存_第7张图片

linux 的RHCS实现共享储存_第8张图片

linux 的RHCS实现共享储存_第9张图片

[root@server1 ~]# clustat

 测试:

先手动关掉server1、集群自动启动server2。

 

7.设置共享磁盘为gfs2格式

1.创建一个新的LVM 并格式化

linux 的RHCS实现共享储存_第10张图片

[root@server1 ~]#  clusvcadm -d apache
Local machine disabling service:apache...Success
[root@server1 ~]# 
[root@server1 ~]# mkfs.gfs2 -p lock_dlm -j 3 -t westos_dd:mygfs2 /dev/vg_dang/node 
This will destroy any data on /dev/vg_dang/node.
It appears to contain: symbolic link to `../dm-3'

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

Device:                    /dev/vg_dang/node
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:                "westos_dd:mygfs2"
UUID:                      66a89fed-c6d4-cfe8-38e8-4bd6b9118945

 linux 的RHCS实现共享储存_第11张图片

2.开机自动挂在

[root@server1 ~]# vim /etc/fstab

/dev/vg_dang/node       /var/www/html           gfs2    _netdev         0 0

[root@server1 ~]# mount -a
[root@server1 ~]# 

测试:

[root@server1 ~]#  cd /var/www/html/
[root@server1 html]# vim index.html

qweqwe

[root@foundation37 ~]# curl 172.25.37.100


 

你可能感兴趣的:(linux 的RHCS实现共享储存)