mdadm用iscsi硬盘和本机硬盘建立raid

iscsi+mdadm 建立镜像

1,硬盘环境
[root@rac1 /]# fdisk -l
...
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System

[root@rac2 ~]# fdisk -l
...
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System
[root@rac2 ~]#

2,在rac2上配置 iscsi-target

在rac2上设置/etc/ietd.conf配置文件为:
Target iqn.2001-04.com.example:storage.disk2.sys1.idisk
Lun 4 Path=/dev/sdb,Type=fileio
Alias sdb

3,启动iscsi-target服务:
[root@rac2 ~]# /etc/init.d/iscsi-target start
Starting iSCSI target service: [ OK ]

4,在rac1上配置/etc/iscsi.conf
修改下面3项:
DiscoveryAddress=<IP Address>
This needs to be set to the Group IP Address of your UIT Array.

SendAsyncText=yes
For the initiator to receive Vendor Specific async events from the target.

Continuous=yes
To globally specify that all discovery sessions be kept open.

5,启动服务
[root@rac1 /]# /etc/init.d/iscsi start
Checking iscsi config: [ OK ]
Loading iscsi driver: [ OK ]
mknod: `/dev/iscsictl': File exists
Starting iscsid: [ OK ]
[root@rac1 /]#

6,此时fdisk结果为:
[root@rac1 /]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 892 7164958+ 83 Linux
/dev/sda2 893 1274 3068415 82 Linux swap
/dev/sda3 1275 2610 10731420 83 Linux

Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System

Disk /dev/sdc: 536 MB, 536870912 bytes
17 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 1037 * 512 = 530944 bytes

Device Boot Start End Blocks Id System
[root@rac1 /]#

rac1增加一个盘sdc,用/dev/sdb,/dev/sdc做镜像。


7,使用mdadm创建RAID1
[root@rac1 /]# mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/sdb /dev/sdc
mdadm: size set to 524224K
mdadm: array /dev/md0 started.
[root@rac1 /]#

每个mdadm的选项都有一个所写的形式,例如,上面的命令可以缩写为:
mdadm -Cv /dev/md0 -l1 -n2 /dev/sdb /dev/sdc


此时fdisk显示:
[root@rac1 /]# fdisk -l
......
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System

Disk /dev/md0: 536 MB, 536805376 bytes
2 heads, 4 sectors/track, 131056 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Device Boot Start End Blocks Id System

Disk /dev/sdc: 536 MB, 536870912 bytes
17 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 1037 * 512 = 530944 bytes

Device Boot Start End Blocks Id System
[root@rac1 /]#

8,查看raid信息:
使用cat /proc/mdstat命令来查看一下RAID的状态,我们也可以利用watch命令来每隔一段时间刷新/proc/mdstat的输出。使用CTRL+C可以取消。
使用mdadm --detail /dev/md0(或mdadm -D /dev/md0)命令以及cat /proc/mdstat命令可以查看RAID设备的状态:

[root@rac1 /]# cat /proc/mdstat
Personalities : [raid1] [raid5]
md0 : active raid1 sdc[1] sdb[0]
524224 blocks [2/2] [UU]

unused devices: <none>
[root@rac1 /]# mdadm -D /dev/md0
/dev/md0:
Version : 00.90.01
Creation Time : Thu Oct 25 15:28:07 2007
Raid Level : raid1
Array Size : 524224 (511.94 MiB 536.81 MB)
Device Size : 524224 (511.94 MiB 536.81 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Thu Oct 25 15:30:24 2007
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0


Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
UUID : 081c04ac:6cb9278e:35bade9d:49098be4
Events : 0.34
[root@rac1 /]#

[root@rac1 /]# mdadm --detail /dev/md0
...

9,为阵列建立文件系统
[root@rac1 /]# mkfs.ext3 /dev/md0
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
131072 inodes, 524224 blocks
26211 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
64 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@rac1 /]# mkdir /mnt/md0
[root@rac1 /]# mount /dev/md0 /mnt/md0
[root@rac1 /]# cd /mnt/md0
[root@rac1 md0]# ls
lost+found
[root@rac1 md0]# touch test
[root@rac1 md0]# ls
lost+found test
[root@rac1 md0]#


10,创建/etc/mdadm.conf配置文件
一个新阵列被创建后我们最好创建一个/etc/mdadm.conf文件。没有该文件在激活阵列时我们就得指定更详细的信息,为方便,我们使用下列命令:
[root@rac1 /]# mdadm --detail --scan
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=081c04ac:6cb9278e:35bade9d:49098be4
devices=/dev/sdb,/dev/sdc
[root@rac1 /]# mdadm --detail --scan > /etc/mdadm.conf
[root@rac1 /]# cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=081c04ac:6cb9278e:35bade9d:49098be4
devices=/dev/sdb,/dev/sdc
[root@rac1 /]#


11,启动停止RAID
使用--stop或-S命令选项可以停止运行的阵列(注意: 停止前必须先umount):
[root@rac1 /]# umount /mnt/md0
[root@rac1 /]# mdadm -S /dev/md0 (或mdadm --stop /dev/md0)

重新启动可以使用:
[root@rac1 /]# mdadm -As /dev/md0
mdadm: no devices found for /dev/md0

启动时报错,

新的配置文件应该这样创建:
[root@rac1 ~]# echo DEVICE /dev/sd* > /etc/mdadm.conf
[root@rac1 ~]# mdadm --detail --scan >> /etc/mdadm.conf
[root@rac1 ~]# cat /etc/mdadm.conf
DEVICE /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdc
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=081c04ac:6cb9278e:35bade9d:49098be4
devices=/dev/sdb,/dev/sdc
[root@rac1 ~]#

然后重新测试关闭启动
[root@rac1 ~]# mdadm --stop /dev/md0
[root@rac1 ~]# mdadm -As /dev/md0
mdadm: /dev/md0 has been started with 2 drives.
[root@rac1 ~]#


当没有配置文件的时候可以用如下方式启动:
[root@rac1 /]# umount /dev/md0
[root@rac1 /]# mdadm -S /dev/md0
[root@rac1 /]# mdadm -A /dev/md0 /dev/sdb /dev/sdc
mdadm: /dev/md0 has been started with 2 drives.
[root@rac1 /]#

 

你可能感兴趣的:(mdadm用iscsi硬盘和本机硬盘建立raid)