jlo86 发表于 2016-1-20 08:20:34

openstack运维实战系列(三)之cinder磁盘挂载

1. 概述
    openstack的cinder项目负责volume的服务,即虚拟机的外挂存储,cinder作为管理存储的工具,可以支持LVM,glusterfs,ceph,sleepdog等开源的存储方案,同时也提供了对HP,IBM,huawei等商业存储的支持,配置完cinder之后,即可对虚拟机分配存储空间,如下给虚拟机分配cinder存储空间为例,讲述cinder的使用方法。

2. 磁盘挂载

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# nova list |grep 10.16.6.52
| 1809ae2e-7e29-4203-930b-494de426bf8e | Dev_20151201_01      | ACTIVE| -          | Running   | vmPrivate=10.16.6.52   | ChuangYiYuan_10_16_2_13 |
# cinder create --display-name "storage_10.16.6.52" 20    #划分一个20G的磁盘   
+---------------------+--------------------------------------+
|       Property      |                Value               |
+---------------------+--------------------------------------+
|   attachments   |                  []                  |
|availability_zone|               nova               |
|       bootable      |                false               |
|      created_at   |      2016-01-19T08:58:29.819663      |
| display_description |               None               |
|   display_name    |          storage_10.16.6.52          |
|      encrypted      |                False               |
|          id         | e5ef5ad4-ddc4-4675-95bf-726473c4c62d |                #获取cinder-volume的id号码,用于和instance关联
|       metadata      |                  {}                  |
|         size      |                  20                  |
|   snapshot_id   |               None               |
|   source_volid    |               None               |
|      status       |               creating               |
|   volume_type   |               None               |
+---------------------+--------------------------------------+

将cinder和虚拟机关联
# nova volume-attach 1809ae2e-7e29-4203-930b-494de426bf8ee5ef5ad4-ddc4-4675-95bf-726473c4c62d   
+----------+--------------------------------------+
| Property | Value                              |
+----------+--------------------------------------+
| device   | /dev/vdc                           |      #虚拟机将会识别为vdc设备
| id       | e5ef5ad4-ddc4-4675-95bf-726473c4c62d |
| serverId | 1809ae2e-7e29-4203-930b-494de426bf8e |
| volumeId | e5ef5ad4-ddc4-4675-95bf-726473c4c62d |
+----------+--------------------------------------+

查看cinder的情况
# cinder show e5ef5ad4-ddc4-4675-95bf-726473c4c62d
+--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+
|            Property            |                                                                                                    Value                                                                                                   |
+--------------------------------+-------------------------------------------------------------------------------------------------------------------------------------+
|          attachments         | [{u'device': u'/dev/vdc', u'server_id': u'1809ae2e-7e29-4203-930b-494de426bf8e', u'id': u'e5ef5ad4-ddc4-4675-95bf-726473c4c62d', u'host_name': None, u'volume_id': u'e5ef5ad4-ddc4-4675-95bf-726473c4c62d'}] |
|       availability_zone      |                                                                                                   nova                                                                                                   |
|            bootable            |                                                                                                    false                                                                                                   |
|         created_at         |                                                                                          2016-01-19T08:58:29.000000                                                                                          |
|      display_description       |                                                                                                   None                                                                                                   |
|          display_name          |                                                                                              storage_10.16.6.52                                                                                              |
|         encrypted            |                                                                                                    False                                                                                                   |
|               id               |                                                                                     e5ef5ad4-ddc4-4675-95bf-726473c4c62d                                                                                     |
|            metadata            |                                                                               {u'readonly': u'False', u'attached_mode': u'rw'}                                                                               |
|   os-vol-host-attr:host      |                                                                                          ChuangYiYuan_10_16_2_7                                                                                          |
| os-vol-mig-status-attr:migstat |                                                                                                   None                                                                                                   |
| os-vol-mig-status-attr:name_id |                                                                                                   None                                                                                                   |
|os-vol-tenant-attr:tenant_id|                                                                                       842ab3268a2c47e6a4b0d8774de805ae                                                                                       |
|            size            |                                                                                                      20                                                                                                      |
|          snapshot_id         |                                                                                                   None                                                                                                   |
|          source_volid          |                                                                                                   None                                                                                                   |
|             status             |                                                                                                    in-use                                                                                                    |
|          volume_type         |                                                                                                   None                                                                                                   |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------+





3. 格式化磁盘

[*]查看系统识别的disk


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether fa:16:3e:d5:e1:4e brd ff:ff:ff:ff:ff:ff
    inet 10.16.6.52/23 brd 10.16.7.255 scope global eth0
# dmesg | tail -10
pci 0000:00:07.0: using default PCI settings
virtio-pci 0000:00:07.0: enabling device (0000 -> 0003)
virtio-pci 0000:00:07.0: PCI INT A -> Link -> GSI 10 (level, high) -> IRQ 10
alloc irq_desc for 31 on node -1
alloc kstat_irqs on node -1
virtio-pci 0000:00:07.0: irq 31 for MSI/MSI-X
alloc irq_desc for 32 on node -1
alloc kstat_irqs on node -1
virtio-pci 0000:00:07.0: irq 32 for MSI/MSI-X
vdc: unknown partition table            #磁盘识别为vdc




2. 分区与格式化

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
39
40
41
42
43
44
45
46
47
48
49
# fdisk /dev/vdc               #磁盘分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x115a4ff3.
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 sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
# partprobe /dev/vdc
# mkfs.ext4 /dev/vdc1             #格式化
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
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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, 2654208,
      4096000

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.Use tune2fs -c or -i to override.




3. 挂载使用

1
2
3
4
5
# mkdir /data2
# mount /dev/vdc1 /data2/
# df -h /data2/
Filesystem            SizeUsed Avail Use% Mounted on
/dev/vdc1            20G172M   19G   1% /data2





4. 总结
    cinder作为一种外挂的存储,在openstack中用于数据存储有非常关键的作用,并且在openstack中,使用cinder非常方便,创建和关联,轻松就可以实现任意大小磁盘的分配,实现高效的管理。

页: [1]
查看完整版本: openstack运维实战系列(三)之cinder磁盘挂载