linux使用iscsi

ISCSI软件。
StarWind 是一个独立于硬件,适合网吧、企业虚拟磁盘数据管理。速度非常的快!
成本效益和可升级的存储管理解决方案,能够得到存储区域网络的好处,如:增强的灾难恢复和提高的调整柔量,不消耗额外的资源在程序服务器上。 StarWind 不需要额外的硬件,它利用现有的以太网和IP网络基础和有效利用现有的存储硬件。
StarWind的快照功允许简易的预定或要求关键数据的快照未备份。如果必需,所有的备份数据可被找回,会只找回需要的个人文件。 StarWind的独特的能力去virtualize和共享物理的硬件,意味着不需要去拥有一个昂贵的DLT 录音带或高容量的蓝光(Blu-Ray)或 HD-DVD 刻录器附属在每台机器上。

ISCSI使用
1.在服务器上安装了iSCSI initiator以及iscsiadm。
[root@rhel6-5x64-8-66 ~]# rpm –ivh iscsi-initiator-utils-6.2.0.742-0.5.el5.i386.rpm

2.iscsiadm是基于命令行的iscsi管理工具,提供了对iSCSI节点、会话、连接以及发现记录的操作。iscsiadm的使用说明可以查看/usr/share/doc/iscsi-initiator-utils-6.2.0.742/README,也可以运行man iscsiadm或iscsiadm --help使用。

3.连接iscsi设备的步骤:
3.1 启动iscsi守护进程
service iscsi start 默认情况下,系统启动后此进程会自动运行

3.2 发现有哪些共享盘可以连接
iscsi发起方和目标方之间通过端口3260连接,已知iscsi的目标方IP是10.12.9.1,运行下列命令:
[root@rhel6-5x64-8-66 ~]# chkconfig iscsi on
[root@rhel6-5x64-8-66 ~]# chkconfig iscsi --list (查看ISCSI启动状态)
iscsi          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@rhel6-5x64-8-66 ~]# iscsiadm -m discovery -t sendtargets -p 10.12.9.1:3260
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-gdisk
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-100g-2
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-hanjun
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-100gdisk

此时找到多个共享盘可以连接。
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-hanjun 就是其中一个,我们等下就连接这个iscsi共享盘。

3.3 连接iscsi共享盘
[root@rhel6-5x64-8-66 ~]# iscsiadm -m node -T iqn.2008-08.com.starwindsoftware:pub-9001-hanjun -p 10.12.9.1 -l
Logging in to [iface: default, target: iqn.2008-08.com.starwindsoftware:pub-9001-hanjun, portal: 10.12.9.1,3260] (multiple)
Login to [iface: default, target: iqn.2008-08.com.starwindsoftware:pub-9001-hanjun, portal: 10.12.9.1,3260] successful.

其中 iqn.2008-08.com.starwindsoftware:pub-9001-hanjun 是iscsi共享盘的名称。

如果要在系统启动时自动登入:
# iscsiadm -m node –T iqn.2008-08.com.starwindsoftware:pub-9001-hanjun -p 10.12.9.1:3260 --op update -n node.startup -v automatic

3.4 接着查看一下磁盘信息
[root@rhel6-5x64-8-66 ~]# fdisk -l
Disk /dev/sdc: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe0d5dbd5

Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       10240    10485744   83  Linux

【/dev/sdc即为连接的iscsi存储设备】

3.5 连接需要需验证码的iscsi共享盘的方法
3.5.1 开启认证
iscsiadm -m node -T [iscsi共享盘] -o update --name node.session.auth.authmethod --value=CHAP *.使用-o同--op
3.5.2 添加用户
iscsiadm -m node -T [iscsi共享盘] --op update --name node.session.auth.username --value=[用户名]
3.5.3 添加密码
iscsiadm –m node –T [iscsi共享盘] -op update –name node.session.auth.password –value=[密码]

3.6 分区并格式化设备
[root@rhel6-5x64-8-66 ~]# fdisk /dev/sdc
设备需要格式化为,我们格式为ext4文件系统,运行:
[root@rhel6-5x64-8-66 ~]# mkfs.ext4 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621436 blocks
131071 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 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.

【3.4 接着查看一下磁盘信息 这里就是分区并格式化好了的】

3.7 挂载设备mount
[root@rhel6-5x64-8-66 ~]# mkdir /sharedisk
[root@rhel6-5x64-8-66 ~]# mount /dev/sdc1 /sharedisk/
[root@rhel6-5x64-8-66 ~]# df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       41284928 16103600  23084176  42% /
tmpfs            4194304        4   4194300   1% /dev/shm
/dev/sdc1       10321192   154108   9642800   2% /sharedisk

iscsi设备被成功挂载,可以当作常规存储设备使用了。

3.8 如果要在系统启动时自动挂接
编辑 # vim /etc/fstab
加入一行:/dev/sdc1 /sharedisk ext4 default 0 0

3.9  注销到共享盘的连接
首先umount,再注销Logout
[root@rhel6-5x64-8-66 ~]# umount /sharedisk
[root@rhel6-5x64-8-66 ~]# iscsiadm -m node -T iqn.2008-08.com.starwindsoftware:pub-9001-gdisk -p 10.12.9.1 -u
Logging out of session [sid: 2, target: iqn.2008-08.com.starwindsoftware:pub-9001-gdisk, portal: 10.12.9.1,3260]
Logout of [sid: 2, target: iqn.2008-08.com.starwindsoftware:pub-9001-gdisk, portal: 10.12.9.1,3260] successful.

4.相关命令

4.1 查看有哪些共享盘可以连
[root@rhel6-5x64-8-66 ~]# iscsiadm --mode discovery --type sendtargets --portal 10.12.9.1
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-gdisk
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-100g-2
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-hanjun
10.12.9.1:3260,-1 iqn.2008-08.com.starwindsoftware:pub-9001-100gdisk

4.2 查看连上了哪些共享盘
[root@rhel6-5x64-8-66 ~]# iscsiadm -m session –R
tcp: [4] 10.12.9.1:3260,1 iqn.2008-08.com.starwindsoftware:pub-9001-hanjun

4.3 连接到某一个特定的共享盘 
[root@rhel6-5x64-8-66 ~]# iscsiadm -m node -T iqn.2008-08.com.starwindsoftware:pub-9001-hanjun -p 10.12.9.1 -l
Logging in to [iface: default, target: iqn.2008-08.com.starwindsoftware:pub-9001-hanjun, portal: 10.12.9.1,3260] (multiple)
Login to [iface: default, target: iqn.2008-08.com.starwindsoftware:pub-9001-hanjun, portal: 10.12.9.1,3260] successful.

4.4 注销到某一个特定的共享盘的连接 
[root@rhel6-5x64-8-66 ~]# iscsiadm -m node -T iqn.2008-08.com.starwindsoftware:pub-9001-gdisk -p 10.12.9.1 -u
Logging out of session [sid: 2, target: iqn.2008-08.com.starwindsoftware:pub-9001-gdisk, portal: 10.12.9.1,3260]
Logout of [sid: 2, target: iqn.2008-08.com.starwindsoftware:pub-9001-gdisk, portal: 10.12.9.1,3260] successful.

4.5 注销所有连接
[root@rhel6-5x64-8-66 ~]# iscsiadm -m node --logoutall=all
Logging out of session [sid: 1, target: iqn.2008-08.com.starwindsoftware:pub-9001-hanjun, portal: 10.12.9.1,3260]
Logging out of session [sid: 2, target: iqn.2008-08.com.starwindsoftware:pub-9001-gdisk, portal: 10.12.9.1,3260]
Logging out of session [sid: 3, target: iqn.2008-08.com.starwindsoftware:pub-9001-100g-2, portal: 10.12.9.1,3260]
Logout of [sid: 1, target: iqn.2008-08.com.starwindsoftware:pub-9001-hanjun, portal: 10.12.9.1,3260] successful.
Logout of [sid: 2, target: iqn.2008-08.com.starwindsoftware:pub-9001-gdisk, portal: 10.12.9.1,3260] successful.
Logout of [sid: 3, target: iqn.2008-08.com.starwindsoftware:pub-9001-100g-2, portal: 10.12.9.1,3260] successful.

4.6 service iscsi restart重启iscsi服务

4.7 service iscsi stop停止iscsi服务。
posted @ 2018-01-05 15:16  hike_bug  阅读(2052)  评论(0编辑  收藏  举报