08.存储Cinder→5.场景学习→03.Attach Volume→2.实际操作

背景:



描述 详细
  1. 向cinder-api发送attach请求
    1. 客户(可以是 OpenStack 最终用户,也可以是其他程序)向 cinder-api 发送请求:“请将这个 volume attach 到指定的 instance 上。”
    2. 这里我们将 volume “vol-1” attach 到 instance ”c1”上。 attach 操作之前,c1 上的虚拟磁盘是:密码是cubswin:)    。可以使用sudo -i切换到root用户
  1. 进入 GUI 操作菜单 Project -> Volumes -> Volumes,选择 volume “vol-1”,点击“Manage Attachments”
    1. 在 “Attach to Instance”下拉列表中,选择instance “c1”

  1. cinder-api 将接收到 attach volume 的请求,attach 请求实际上包含两个步骤:
    1. 初始化 volume的连接
      1. Volume 创建后,只是在 volume provider 中创建了相应存储对象(比如 LV),这时计算节点是无法使用的。Cinder-volume 需要以某种方式将 volume export 出来,计算节点才能够访问得到。这个 export 的过程就是“初始化 volume 的连接”
      2. Initialize_connection 的具体工作主要由 cinder-volume 完成,将在后面详细讨论。
    2. Attach volume
      1. 初始化 volume 连接后,计算节点将 volume 挂载到指定的 instance,完成 attach 操作。
      2. Attach 的具体工作主要由 nova-compute 完成,也将在后面详细讨论。
cloudman的cinder-api日志:



os:openstack
我的:
1
2
3
4
Jun 19 10:39:48 controller devstack@c-api.service[31309]: 
INFO cinder.api.openstack.wsgi
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ad61d583-08fe-4c0f-95e9-0d532819b2c2 admin admin]
PUT http://172.16.1.17/volume/v3/51743f081cb7477f9a1f4ccdf6490d8e/attachments/ca8...
1
2
3
4
5
6
Jun 19 10:39:48 controller devstack@c-api.service[31309]: 
DEBUG cinder.api.openstack.wsgi
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ad61d583-08fe-4c0f-95e9-0d532819b2c2 admin admin]
Action: 'update', calling method: <function version_select at 0x7f35b545ff50>,
body: {"attachment": {"connector": {"initiator": "iqn.1993-08.org.debian:01:78b9dad15bad",
{{(pid=31313) _process_stack /opt/stack/cinder/cinder/api/openstack/wsgi.py:868
_process_stack:Implement the processing stack

1
2
3
4
Jun 19 10:39:54 controller devstack@c-api.service[31309]: 
INFO cinder.api.openstack.wsgi
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ee075a89-44d9-49ba-98cb-1194235eebc4 admin admin]
POST http://172.16.1.17/volume/v3/51743f081cb7477f9a1f4ccdf6490d8e/attachments/ca804b4...
1
2
3
4
5
Jun 19 10:39:54 controller devstack@c-api.service[31309]: 
DEBUG cinder.api.openstack.wsgi
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ee075a89-44d9-49ba-98cb-1194235eebc4 admin admin]
Action body: {"os-complete": null}
{{(pid=31313) get_method /opt/stack/cinder/cinder/api/openstack/wsgi.py:985
os-complete表明请求由cinder-volume和nova-compute处理完成。看下时间就知道,此时是处理后api得到的反馈消息
get_method:Get the implementing method

  1. cinder-api 发送消息
    1. cinder-api 分两步完成 attach 操作,所以会先后向 RabbitMQ 发送了两条消息
      1. 初始化 volume 的连接
        1. 没有打印发送消息的日志,只能通过源代码查看 /opt/stack/cinder/cinder/volume/api.py,方法为 initialize_connection
  1. Attach volume
    1. 没有打印发送消息的日志,只能通过源代码查看 /opt/stack/cinder/cinder/volume/api.py,方法为 attach
  1. cinder-volume 初始化 volume 的连接
    1. 查看cinder-volume日志:cinder-volume 接收到 initialize_connection 消息后,会通过 tgt 创建 target,并将 volume 所对应的 LV 通过 target export 出来。
1
2
3
4
5
Jun 19 10:39:49 controller cinder-volume[304]: 
DEBUG cinder.volume.targets.tgt
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ad61d583-08fe-4c0f-95e9-0d532819b2c2 admin None]
Creating iscsi_target for Volume ID: volume-f0a54ac7-5423-4794-8883-d753f6a903cd
{{(pid=460) create_iscsi_target /opt/stack/cinder/cinder/volume/targets/tgt.py:162
 1
2
3
4
5
6
7
8
9
10
11
12
13
Jun 19 10:39:49 controller cinder-volume[304]: 
DEBUG cinder.volume.targets.tgt
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ad61d583-08fe-4c0f-95e9-0d532819b2c2 admin None]
Created volume path /opt/stack/data/cinder/volumes/volume-f0a54ac7-5423-4794-8883-d753f6a903cd,
Jun 19 10:39:49 controller cinder-volume[304]: content:
<target iqn.2010-10.org.openstack:volume-f0a54ac7-5423-4794-8883-d753f6a903cd>
backing-store /dev/stack-volumes-lvmdriver-1/volume-f0a54ac7-5423-4794-8883-d753f6a903cd
driver iscsi
incominguser uRAJv2FYqDckNKAsMTw9 hcASxywRe5SZ7Xou

write-cache on
</target>
{{(pid=460) create_iscsi_target /opt/stack/cinder/cinder/volume/targets/tgt.py:172
  1. 通过命令 tgtadm --lld iscsi --op show --mode target 看到已经将 1GB(1074MB)的 LV /dev/stack-volumes-lvmdriver-1/volume-f0a54ac7-5423-4794-8883-d753f6a903cd 通过 Target 1 export 出来了
1
2
3
4
5
6
Jun 19 10:39:50 controller cinder-volume[304]: 
DEBUG oslo_concurrency.processutils
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ad61d583-08fe-4c0f-95e9-0d532819b2c2 admin None]
CMD "sudo cinder-rootwrap /etc/cinder/rootwrap.conf tgtadm --lld iscsi --op show --mode target"
returned: 0 in 0.204s
{{(pid=460) execute /usr/local/lib/python2.7/dist-packages/oslo_concurrency/processutils.py:409
用法:tgtadm --lld [driver] --op [operation] --mode [mode] [OPTION]
--op new表示创建一个target;--op show表示显示target
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Jun 19 10:39:50 controller cinder-volume[304]: DEBUG cinder.volume.targets.tgt 
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ad61d583-08fe-4c0f-95e9-0d5...]
Targets after update:
Target 1: iqn.2010-10.org.openstack:volume-f0a54ac7-5423-4794-8883-d753f6a903cd
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
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path:
/dev/stack-volumes-lvmdriver-1/volume-f0a54ac7-5423-4794-8883-d753f6a903cd
...
  1. Initialize connection 完成。
cloudman:

我:
1
2
3
Jun 19 10:39:50 controller cinder-volume[304]: INFO cinder.volume.manager 
[req-d5993ab6-9ced-4267-aab8-5c993e9bad4f req-ad61d583-08fe-4c0f-95e...]
attachment_update completed successfully.
向cinder api发出attach请求时也是attachment update
  1. nova-compute 将 volume attach 到 instance
    1. 查看计算节点nova-compute日志文件:计算节点作为 iSCSI initiator 访问存储节点 Iscsi Target 上的 volume,并将其 attach 到 instance。
1
2
3
4
5
Jun 19 10:39:51 compute nova-compute[5685]: 
DEBUG nova.virt.libvirt.volume.iscsi
[None req-d5993ab6-9ced-4267-aab8-5c993e9bad4f admin admin]
Calling os-brick to attach iSCSI Volume
{{(pid=5685) connect_volume /opt/stack/nova/nova/virt/libvirt/volume/iscsi.py:63
os-brick:OpenStack Cinder brick library for managing local volume attaches,可以使用pip install os-brick安装
cinder brick:炉渣砖
  1. nova-compute 依次执行 iscsiadm 的 new, update, login, rescan 操作访问 target 上的 volume
    1. 我没有找到rescan
1
2
3
4
Jun 19 10:39:51 compute nova-compute[5685]: 
DEBUG os_brick.initiator.connectors.iscsi
[None req-d5993ab6-9ced-4267-aab8-5c993e9bad4f admin admin]
iscsiadm ('--interface', 'default', '--op', 'new'): stdout=New iSCSI node ...
1
2
3
4
5
6
Jun 19 10:39:51 compute nova-compute[5685]: 
DEBUG os_brick.initiator.connectors.iscsi
[None req-d5993ab6-9ced-4267-aab8-5c993e9bad4f admin admin]
iscsiadm ('--op', 'update', '-n', 'node.session.auth.password', '-v', u'***'): stdout= stderr=
{{(pid=5685) _run_iscsiadm
/usr/local/lib/python2.7/dist-packages/os_brick/initiator/connectors/iscsi.py:973
1
2
3
4
Jun 19 10:39:52 compute nova-compute[5685]: 
DEBUG os_brick.initiator.connectors.iscsi
[None req-d5993ab6-9ced-4267-aab8-5c993e9bad4f admin admin]
iscsiadm ('--login',): stdout=Logging in to ...
因为计算节点是iscsi客户端,因此要进行login操作
  1. 计算节点将 iSCSI target 上的 volume 识别为一个磁盘文件
先输入一行,再输入一行
1
2
3
4
root@compute:~# ll /dev/disk/by-path/ip-172.16.1.17 
> :3260-iscsi-iqn.2010-10.org.openstack:volume-f0a54ac7-5423-4794-8883-d753f6a903cd-lun-1
lrwxrwxrwx 1 root root 9 Jun 19 10:39 /dev/disk/by-path/ip-172.16.1.17:3260-iscsi-iqn.2010-10
.org.openstack:volume-f0a54ac7-5423-4794-8883-d753f6a903cd-lun-1 -> ../../sda
是/dev/sda的软连接
  1. 然后通过更新 instance 的 XML 配置文件将 volume 映射给 instance
    1. 可以看到,instance 增加了一个类型为 block 的虚拟磁盘,source 就是要 attach 的 volume,该虚拟磁盘的设备名为 vdb
 1
2
3
4
5
6
7
8
9
10
Jun 19 10:39:53 compute nova-compute[5685]: 
DEBUG nova.virt.libvirt.guest
[None req-d5993ab6-9ced-4267-aab8-5c993e9bad4f admin admin]
attach device xml: <disk type="block" device="disk">
<driver name="qemu" type="raw" cache="none" io="native"/>
<source dev="/dev/sda"/>
<target bus="virtio" dev="vdb"/>
<serial>f0a54ac7-5423-4794-8883-d753f6a903cd</serial>
</disk>
{{(pid=5685) attach_device /opt/stack/nova/nova/virt/libvirt/guest.py:305
  1. 通过在计算节点输入virsh edit instance-00000001查看更新后的 XML

source指的是宿主机的文件对应位置,比如虚机instance-00000001的vda磁盘(启动盘)。其中id号不用管(这是我后来添加的笔记)


  1.  attach 操作之后,c1 上的虚拟磁盘是:密码是cubswin:)
    1. GUI 界面也会更新相关 attach 信息

猜你喜欢

转载自www.cnblogs.com/LeisureZhao/p/11185463.html