1。起因

有两台服务器分别安装部署了openstack的管理节点和计算节点,现在想给win7实例额外挂载E盘。

两台服务器安装系统时都是在配置完boot、swap和root后,将所有剩余磁盘空间分配给了home。因此没有剩余空间创建sdb。

2。解决方案

控制节点上部署cinder,并部署iscsi target,模拟出sdb;

计算节点上安装LVM作为存储节点给cinder用,计算节点挂载控制节点上模拟出的sdb;

这样dashboard上就能创建卷创建云盘,给win7实例当作E盘使用了。

cinder和LVM的安装部署见另一个随笔。本次只描述控制节点上如何部署iscsi target。

3。详细过程

a)安装:[root@controller ~]# yum install targetcli

b)新建文件夹:[root@controller ~]# mkdir /home/targetdisk

c)运行targetcli,依次执行如下命令创建iSCSI块设备:

  [root@controller ~]# targetcli

  /> cd backstores/fileio/

  /backstores/fileio> create disk01 /home/targetdisk/disk01 40G

此时进入/home/targetdisk,就能看到大小是40G的文件disk01

(补充说明:如果如前面所述安装系统时有未分配的磁盘空间作为sdb,那么本步骤就不是进入fileio,而是进入block,然后用这个命令来创建块:create block01 /dev/sdb)

d)创建LIO iSCSI目标:

 

/> cd iscsi 
  /iscsi> create
  Created target iqn.2003-01.org.linux-iscsi.controller.x8664:sn.f9144284c7ca.
  Created TPG 1.
  Global pref auto_add_default_portal=true
  Created default portal listening on all IPs (0.0.0.0), port 3260.
  /iscsi>e)创建逻辑单元:
  /iscsi> cd iqn.2003-01.org.linux-iscsi.controller.x8664:sn.f9144284c7ca/
  /iscsi/iqn.20....f9144284c7ca> cd tpg1/luns
  /iscsi/iqn.20...7ca/tpg1/luns> create /backstores/fileio/disk01
  Created LUN 0.
f)创建网络入口:
  /iscsi/iqn.20.../tpg1/portals> create 10.47.181.26
  Using default IP port 3260
  Could not create NetworkPortal in configFS
  /iscsi/iqn.20.../tpg1/portals> ls
  o- portals ............................................................................................................ [Portals: 1]
   o- 0.0.0.0:3260 ............................................................................................................. [OK]  /iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
  Deleted network portal 0.0.0.0:3260
  /iscsi/iqn.20.../tpg1/portals> create 10.47.181.26
  Using default IP port 3260
  Created network portal 10.47.181.26:3260.g)创建访问控制列表:
  /iscsi/iqn.20.../tpg1/portals> cd ../acls 
  /iscsi/iqn.20...7ca/tpg1/acls> ls
  o- acls .................................................................................................................. [ACLs: 0]
  /iscsi/iqn.20...7ca/tpg1/acls> create iqn.1994-05.com.redhat:91a579c4e39 (create后面的内容为何是这样的还不清楚,后面再研究)
  Created Node ACL for iqn.1994-05.com.redhat:91a579c4e39
  Created mapped LUN 0.h)完成目标创建:
o- / ......................................................................................................................... [...]
 o- backstores .............................................................................................................. [...]
 | o- block .................................................................................................. [Storage Objects: 0]
 | o- fileio ................................................................................................. [Storage Objects: 1]
 | | o- disk01 ........................................................... [/home/targetdisk/disk01 (40.0GiB) write-back activated]
 | | o- alua ................................................................................................... [ALUA Groups: 1]
 | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
 | o- pscsi .................................................................................................. [Storage Objects: 0]
 | o- ramdisk ................................................................................................ [Storage Objects: 0]
 o- iscsi ............................................................................................................ [Targets: 1]
 | o- iqn.2003-01.org.linux-iscsi.controller.x8664:sn.dd2dce582c05 ...................................................... [TPGs: 1]
 | o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
 | o- acls .......................................................................................................... [ACLs: 1]
 | | o- iqn.1994-05.com.redhat:91a579c4e39 ................................................................... [Mapped LUNs: 1]
 | | o- mapped_lun0 ............................................................................... [lun0 fileio/disk01 (rw)]
 | o- luns .......................................................................................................... [LUNs: 1]
 | | o- lun0 ..................................................... [fileio/disk01 (/home/targetdisk/disk01) (default_tg_pt_gp)]
 | o- portals .................................................................................................... [Portals: 1]
 | o- 10.47.181.26:3260 ................................................................................................ [OK]
 o- loopback ......................................................................................................... [Targets: 0]i)设置认证凭证:
  /> cd iscsi/
  /iscsi> cd iqn.2003-01.org.linux-iscsi.controller.x8664:sn.f9144284c7ca/
  /iscsi/iqn.20....f9144284c7ca> cd tpg1/
  /iscsi/iqn.20...4284c7ca/tpg1> cd acls/iqn.1994-05.com.redhat:91a579c4e39/
  /iscsi/iqn.20...t:91a579c4e39> set auth userid=IncomingUser
  Parameter userid is now 'IncomingUser'.
  /iscsi/iqn.20...t:91a579c4e39> set auth password=SomePassword
  Parameter password is now 'SomePassword'.
  /iscsi/iqn.20...t:91a579c4e39> set auth mutual_userid=OutgoingUser
  Parameter mutual_userid is now 'OutgoingUser'.
  /iscsi/iqn.20...t:91a579c4e39> set auth mutual_password=AnotherPassword
  Parameter mutual_password is now 'AnotherPassword'.下面开始配置计算节点(即合一的存储节点)
a)安装:[root@compute ~]# yum install iscsi-initiator-utils
b)配置:[root@compute ~]# vi /etc/iscsi/iscsid.conf
  node.session.auth.authmethod = CHAP
  node.session.auth.username = IncomingUser
  node.session.auth.password = SomePassword
  node.session.auth.username_in = OutgoingUser
  node.session.auth.password_in = AnotherPassword
c)配置:[root@compute ~]# vi /etc/iscsi/initiatorname.iscsi   InitiatorName=iqn.1994-05.com.redhat:91a579c4e39
d)重启两个服务:
  [root@compute ~]# systemctl restart iscsi
  [root@compute ~]# systemctl restart iscsid
e)发现目标:[root@compute ~]# iscsiadm -m descovery -t sendtargets -p 10.47.181.26
f)登录目标:[root@compute ~]# iscsiadm -m node --login
g)察看磁盘吧:有sdb了:
[root@compute ~]# fdisk -l
磁盘 /dev/sda:1199.0 GB, 1198999470080 字节,2341795840 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:dos
磁盘标识符:0x00079f2a 设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 2341795839 1169848320 8e Linux LVM磁盘 /dev/mapper/centos-root:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节磁盘 /dev/mapper/centos-swap:4294 MB, 4294967296 字节,8388608 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节磁盘 /dev/mapper/centos-home:1086.3 GB, 1086253432832 字节,2121588736 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节磁盘 /dev/sdb:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 4194304 字节