20 实例使用-Cinder存储服务组件
参考博客:https://www.cnblogs.com/Wang-Hongwei/p/13132238.html
20.1 使用块存储服务向实例提供数据盘
创建卷(volume)创建一个10 GB的卷:
cd
source admin-openrc.sh
openstack volume create --size 10 volume1
[root@controller ~]# cd
[root@controller ~]# source admin-openrc.sh
[root@controller ~]# openstack volume create --size 10 volume1
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2022-10-06T03:09:30.000000 |
| description | None |
| encrypted | False |
| id | 7035c7a1-2006-42ef-974b-13fcc9992513 |
| migration_status | None |
| multiattach | False |
| name | volume1 |
| properties | |
| replication_status | None |
| size | 10 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | __DEFAULT__ |
| updated_at | None |
| user_id | a10b16e624f847229868a23c650c0ac7 |
+---------------------+--------------------------------------+
[root@controller ~]#
很短的时间后,卷状态应该从creating 到available
openstack volume list
[root@controller ~]# openstack volume list
+--------------------------------------+---------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+---------+-----------+------+-------------+
| 7035c7a1-2006-42ef-974b-13fcc9992513 | volume1 | available | 10 | |
+--------------------------------------+---------+-----------+------+-------------+
[root@controller ~]#
20.2 将卷附加到实例
openstack server add volume INSTANCE_NAME VOLUME_NAME
将volume1卷附加到provider-instance实例:
openstack server add volume provider-instance volume1
openstack volume list
[root@controller ~]# openstack server add volume provider-instance volume1
[root@controller ~]#
[root@controller ~]# openstack volume list
+--------------------------------------+---------+--------+------+--------------------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+---------+--------+------+--------------------------------------------+
| 7035c7a1-2006-42ef-974b-13fcc9992513 | volume1 | in-use | 10 | Attached to provider-instance on /dev/vdb |
+--------------------------------------+---------+--------+------+--------------------------------------------+
[root@controller ~]#
20.3 登录实例,并使用以下fdisk命令验证该卷是否作为/dev/vdb块存储设备
ssh cirros@10.224.4.8
sudo fdisk -l
[root@controller ~]# ssh cirros@10.224.4.8
$
$ sudo fdisk -l
Disk /dev/vda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/vda1 * 16065 20964824 10474380 83 Linux
Disk /dev/vdb: 10.7 GB, 10737418240 bytes
16 heads, 63 sectors/track, 20805 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/vdb doesn't contain a valid partition table
$
20.3.1 分区并格式化新添加的/dev/vdb
sudo fdisk /dev/vdb
$ sudo fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x4ae0378d.
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
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
$
20.3.2 查看创建的主分区
ls /dev/vdb*
$ ls /dev/vdb*
/dev/vdb /dev/vdb1
$
20.3.3 格式化、创建文件系统
sudo mkfs.ext4 /dev/vdb1
$ sudo mkfs.ext3 /dev/vdb1
mke2fs 1.42.2 (27-Mar-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621184 blocks
131059 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
$
20.3.4 临时挂载
sudo mount /dev/vdb1 /mnt/
df -h|tail -1
$ sudo mount /dev/vdb1 /mnt/
$ df -h|tail -1
/dev/vdb1 9.8G 150.6M 9.2G 2% /mnt
$
20.3.5 永久挂载
sudo su -
echo '/dev/vdb1 /mnt/ ext3 defaults 0 0' >>/etc/fstab
$ sudo su -
# echo '/dev/vdb1 /mnt/ ext3 defaults 0 0' >>/etc/fstab
#
有什么吐槽或反馈意见,直接告诉我!
我会解决您说的问题!
温馨提示:如出现二维码失效也可直接添加微信号:ysc13803862469。
