您的位置:首页 > 运维架构 > Linux

Linux Iscsi 安装和配置

2012-03-03 23:12 211 查看
1. 使用mount将光盘位置/dev/cdrom内的文件挂载到/mnt/cdrom位置上:

mount /dev/cdrom /mnt/cdrom
2. 挂载yum源
[root@looklo ~]# vim /etc/yum.repos.d/rhel-source.repo
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
3. 安装安装包:
安装方法一:
查找包
[root@looklo ~]# yum search iscsi
iscsi-initiator-utils.x86_64 : iSCSI daemon and utility programs
安装包
[root@looklo ~]# yum install iscsi-initiator-utils.x86_64 –y
安装方法二:
find -name iscsi*

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 或
/etc/init.d/iscsi start
5.搜索盘阵:

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

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

iscsiadm -m discovery -t sendtargets -p 192.168.0.230
6.显示盘阵:

显示存储端target name

eg:

[root@localhost cdrom]# iscsiadm -m node

192.168.0.230:3260,1 iqn.2001-05.com.equallogic:0-290c06-cb5684bd1-00a4abe3c9d4e5ca-pillar

192.168.0.135:3260,1 iqn.2001-05.com.equallogic:0-290c06-d068419ca-00d000000244f040-volume1

[root@localhost cdrom]#
7.登录盘阵

命令格式:target登陆

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

eg:

[root@localhost cdrom]# iscsiadm -m node -T iqn.2001-05.com.equallogic:0-290c06-cb5684bd1-00a4abe3c9d4e5ca-pillar -p 192.168.0.230: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

[root@localhost cdrom]#
经过以上几步,fdisk–l就可以看到所挂接分区了!!!

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

[root@linux ~]# vi /etc/iscsi/iscsid.conf
iscsiadm -m node -T iqn.2001-05.com.equallogic:0-290c06-cb5684bd1-00a4abe3c9d4e5ca-pillar -p 192.168.0.230:3260 –l
添加到该文件中的开始部分。

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

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

使用fdisk命令进行磁盘分区

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

# fdisk /dev/sdb

运行后出现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/sdb 查看磁盘信息

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/sdb
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/sdb1

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/sdb1 /mnt/cluster

[root@localhost mnt]# df -h

[root@looklo ~]# df –h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg0-lvroot

9.9G 5.3G 4.2G 57% /

tmpfs 1004M 272K 1004M 1% /dev/shm

/dev/sda1 291M 78M 199M 28% /boot

/dev/mapper/vg0-lvhome

4.0G 202M 3.6G 6% /home

/dev/mapper/vg0-lviso

4.0G 3.5G 255M 94% /iso

/dev/mapper/vg1-lv_oracle

9.9G 8.0G 1.4G 86% /opt

/dev/sdb1 389M 11M 359M 3% /mnt/cluster
[root@localhost mnt]#

12.设定自动挂载

在机器重新启动后自动加载分区,必须在/etc/fstab中加入相应分区,但分区类型必须市"_netdev".例如加载的分区sda1:

[root@linux ~]# vi /etc/fstab

/dev/sdb1 /mnt/cluster ext3 ­_netdev 0 0
本文出自 “IT-爱好者” 博客,请务必保留此出处http://pillarmanocean.blog.51cto.com/2349508/795623
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: