CentOS 5.2+Raid 0+LVM+ISCSI配置详解

CentOS 5.2+Raid 0+LVM+ISCSI 配置详解
 
广东东莞 曾令萍
 
题记:本文同步发表在本人新浪博客及CU博客,敬请知悉。
 
系统环境: CentOS 5.2
硬件配置: ASUS P5GC-MX +Intel E2160+Kinston 1GB 667*2+D-Link 530 1Gbps
硬盘 1 Seagate 80GB/7200S/8MB/SATA
硬盘 2 Seagate  1TB/7200S/32MB/SATA
硬盘 3 Seagate  1TB/7200S/32MB/SATA
 
场景:
笔者所在单位有一台用于备份文件的服务器目前空间不足(使用 Symantec Backup Exec 10d for Windows Servers 备份软件,备份文件服务器的所有数据,保留 15 天,每周六完整备份,周一至周五增量备份,现有 2TB 的空间已用完),该服务器已安装 8 个(容量与规格不一,有 SCSI/IDE/SATA )硬盘,机箱内已无空间再增加硬盘,经过考虑,决定重新安装一台 LINUX 服务器配置 ISCSI 服务(提供 Target Server 角色),在 Windows Server 2003 上安装 Microsoft iSCSI Initiator 驱动,添加 ISCSI 硬盘,解决目前的空间问题;
 
目标:
Target Server 系统安装在 ST 80GB 的硬盘上,两块 1TB 的硬盘通过软件( Software Raid )配置为 Raid 0, 然后在 Raild 0 硬盘上配置 LVM ,在 LVM 上创建两个逻辑卷, LV1 data1 )为 1.5TB LV2(data2) 325GB
 
Target server 建立两个 target device ,将 LVM 创建的两个逻辑卷分别加入两个 target device,node1 连接到 target device 1(iqn.2008-12.cn.lanexpert:iscsi-data1) node2 连接到 target device 2 iqn.2008-12.cn.lanexpert:iscsi-data2
 
功能
操作系统
主机名称
IP 地址
Iscsi-target server
CentOS 5.2
Fsbak2.lanexpert.cn
192.168.3.19
Iscsi-initiator(node1)
Windows Server 2003 Std R2 with sp2
Fsbak1.lanexpert.cn
192.168.3.18
Iscsi-initiator(node2)
Windows XP Pro With sp3
Client1.lanexpert.cn
192.168.11.108
 
Target Server 系统安装在 Seagate 80GB 的硬盘上,在安装系统时,根据以下要求分区(仅为个人习惯,供参考),其它两个 1TB 的硬盘暂时不分区;
/boot    100MB
/             10GB
/usr        20GB
/home   10GB
/var        30GB
Swap      3GB
 
系统选择最小化安装,仅安装最基本的服务;
 
一、 配置 Raid 0
#fdisk  -l           ( 显示所有连接在主机上的硬盘 )
Disk /dev/sda: 80.0 GB, 80025280000 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        3929    10482412+  83  Linux
/dev/sda4            3930        9729    46588500    5  Extended
/dev/sda5            3930        5234    10482381   83  Linux
/dev/sda6            5235        5708     3807373+  82  Linux swap / Solaris
/dev/sda7            5709        9729    32298651   83  Linux
 
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
从以上信息可以看到, /dev/sda 连接的是我们的系统分区,其它两个硬盘( sdb and sdc )没有分区表;
 
现在,我们要为另外两个硬盘分别创建分区,参考如下:
 
#fdisk /dev/sdb
The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
# 进入 fdisk 程序的工作画面后,如果硬盘太大,就会出现上述信息,这个信息表明,某些旧版本的软件与操作系统将无法支持大于 1024 柱面后的扇区使用
Command (m for help):m  # 可以通过此命令查看所有参数
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): new
Command action
   e   extended
   p   primary partition (1-4) p
Partition number (1-4): 1
First cylinder (1-121601, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-121601, default 121601):
Using default value 121601
 
Command (m for help): type
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
 
Command (m for help): write
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
 
重复以上命令对 sdc 进行分区;
 
完毕后使用 fdisk �Cl 查看分区信息:
#fdisk -l
isk /dev/sda: 80.0 GB, 80025280000 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        3929    10482412+  83  Linux
/dev/sda4            3930        9729    46588500    5  Extended
/dev/sda5            3930        5234    10482381   83  Linux
/dev/sda6            5235        5708     3807373+  82  Linux swap / Solaris
/dev/sda7            5709        9729    32298651   83  Linux
 
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      121601   976760001   fd  Linux raid autodetect
 
Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1      121601   976760001   fd  Linux raid autodetect
 
配置 raid 使用 mdadm 命令,有关该命令的具体参数参考 man mdadm;
 
# mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: array /dev/md0 started.
 
# cat /proc/mdstat    # 查看 Raid 信息
Personalities : [raid0]
md0 : active raid0 sdc1[1] sdb1[0]
      1953519872 blocks 64k chunks
     
unused devices: <none>
 
# fdisk -l
 
Disk /dev/sda: 80.0 GB, 80025280000 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        3929    10482412+  83  Linux
/dev/sda4            3930        9729    46588500    5  Extended
/dev/sda5            3930        5234    10482381   83  Linux
/dev/sda6            5235        5708     3807373+  82  Linux swap / Solaris
/dev/sda7            5709        9729    32298651   83  Linux
 
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      121601   976760001   fd  Linux raid autodetect
 
Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1      121601   976760001   fd  Linux raid autodetect
 
Disk /dev/md0: 2000.4 GB, 2000404348928 bytes
2 heads, 4 sectors/track, 488379968 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
 
Disk /dev/md0 doesn't contain a valid partition table
 
# mdadm --detail --scan
ARRAY /dev/md0 level=raid0 num-devices=2 UUID=bf5eb6f7:da2e7196:dc2b05b5:fa5903c1
 
为了让系统开机启动时自动加载 raid 信息,可以使用以下命令将配置信息写入 /etc/mdadm.conf 文件,该文件默认没有,可自行创建;
 
#echo DEVICE /dev/sdb1 /dev/sdc1 > /etc/mdadm.conf
#mdadm �Cdetail �Cscan >> /etc/mdadm.conf   (-- 为两个中短线 )
 
# cat /etc/mdadm.conf
DEVICE /dev/sdb1 /dev/sdc1
ARRAY /dev/md0 level=raid0 num-devices=2 UUID=bf5eb6f7:da2e7196:dc2b05b5:fa5903c1
 
二、 配置 LVM
 
要配置 LVM ,可以按以下步骤进行:
1.       创建和初始化物理卷( Physical Volume ),通过 pvcreate 建立 pv ,即 pv 阶段;
2.       添加物理卷到卷组( Volume Group ),使用 vgcreate 加入多个 pv 成为 vg ,即 vg 阶段;
3.       在卷组上创建逻辑卷( logical volume ),使用 lvcreate 划分 vg, 成为一个或多个 lv, lv 阶段;
 
# pvcreate /dev/md0      # 创建 PV
  Physical volume "/dev/md0" successfully created
 
# pvscan
  PV /dev/md0   VG LVM1   lvm2 [1.82 TB / 1.82 GB free]
  Total: 1 [1.82 TB] / in use: 1 [1.82 TB] / in no VG: 0 [0   ]
 
# vgcreate LVM1 /dev/md0  # 创建 VG
  Volume group "LVM1" successfully created
 
# vgdisplay  LVM1  
  --- Volume group ---
  VG Name               LVM1
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1.82 TB
  PE Size               4.00 MB
  Total PE              476933
  Alloc PE / Size       0 / 0  
  Free  PE / Size       476933 / 1.82 TB
  VG UUID               97Fecv-lBFP-oB19-dfrF-wJ7y-9KJ9-9sIKYG
 
# lvcreate -L 1.5TB -n data1 LVM1     # 创建 LV
  /dev/cdrom: open failed: Read-only file system
  Logical volume "data1" created
 
# lvcreate -L 325GB -n data2 LVM1   # 创建 LV
  /dev/cdrom: open failed: Read-only file system
  Logical volume "data2" created
 
# lvscan                   # 查看 LV 信息
  ACTIVE            '/dev/LVM1/data1' [1.50 TB] inherit
  ACTIVE            '/dev/LVM1/data2' [325.00 GB] inherit
 
# pvscan                  # 再次查看 PV 信息
  PV /dev/md0   VG LVM1   lvm2 [1.82 TB / 2.02 GB free]
  Total: 1 [1.82 TB] / in use: 1 [1.82 TB] / in no VG: 0 [0   ]
 
# vgdisplay LVM1       # 再次查看 VG 信息
 
  --- Volume group ---
  VG Name               LVM1
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1.82 TB
  PE Size               4.00 MB
  Total PE              476933
  Alloc PE / Size       476416 / 1.82 TB
  Free  PE / Size       517 / 2.02 GB
  VG UUID               97Fecv-lBFP-oB19-dfrF-wJ7y-9KJ9-9sIKYG
 
到这里,本实例的 LVM 配置完成;
注意:由于要将 LV 挂载到 iscsi ,所以,在这里不必格式化,也不必将 LV 挂载到系统中,以下是挂载方法,如应用于其它地方,可以参考;
 
格式化逻辑卷
#mke2fs -j /dev/LVM1/data1
#mke2fs -j /dev/LVM1/data2
 
参数说明:
-j :本来 mke2fs ext2, 加上 -j 后,会主动加入日志而成为 ext3
 
# 新增两个挂载点
#mkdir -pv /data1 /data2 
 
挂载命令,本例不需要将以下两个 LV 挂载到系统中;
#mount /dev/LVM1/data1 /data1
#mount /dev/LVM1/data2 /data2
 
设置开机自动挂载:
编辑 /etc/fstab
#Raid 0 and LVM1
/dev/LVM1/data1         /data1                  ext3    defaults        2 2
/dev/LVM1/data2         /data2                  ext3    defaults        2 2
 
★有关挂载参数说明,请参考鸟哥私房菜――基础学习篇
 
三、 配置 ISCSI
1、 安装 iscsi-target iscsi-target 可以从以下网址下载 :
#wget [url]ftp://ftp.muug.mb.ca/mirror/centos/5.2/os/i386/CentOS/scsi-target-utils-0.0-0.20070620snap.el5.i386.rpm[/url]
#rpm -ivh scsi-target-utils-0.0-0.20070620snap.el5.i386.rpm
 
# 启动 tgtd 服务
#service tgtd start    
 
# 设置开机自启动 tgtd 服务
#chkconfig --level 345 tgtd on      
 
# 服务启动后,可以查看监听端口:
# netstat -tunlp |grep tgtd
tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      2295/tgtd          
tcp        0      0 :::3260                     :::*                        LISTEN      2295/tgtd          
 
可以看到,默认 target server 使用的服务端口是 tcp 3260;
2、 建立 target device
Centos 5.0 以上是利用 tgtadm 命令来设置而不是编写 /etc/ietd.conf( 据台湾朋友 Alex Lin 介绍, 4.0 是通过编写 /etc/ietd.conf 来配置的,本节也是参考 Alex 的文章测试的 ) ,个人认为 tgtadm 的命令相关参数真的较难记,幸好 scsi-target-utils 软件中包含如何利用 tagadm 命令建立 target device 的步骤,建议读者一定要把 /usr/share/doc/scsi-target-utils-0.0/README.iscs 打开阅读,里面有举例说明可参考;
 
现准备新增 iqn 名为 iqn.2008-12.cn.lanexpert:iscsi-data1 target device
[iscsi qualified name]   ( 简称 iqn) ,格式通常如下:
  
 
 
Yyyy-mm
年-月
2008-12
Reversed domain name
把域名反过来写
Cn.lanexpert
identifier
识别字,通常描述这个储存空间的用途
Iscsi-data1
 
新增 target device 命令如下:
 
#tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2008-12.cn.lanexpert:iscsi-data1
 
执行后,可以利用以下命令查看 target device:
# tgtadm --lld iscsi --op show  --mode target
Target 1: iqn.2008-12. cn.lanexpert:iscsi-data1
    System information:
        Driver: iscsi
        Status: running
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
    Account information:
ACL information:
3、 target server 新建的 LV1 /dev/LVM1/data1 )加入 target device
#tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/LVM1/data1
将逻辑卷加入 target device 后,利用下列命令查看 target device 的信息:
# tgtadm --lld iscsi --op show  --mode target
Target 1: iqn.2008-12. cn.lanexpert:iscsi-data1
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 1T                      
# 这里有些不解,实际上的容量是 1.5TB ,后来我在 Win2k3 上连接并分区时也是 1.5TB
            Backing store: /dev/LVM1/data1
    Account information:
    ACL information:
 
4、 允许 initiator 主机 node1(192.168.3.18) 可以存取此 target device
#tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.3.18
 
将逻辑卷加入 target device 后,利用下面的命令查看 target device 的信息:
# tgtadm --lld iscsi --op show  --mode target
Target 1: iqn.2008-12.local.superlgroup.xt:iscsi-data1
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 1T
            Backing store: /dev/LVM1/data1
    Account information:
    ACL information:
        192.168.3.18
 
再使用以下命令创建另一个 target device:
tgtadm --lld iscsi --op new --mode target --tid 2 -T iqn.2008-12.cn.lanexpert:iscsi-data2
tgtadm --lld iscsi --op new --mode logicalunit --tid 2 --lun 1 -b /dev/LVM1/data2
tgtadm --lld iscsi --op bind --mode target --tid 2 -I 192.168.11.108
 
创建完毕后,再利用下面的命令查看 target device:
# tgtadm --lld iscsi --op show  --mode target
Target 1: iqn.2008-12.cn.lanexpert:iscsi-data1
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 1T
            Backing store: /dev/LVM1/data1
    Account information:
    ACL information:
        192.168.3.18
Target 2: iqn.2008-12.cn.lanexpert:iscsi-data2
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf2:0
            SCSI SN: beaf20
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf2:1
            SCSI SN: beaf21
            Size: 325G
            Backing store: /dev/LVM1/data2
    Account information:
    ACL information:
        192.168.11.108
 
5、 修改 /etc/rc.local ,设置开机自动加载 target device 配置
因为以上命令的配置结果,重新开机后便会消失,而且现版本的 target server,Redhat 尚未修改成 System V 服务,如果需要系统重新启动后上述配置仍然有效,只能将以上配置写入 /etc/rc.local ,让系统每次开机都自动执行一次:
 
# ISCSI target device setting -LingPing 2008/12/06
#target 1 (Space 1.5TB)
tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2008-12.cn.lanexpert:iscsi-data1
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/LVM1/data1
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.3.18
 
#target 2 (Space 325GB)
tgtadm --lld iscsi --op new --mode target --tid 2 -T iqn.2008-12.cn.lanexpert:iscsi-data2
tgtadm --lld iscsi --op new --mode logicalunit --tid 2 --lun 1 -b /dev/LVM1/data2
tgtadm --lld iscsi --op bind --mode target --tid 2 -I 192.168.11.108
 
由于 tgtdm 的参数短时间内难于记忆,建议多参考 man 或以下提及的文章;
本节主要参考台湾朋友林彦明的大作,在鸟哥的网站可下载到,原文还详细介绍了 iscsi initiator on rhel 5.1 的配置,值得一读;
 
四、 配置 Windows Initiator )系统连接到 ISCSI
 
Initiator 主要是负责电脑连接到 target 作磁盘读取功能,如果是 Windows 系统,可以到 Microsoft 的官方网站下载最新版本的 initiator ,可在以下网址选择适合自己的版本:
[url]http://www.microsoft.com/downloads/details.aspx?FamilyID=12cb3c1a-15d6-4585-b385-befd1319f825&DisplayLang=en[/url]
 
1 、安装 initiator
双击 iator-2.08-build3825-x86fre.exe 依提示进行安装,安装完毕后,会在桌面上产生一个 Microsoft iSCSI Initiator 图标;
 
2 、配置 initiator
双击 Microsoft iSCSI Initiator 图标,在 discovery 选项的 target portals 框中,选择 add, 填写 target portals 的地址,例如 192.168.3.19 ,端口保持默认;如图:
 
数秒钟后,可以在 targets 选项中看到刚才在 target server 建立的 iqn 名称(是经过授权的,未经授权的将不会显示出来),本例中的截图是 node2, 所以显示的是 iqn.2008-12.cn.lanexpert:iscsi-data2
 
在上图中,点击 log on, 出现如下所示对话框,建议勾选第一个选项,让系统重启后自动加载;
 
 
然后打开我的电脑-属性-管理-磁盘管理,会弹出一个初始化磁盘的向导,依向导提示即可如操作本机中的硬盘一样进行分区、格式化等工作;
 
可以通过同样的方法将 Fsbak1.lanexpert.cn 连接到另一个 Target ,解决备份服务器的空间问题;
 
主要参考资料: Linux 系统管理手册(第二版)、鸟哥私房菜、林彦明朋友的专题文章( rhel5-iscsi.pdf
LingPing   on 2008/12/06
[url]http://blog.sina.com.cn/zenglingping[/url]

你可能感兴趣的:(centos,raid,target,lvm,iSCSI)