CentOS6.3安装配置iscsi并实现自动挂载
来源:http://blog.sina.com.cn/s/blog_45e9485a0101acm9.html
1,ISCSI目标配置例子
[root@openstack1 ~]# cat /etc/issue
CentOS release 6.3 (Final)
Kernel \r on an \m
[root@openstack1 ~]# uname -a
Linux openstack1 2.6.32-279.14.1.el6.x86_64 #1 SMP Tue Nov 6 23:43:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@openstack1 ~]# yum -y install scsi-target-utils
[root@openstack1 ~]# dd if=/dev/zero of=/tmp/iscsilun01.img bs=1024 count=1024000
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 2.68409 s, 391 MB/s
[root@openstack1 ~]# vi /etc/tgt/targets.conf
[root@openstack1 ~]# sed /^#/d /etc/tgt/targets.conf | sed /^$/d | grep -v "#"
default-driver iscsi
backing-store /tmp/iscsilun01.img
write-cache off
[root@openstack1 ~]# /etc/init.d/tgtd restart
Stopping SCSI target daemon: not running [FAILED]
Starting SCSI target daemon: [ OK ]
[root@openstack1 ~]# tgt-admin --show
Target 1: iqn.2012-12.com.example:server.target1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1049 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /tmp/iscsilun01.img
Backing store flags:
Account information:
ACL information:
ALL
[root@openstack1 ~]# chkconfig tgtd on
[root@openstack1 ~]# chkconfig --list | grep tgtd
tgtd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@openstack1 ~]#
2,ISCSI启动器配置
[root@openstack2 ~]# yum -y install iscsi-initiator-utils
[root@openstack2 ~]# /etc/init.d/iscsid start
[root@openstack2 ~]# chkconfig iscsid on
[root@openstack2 ~]# chkconfig --list | grep iscsid
iscsid 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@openstack2 ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.16.101 192.168.16.101:3260,1 iqn.2012-12.com.example:server.target1
Starting iscsid: [ OK ]
192.168.16.101:3260,1 iqn.2012-12.com.example:server.target1
[root@openstack2 ~]# iscsiadm -m node -T iqn.2012-12.com.example:server.target1 -p 192.168.16.101 -l
Logging in to [iface: default, target: iqn.2012-12.com.example:server.target1, portal: 192.168.16.101,3260] (multiple)
Login to [iface: default, target: iqn.2012-12.com.example:server.target1, portal: 192.168.16.101,3260] successful.
[root@openstack2 ~]# fdisk -l
。。。。。。。。。。。。。。
。。。。。。。。。
。。。。。
Disk /dev/sdb: 1048 MB, 1048576000 bytes
33 heads, 61 sectors/track, 1017 cylinders
Units = cylinders of 2013 * 512 = 1030656 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@openstack2 ~]#
现在你可以格式化分区,挂载在本地。如果要实现开机自动挂载,要在fstab文件添加记录。一定要添加_netdev参数,要不你在重启iscsi server后,启动时会报错。例如:
[root@openstack2 ~]# vi /etc/fstab
/dev/sdc /mnt ext4 default,_netdev 0 0
3,删除一个ISCSI设备流程
首先登出该ISCSI设备,否则无法删除
[root@openstack2 ~]# iscsiadm -m node -T iqn.2012-12.com.example:server.target1 -p 192.168.16.101 -u
Logging out of session [sid: 1, target: iqn.2012-12.com.example:server.target1, portal: 192.168.16.101,3260]
Logout of [sid: 1, target: iqn.2012-12.com.example:server.target1, portal: 192.168.16.101,3260] successful.
开始删除该ISCSI设备
[root@openstack2 ~]# iscsiadm -m node -o delete -T iqn.2012-12.com.example:server.target1 -p 192.168.16.101
[root@openstack2 ~]# fdisk -l
此时已经无法查看到/dev/sdb设备了
参考:ISCSI常用命令
1.发现iscsi存储: iscsiadm -m discovery -t st -p ISCSI_IP
2.查看iscsi发现记录 iscsiadm -m node
3.删除iscsi发现记录 iscsiadm -m node -o delete -T LUN_NAME -p ISCSI_IP
4.登录iscsi存储 iscsiadm -m node -T LUN_NAME -p ISCSI_IP -l
5.登出iscsi存储 iscsiadm -m node -T LUN_NAME -p ISCSI_IP -u