- 論壇徽章:
- 0
|
CentOS 5.2+Raid 0+LVM+ISCSI配置詳解
原文參考附件PDF,文中圖片未上傳;
系統(tǒng)環(huán)境:CentOS 5.2
硬件配置:ASUS P5GC-MX +Intel E2160+Kinston 1GB 667*2+D-Link 530 1Gbps
硬盤(pán)1:Seagate 80GB/7200S/8MB/SATA
硬盤(pán)2:Seagate 1TB/7200S/32MB/SATA
硬盤(pán)3:Seagate 1TB/7200S/32MB/SATA
場(chǎng)景:
一臺(tái)用于備份文件的服務(wù)器目前空間不足(使用Symantec Backup Exec 10d for Windows Servers備份軟件,備份文件服務(wù)器的所有數(shù)據(jù),保留15天,每周六完整備份,周一至周五增量備份,現(xiàn)有2TB的空間已用完),該服務(wù)器已安裝8個(gè)(容量與規(guī)格不一,有SCSI/IDE/SATA)硬盤(pán),機(jī)箱內(nèi)已無(wú)空間再增加硬盤(pán),經(jīng)過(guò)考慮,決定重新安裝一臺(tái)LINUX服務(wù)器配置ISCSI服務(wù)(提供Target Server角色),在Windows Server 2003上安裝Microsoft iSCSI Initiator驅(qū)動(dòng),添加ISCSI硬盤(pán),解決目前的空間問(wèn)題;
Target Server要求系統(tǒng)安裝在ST 80GB的硬盤(pán)上,兩塊1TB的硬盤(pán)配置為Raid 0,然后在Raild 0硬盤(pán)上配置LVM,在LVM上創(chuàng)建兩個(gè)邏輯卷,LV1(data1)為1.5TB,LV2(data2)為325GB;
Target server 建立兩個(gè)target device,將LVM創(chuàng)建的兩個(gè)邏輯卷分別加入兩個(gè)target device,node1連接到target device 1(iqn.2008-12.cn.lanexpert:iscsi-data1),node2連接到target device 2(iqn.2008-12.cn.lanexpert:iscsi-data2)
功能
操作系統(tǒng)
主機(jī)名稱(chēng)
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系統(tǒng)安裝在Seagate 80GB的硬盤(pán)上,在安裝系統(tǒng)時(shí),根據(jù)以下要求分區(qū)(僅為個(gè)人習(xí)慣,供參考),其它兩個(gè)1TB的硬盤(pán)暫時(shí)不分區(qū);
/boot 100MB
/ 10GB
/usr 20GB
/home 10GB
/var 30GB
Swap 3GB
系統(tǒng)選擇最小化安裝,僅安裝最基本的服務(wù);
一、配置Raid 0
#fdisk -l (顯示所有連接在主機(jī)上的硬盤(pán))
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連接的是我們的系統(tǒng)分區(qū),其它兩個(gè)硬盤(pán)(sdb and sdc)沒(méi)有分區(qū)表;
現(xiàn)在,我們要為另外兩個(gè)硬盤(pán)分別創(chuàng)建分區(qū),參考如下:
#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)
#進(jìn)入fdisk程序的工作畫(huà)面后,如果硬盤(pán)太大,就會(huì)出現(xiàn)上述信息,這個(gè)信息表明,某些舊版本的軟件與操作系統(tǒng)將無(wú)法支持大于1024柱面后的扇區(qū)使用
Command (m for help):m #可以通過(guò)此命令查看所有參數(shù)
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.
重復(fù)以上命令對(duì)sdc進(jìn)行分區(qū);
完畢后使用fdisk –l查看分區(qū)信息:
#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命令,有關(guān)該命令的具體參數(shù)參考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:
# 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
為了讓系統(tǒng)開(kāi)機(jī)啟動(dòng)時(shí)自動(dòng)加載raid信息,可以使用以下命令將配置信息寫(xiě)入/etc/mdadm.conf文件,該文件默認(rèn)沒(méi)有,可自行創(chuàng)建;
#echo DEVICE /dev/sdb1 /dev/sdc1 > /etc/mdadm.conf
#mdadm –detail –scan >> /etc/mdadm.conf (--為兩個(gè)中短線)
# cat /etc/mdadm.conf
DEVICE /dev/sdb1 /dev/sdc1
ARRAY /dev/md0 level=raid0 num-devices=2 UUID=bf5eb6f7:da2e7196:dc2b05b5:fa5903c1
二、配置LVM;
要配置LVM,可以按以下步驟進(jìn)行:
1. 創(chuàng)建和初始化物理卷(Physical Volume),通過(guò)pvcreate建立pv,即pv階段;
2. 添加物理卷到卷組(Volume Group),使用vgcreate加入多個(gè)pv成為vg,即vg階段;
3. 在卷組上創(chuàng)建邏輯卷(logical volume),使用lvcreate劃分vg,成為一個(gè)或多個(gè)lv,即lv階段;
# pvcreate /dev/md0 #創(chuàng)建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 #創(chuàng)建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 #創(chuàng)建LV
/dev/cdrom: open failed: Read-only file system
Logical volume "data1" created
# lvcreate -L 325GB -n data2 LVM1 #創(chuàng)建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
到這里,本實(shí)例的LVM配置完成;
注意:由于要將LV掛載到iscsi,所以,在這里不必格式化,也不必將LV掛載到系統(tǒng)中,以下是掛載方法,如應(yīng)用于其它地方,可以參考;
格式化邏輯卷
#mke2fs -j /dev/LVM1/data1
#mke2fs -j /dev/LVM1/data2
參數(shù)說(shuō)明:
-j :本來(lái)mke2fs是ext2,加上-j后,會(huì)主動(dòng)加入日志而成為ext3
#新增兩個(gè)掛載點(diǎn)
#mkdir -pv /data1 /data2
掛載命令,本例不需要將以下兩個(gè)LV掛載到系統(tǒng)中;
#mount /dev/LVM1/data1 /data1
#mount /dev/LVM1/data2 /data2
設(shè)置開(kāi)機(jī)自動(dòng)掛載:
編輯/etc/fstab
#Raid 0 and LVM1
/dev/LVM1/data1 /data1 ext3 defaults 2 2
/dev/LVM1/data2 /data2 ext3 defaults 2 2
★有關(guān)掛載參數(shù)說(shuō)明,請(qǐng)參考鳥(niǎo)哥私房菜——基礎(chǔ)學(xué)習(xí)篇
三、配置ISCSI
1、 安裝iscsi-target,iscsi-target可以從以下網(wǎng)址下載:
#wget ftp://ftp.muug.mb.ca/mirror/centos/5.2/os/i386/CentOS/scsi-target-utils-0.0-0.20070620snap.el5.i386.rpm
#rpm -ivh scsi-target-utils-0.0-0.20070620snap.el5.i386.rpm
#啟動(dòng)tgtd服務(wù)
#service tgtd start
#設(shè)置開(kāi)機(jī)自啟動(dòng)tgtd服務(wù)
#chkconfig --level 345 tgtd on
#服務(wù)啟動(dòng)后,可以查看監(jiān)聽(tīng)端口:
# 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
可以看到,默認(rèn)target server使用的服務(wù)端口是tcp 3260;
2、 建立target device
Centos 5.0以上是利用tgtadm命令來(lái)設(shè)置而不是編寫(xiě)/etc/ietd.conf(據(jù)臺(tái)灣朋友Alex Lin介紹,4.0是通過(guò)編寫(xiě)/etc/ietd.conf來(lái)配置的,本節(jié)也是參考Alex的文章測(cè)試的),個(gè)人認(rèn)為tgtadm的命令相關(guān)參數(shù)真的較難記,幸好scsi-target-utils軟件中包含如何利用tagadm命令建立target device的步驟,建議讀者一定要把/usr/share/doc/scsi-target-utils-0.0/README.iscs打開(kāi)閱讀,里面有舉例說(shuō)明可參考;
現(xiàn)準(zhǔn)備新增iqn名為iqn.2008-12.cn.lanexpert:iscsi-data1的target device
[iscsi qualified name] (簡(jiǎn)稱(chēng)iqn),格式通常如下:
格 式
意 義
范 例
Yyyy-mm
年-月
2008-12
Reversed domain name
把域名反過(guò)來(lái)寫(xiě)
Cn.lanexpert
identifier
識(shí)別字,通常描述這個(gè)儲(chǔ)存空間的用途
Iscsi-data1
新增target device 命令如下:
#tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2008-12.cn.lanexpert:iscsi-data1
執(zhí)行后,可以利用以下命令查看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
#這里有些不解,實(shí)際上的容量是1.5TB,后來(lái)我在Win2k3上連接并分區(qū)時(shí)也是1.5TB
Backing store: /dev/LVM1/data1
Account information:
ACL information:
4、 允許initiator主機(jī)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
再使用以下命令創(chuàng)建另一個(gè)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
創(chuàng)建完畢后,再利用下面的命令查看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,設(shè)置開(kāi)機(jī)自動(dòng)加載target device配置
因?yàn)橐陨厦畹呐渲媒Y(jié)果,重新開(kāi)機(jī)后便會(huì)消失,而且現(xiàn)版本的target server,Redhat尚未修改成System V服務(wù),如果需要系統(tǒng)重新啟動(dòng)后上述配置仍然有效,只能將以上配置寫(xiě)入/etc/rc.local,讓系統(tǒng)每次開(kāi)機(jī)都自動(dòng)執(zhí)行一次:
# 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的參數(shù)短時(shí)間內(nèi)難于記憶,建議多參考man或以下提及的文章;
本節(jié)主要參考臺(tái)灣朋友林彥明的大作,在鳥(niǎo)哥的網(wǎng)站可下載到,原文還詳細(xì)介紹了iscsi initiator on rhel 5.1的配置,值得一讀;
四、配置Windows(Initiator)系統(tǒng)連接到ISCSI
Initiator主要是負(fù)責(zé)電腦連接到target作磁盤(pán)讀取功能,如果是Windows系統(tǒng),可以到Microsoft的官方網(wǎng)站下載最新版本的initiator,可在以下網(wǎng)址選擇適合自己的版本:
http://www.microsoft.com/downloads/details.aspx?FamilyID=12cb3c1a-15d6-4585-b385-befd1319f825&DisplayLang=en
1、安裝initiator
雙擊iator-2.08-build3825-x86fre.exe依提示進(jìn)行安裝,安裝完畢后,會(huì)在桌面上產(chǎn)生一個(gè)Microsoft iSCSI Initiator圖標(biāo);
2、配置initiator
雙擊Microsoft iSCSI Initiator圖標(biāo),在discovery選項(xiàng)的target portals框中,選擇add,填寫(xiě)target portals的地址,例如192.168.3.19,端口保持默認(rèn);如圖:
數(shù)秒鐘后,可以在targets選項(xiàng)中看到剛才在target server建立的iqn名稱(chēng)(是經(jīng)過(guò)授權(quán)的,未經(jīng)授權(quán)的將不會(huì)顯示出來(lái)),本例中的截圖是node2,所以顯示的是iqn.2008-12.cn.lanexpert:iscsi-data2
在上圖中,點(diǎn)擊log on,出現(xiàn)如下所示對(duì)話框,建議勾選第一個(gè)選項(xiàng),讓系統(tǒng)重啟后自動(dòng)加載;
![]()
文件:
CentOS 5.2+Raid 0+LVM+ISCSI配置詳解.pdf
大小:
430KB
下載:
下載
然后打開(kāi)我的電腦-屬性-管理-磁盤(pán)管理,會(huì)彈出一個(gè)初始化磁盤(pán)的向?qū),依向(qū)崾炯纯扇绮僮鞅緳C(jī)中的硬盤(pán)一樣進(jìn)行分區(qū)、格式化等工作;
主要參考資料:Linux系統(tǒng)管理手冊(cè)(第二版)、鳥(niǎo)哥私房菜、林彥明朋友的專(zhuān)題文章(rhel5-iscsi.pdf)
LingPing
2008/12/06
http://blog.sina.com.cn/zenglingping
本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u2/71174/showart_1683305.html |
|