###RHCS高可用集群下的ISCSI磁盘共享###

###磁盘共享###
generic3添加一块虚拟磁盘
在这里插入图片描述

[root@generic3 ~]# fdisk -l  ##查看磁盘
Disk /dev/vda: 21.5 GB, 21474836480 bytes  ##添加的磁盘/dev/vda
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@generic3 yum.repos.d]# yum install -y scsi-*  ##三台主机都要安装该软件
[root@generic3 yum.repos.d]# vim /etc/tgt/targets.conf   ##编辑磁盘共享配置文件
<target iqn.2019-06.com.example:server.target1>
    backing-store /dev/vda
</target>
[root@generic3 yum.repos.d]# /etc/init.d/tgtd start  #启动服务
Starting SCSI target daemon:                               [  OK  ]
[root@generic3 yum.repos.d]# tgt-admin -s
         Backing store flags: 
    Account information:
    ACL information:
      ALL
[root@generic3 yum.repos.d]# ps ax
1148 ?        Ssl    0:00 tgtd
 1151 ?        S      0:00 tgtd

配置服务端:
generic1:

[root@generic1 ~]# /etc/init.d/httpd stop  #关闭httpd
Stopping httpd:                                            [  OK  ]
[root@generic1 ~]# /etc/init.d/httpd status
httpd is stopped
[root@generic1 ~]# yum install -y iscsi-*  ##安装iscsi
[root@generic1 ~]# iscsiadm -m discovery -t st -p 172.25.40.112  #发现共享设备
Starting iscsid:                                           [  OK  ]
172.25.40.112:3260,1 iqn.2019-06.com.example:server.target1
[root@generic1 ~]# iscsiadm -m node -l  ##连接共享设备
Logging in to [iface: default, target: iqn.2019-06.com.example:server.target1, portal: 172.25.40.112,3260] (multiple)
Login to [iface: default, target: iqn.2019-06.com.example:server.target1, portal: 172.25.40.112,3260] successful.
[root@generic1 ~]# 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: 0x00000000
[root@generic1 ~]# cat /proc/partitions 
major minor  #blocks  name

   8        0   20971520 sda
   8        1     512000 sda1
   8        2   20458496 sda2
 253        0   19439616 dm-0
 253        1    1015808 dm-1
   8       16   20971520 sdb


generic2:

[root@generic2 html]# yum install -y iscsi-*
[root@generic2 ~]#  iscsiadm -m discovery -t st -p 172.25.40.112
Starting iscsid:                                           [  OK  ]
172.25.40.112:3260,1 iqn.2019-06.com.example:server.target1
[root@generic2 ~]# iscsiadm -m node -l
Logging in to [iface: default, target: iqn.2019-06.com.example:server.target1, portal: 172.25.40.112,3260] (multiple)
Login to [iface: default, target: iqn.2019-06.com.example:server.target1, portal: 172.25.40.112,3260] successful.
[root@generic2 ~]# 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: 0x00000000
[root@generic2 ~]# cat /proc/partitions 
major minor  #blocks  name

   8        0   20971520 sda
   8        1     512000 sda1
   8        2   20458496 sda2
 253        0   19439616 dm-0
 253        1    1015808 dm-1
   8       16   20971520 sdb

generic1将共享的磁盘划分一个lvm分区

[root@generic1 ~]# fdisk -cu /dev/sdb
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039

Command (m for help): t
Selected partition 1
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, total 41943040 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 identifier: 0xe2e83306

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   8e  Linux LVM

Command (m for help): wq
The pa[root@generic1 ~]# 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@generic1 ~]# cat /proc/partitions   ##查看设备
major minor  #blocks  name

   8        0   20971520 sda
   8        1     512000 sda1
   8        2   20458496 sda2
 253        0   19439616 dm-0
 253        1    1015808 dm-1
   8       16   20971520 sdb
   8       17   20970496 sdb1
[root@generic1 ~]# pvcreate /dev/sdb1
  dev_is_mpath: failed to get device for 8:17
  Physical volume "/dev/sdb1" successfully created
[root@generic1 ~]# pvs
  PV         VG       Fmt  Attr PSize  PFree 
  /dev/sda2  VolGroup lvm2 a--  19.51g     0 
  /dev/sdb1           lvm2 a--  20.00g 20.00g
[root@generic1 ~]# vgcreate vg0 /dev/sdb1
  Clustered volume group "vg0" successfully created
[root@generic1 ~]# vgs
  VG       #PV #LV #SN Attr   VSize  VFree 
  VolGroup   1   2   0 wz--n- 19.51g     0 
  vg0        1   0   0 wz--nc 20.00g 20.00g
[root@generic1 ~]# lvcreate -L 5G -n lv0 vg0
  Logical volume "lv0" created
[root@generic1 ~]# lvs
  LV      VG       Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root VolGroup -wi-ao----  18.54g                                             
  lv_swap VolGroup -wi-ao---- 992.00m                                             
  lv0     vg0      -wi-a-----   5.00g      rtition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

generic2此时也会同步更新

[root@generic2 ~]# 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@generic2 ~]# cat /proc/partitions 
major minor  #blocks  name

   8        0   20971520 sda
   8        1     512000 sda1
   8        2   20458496 sda2
 253        0   19439616 dm-0
 253        1    1015808 dm-1
   8       16   20971520 sdb
   8       17   20970496 sdb1
[root@generic2 ~]# pvs
  PV         VG       Fmt  Attr PSize  PFree 
  /dev/sda2  VolGroup lvm2 a--  19.51g     0 
  /dev/sdb1           lvm2 a--  20.00g 20.00g
[root@generic2 ~]# vgs
  VG       #PV #LV #SN Attr   VSize  VFree 
  VolGroup   1   2   0 wz--n- 19.51g     0 
  vg0        1   1   0 wz--nc 20.00g 15.00g
[root@generic2 ~]# lvs
  LV      VG       Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root VolGroup -wi-ao----  18.54g                                             
  lv_swap VolGroup -wi-ao---- 992.00m                                             
  lv0     vg0      -wi-a-----   5.00g         

格式化磁盘
在这里插入图片描述

[root@generic1 ~]# mount /dev/vg0/lv0 /mnt/  #
[root@generic1 ~]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  19134332 1108516  17053836   7% /
tmpfs                           251136   25656    225480  11% /dev/shm
/dev/sda1                       495844   33474    436770   8% /boot
/dev/mapper/vg0-lv0            5160576  141304   4757128   3% /mnt
[root@generic1 ~]# cp /etc/passwd /mnt/
[root@generic1 ~]# cd /mnt/
[root@generic1 mnt]# ls
lost+found  passwd
[root@generic1 mnt]# cat passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

generic2 在复制文件后重新挂载才可以看到passwd文件

[root@generic2 ~]# mount /dev/vg0/lv0 /mnt/  ##generic1复制文件之前挂载
[root@generic2 ~]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  19134332 1053128  17109224   6% /
tmpfs                           251136   25656    225480  11% /dev/shm
/dev/sda1                       495844   33474    436770   8% /boot
/dev/mapper/vg0-lv0            5160576  141304   4757128   3% /mnt
[root@generic2 ~]# cd /mnt/  ##generic1复制文件之后也查看不到
[root@generic2 mnt]# ls
lost+found
[root@generic2 ~]# umount /mnt/  ##卸载重挂载
[root@generic2 ~]# mount /dev/vg0/lv0 /mnt/
[root@generic2 ~]# cd /mnt/
[root@generic2 mnt]# ls  ##可以看到passwd文件但不能访问其中的内容
ls: cannot access passwd: Input/output error
lost+found  passwd
[root@generic2 mnt]# cat passwd 
cat: passwd: Input/output error

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[root@generic1 html]# mount /dev/vg0/lv0 /mnt/
root@generic1 html]# cd /mnt/
[root@generic1 mnt]# ls
lost+found
[root@generic1 mnt]# vim index.html
[root@generic1 mnt]# cat index.html
hello,today is cold
[root@generic1 ~]# cd /var/www/html/
[root@generic1 html]# ls
index.html
[root@generic1 html]# cat index.html 
generic1
neric1 mnt]# umount /mnt

测试:
在这里插入图片描述

[root@generic1 html]# /etc/init.d/httpd status
httpd (pid  15190) is running...
[root@generic1 html]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  19134332 1108568  17053784   7% /
tmpfs                           251136   25656    225480  11% /dev/shm
/dev/sda1                       495844   33474    436770   8% /boot
/dev/mapper/vg0-lv0            5160576  141308   4757124   3% /var/www/html
[root@generic1 html]# clustat 
Cluster Status for generic_dd @ Thu Jun 20 15:51:53 2019
Member Status: Quorate

 Member Name                              ID   Status
 ------ ----                              ---- ------
 generic1                                     1 Online, Local, rgmanager
 generic2                                     2 Online, rgmanager

 Service Name                    Owner (Last)                    State         
 ------- ----                    ----- ------                    -----         
 service:apache                  generic1                        started       

[root@generic1 html]# /etc/init.d/httpd status
httpd (pid  15190) is running...
[root@generic1 html]# clusvcadm -r apache -m generic2
Trying to relocate service:apache to generic2...Success
service:apache is now running on generic2
[root@generic1 html]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  19134332 1108572  17053780   7% /
tmpfs                           251136   25656    225480  11% /dev/shm
/dev/sda1                       495844   33474    436770   8% /boot
[root@generic1 html]# /etc/init.d/httpd status
httpd is stopped
[root@generic1 html]# clustat 
Cluster Status for generic_dd @ Thu Jun 20 15:56:53 2019
Member Status: Quorate

 Member Name                              ID   Status
 ------ ----                              ---- ------
 generic1                                     1 Online, Local, rgmanager
 generic2                                     2 Online, rgmanager

 Service Name                    Owner (Last)                    State         
 ------- ----                    ----- ------                    -----         
 service:apache                  generic2                        started     d is stopped

测试:
在这里插入图片描述

[root@generic2 ~]# /etc/init.d/httpd status   ##测试之前
httpd is stopped
[root@generic2 ~]# df  
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  19134332 1053144  17109208   6% /
tmpfs                           251136   25656    225480  11% /dev/shm
/dev/sda1                       495844   33474    436770   8% /boot
/dev/mapper/vg0-lv0            5160576  141308   4757124   3% /var/www/html
[root@generic2 ~]# /etc/init.d/httpd status 
httpd (pid  9421) is running...

在图形界面remove Filesystem ,只剩下以下两个
在这里插入图片描述
在这里插入图片描述
generic1 和 generic2中编辑文件 vim /etc/fstab
在这里插入图片描述
generic2 中

[root@generic2 ~]# clusvcadm  -d apache
Local machine disabling service:apache...Success
[root@generic2 ~]# lvs
  LV      VG       Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root VolGroup -wi-ao----  18.54g                                             
  lv_swap VolGroup -wi-ao---- 992.00m                                             
  lv0     vg0      -wi-a-----   5.00g              
[root@generic2 ~]# mkfs.gfs2 -p lock_dlm -j 2 -t generic_dd:mygfs2 /dev/vg0/lv0   #格式化,同步只做一次就可以
This will destroy any data on /dev/vg0/lv0.
It appears to contain: symbolic link to `../dm-2'

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

Device:                    /dev/vg0/lv0
Blocksize:                 4096
Device Size                5.00 GB (1310720 blocks)
Filesystem Size:           5.00 GB (1310718 blocks)
Journals:                  2
Resource Groups:           20
Locking Protocol:          "lock_dlm"
Lock Table:                "generic_dd:mygfs2"
UUID:                      edc021b1-c661-db7d-2863-725c788ab320

[root@generic2 ~]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  19134332 1053152  17109200   6% /
tmpfs                           251136   25656    225480  11% /dev/shm
/dev/sda1                       495844   33474    436770   8% /boot
[root@generic2 mnt]# vim /etc/fstab    #generic2 和generic1都做
[root@generic2 ~]# mount -a
[root@generic2 ~]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  19134332 1053156  17109196   6% /
tmpfs                           251136   31816    219320  13% /dev/shm
/dev/sda1                       495844   33474    436770   8% /boot
/dev/mapper/vg0-lv0            5242256  264776   4977480   6% /var/www/html

测试:在任何节点进行操作都能同步,且都能查看
在这里插入图片描述
generic1上拷贝文件
在这里插入图片描述generic2不用重新挂载直接可以看到文件及内容
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44821839/article/details/93053397
今日推荐