天天看点

linux iscsi服务实现

1.使用mount将光盘位置/dev/cdrom内的文件挂载到/mnt/cdrom位置上:

mount /dev/cdrom /mnt/cdrom

2.使用find 命令查找安装包:

find -name iscsi*

3.安装安装包:

rpm -ivh  ./Server/iscsi-initiator-utils-6.2.0.868-0.18.el5.i386.rpm

运行此命令后,会生成一个目录/etc/iscsi,该目录下有两个文件:

Initiatorname.iscsi和iscsid.conf

4.启动iscsi服务

service iscsi start     或              cd /etc/init.d/   and  ./iscsi start

5.搜索盘阵:

运行以下命令搜寻target,即目标端:存储设备

命令格式:[root@linux ~]#iscsiadm --mode discovery --type sendtargets --portal ipaddre

iscsiadm -m discovery -t sendtargets -p 100.1.1.5

6.显示盘阵:

显示存储端target name

eg:

[root@localhost cdrom]# iscsiadm -m node

100.1.1.5:3260,1 iqn.2006-01.com.openfiler:tsn.63bb25fbfaa8

100.1.1.5:3260,1 iqn.2006-01.com.openfiler:tsn.959c083bcac2

[root@localhost cdrom]#

7.登录盘阵

命令格式:target登陆

[root@linux ~]#iscsiadm --mode node --targetname targetname --portal 192.168.1.221:3260 --login

[root@localhost cdrom]# iscsiadm -m node -T iqn.2006-01.com.openfiler:tsn.959c083bcac2 -p 100.1.1.5:3260 -l

Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.959c083bcac2, portal: 100.1.1.5,3260]

Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.959c083bcac2, portal: 100.1.1.5,3260]: successful

经过以上几步,fdisk–l就可以看到所挂接分区了!!!

(为确保重启后也能看到,再修改一下/etc/iscsi/iscsid.conf

[root@linux ~]# vi /etc/iscsi/iscsid.conf

iscsiadm --mode node --targetname targetname --portal 192.168.1.221:3260 –login

添加到该文件中的开始部分。

设置服务启动chkconfig --level 35 iscsid .)

其实这个文件大多数内容处于被注释状态,该命令添加位置应该影响不大.然后重启电脑后直接fdisk –l 依然可以看到所挂接的分区。至此iscsi所有操作完成,但挂载的分区不是linux所识别,必须使用FDISK进行磁盘分区。

8.设置分区

使用fdisk命令进行磁盘分区

fdisk是各种Linux发行版本中最常用的分区工具,是被定义为Expert级别的分区工具。我们可以通过fdisk来分区使用iscsi设备。它还包括一个二级选单,首先输入命令,然后出现问答式界面,用户通过在这个界面中输入命令参数来操作fdisk。

# fdisk /dev/hdb

运行后出现fdiak的命令提示符:

Command (m for help):

使用n命令创建一个分区,会出现选择主分区(p primary partition)还是扩展分区(llogical)的提示,通常选用主分区。然后按照提示输入分区号(Partion number(1-4):)、新分区起始的磁盘块数(FirstCylinder)和分区的大小,可以是以MB为单位的数字(Last cylindet or +siza or +sizeM or+sizeK:)。例如:

[root@localhost ~]# fdisk /dev/sda      查看磁盘信息

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. 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)

Command (m for help): n    创建新分区

Command action

   e   extended                   扩展分区

   p   primary partition (1-4)  逻辑分区

p

Partition number (1-4): 1

First cylinder (1-1011, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-1011, default 1011):

Using default value 1011

Command (m for help): w        保存分区信息

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost ~]#

9.检验新分区

[root@localhost ~]# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes

34 heads, 61 sectors/track, 1011 cylinders

Units = cylinders of 2074 * 512 = 1061888 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1        1011     1048376+  83  Linux

10.格式化分区

[root@localhost ~]# mkfs -t ext3 /dev/sda1

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

131072 inodes, 262094 blocks

13104 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=268435456

8 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376

Writing inode tables: done                           

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

11.设定加载点

文件系统必须有一个挂载点,它只是一个空的目录,新文件系统在这里与系统目录树“相连”。

经过以上的操作,Linux服务器已经连接到 iSCSI 储存设备, 并且如同Linux 本机上面的一个 SCSI 硬盘一样。 使用的方式几乎一模一样。

假设iSCSI 主机挂载到 /mnt/cluster目录下:

[root@localhost mnt]# mkdir  /mnt/cluster

[root@localhost mnt]# mount /dev/sda1 /mnt/cluster

[root@localhost mnt]# df

Filesystem        1K-blocks      used Available Use% Mounted on                                                                          /dev/mapper/VolGroup00-LogVol00

                       7491040   2571976   4532404  37% /

/dev/hda1               101086     10787     85080  12% /boot

tmpfs                   127852         0    127852   0% /dev/shm

/dev/sda1              1031888     17692    961780   2% /mnt/cluster

[root@localhost mnt]#

继续阅读