跳转至

14. 安装块存储服务cinder——存储节点

1. 添加硬盘

1. 添加第一块30G的硬盘

# compute1
# 打开虚拟机设置,点击左下角的添加,选择硬盘,然后下一步!

img_33.png

# 一路默认,大小改为30G

img_34.png

2. 添加第二块10G的硬盘

# 操作同上,唯一区别是将存储在单个文件(老师2个都是这么选的,我也不知道什么区别。百度一下吧。)

img_35.png

2. 查看新加磁盘

#1.查看磁盘,发现没有刚添加的2块硬盘
fdisk -l

#2.执行如下命令,让系统再扫描一下硬盘
echo '- - -' >/sys/class/scsi_host/host0/scan

#3.再次查看磁盘
fdisk -l
[root@compute1 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk identifier: 0x000a2c65

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     4196351     2097152   82  Linux swap / Solaris
/dev/sda2   *     4196352   104857599    50330624   83  Linux
[root@compute1 ~]#
[root@compute1 ~]#
[root@compute1 ~]#
[root@compute1 ~]# echo '- - -' >/sys/class/scsi_host/host0/scan
[root@compute1 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk identifier: 0x000a2c65

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     4196351     2097152   82  Linux swap / Solaris
/dev/sda2   *     4196352   104857599    50330624   83  Linux

Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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 /dev/sdc: 10.7 GB, 10737418240 bytes, 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

[root@compute1 ~]#

3. 创建pv卷和卷组

#1.创建物理卷
pvcreate /dev/sdb
pvcreate /dev/sdc

#2.创建卷组
vgcreate cinder-ssd /dev/sdb
vgcreate cinder-sata /dev/sdc

#3.查看物理卷、卷组、逻辑卷
pvs
vgs
#因为现在没有创建逻辑卷,所以还没有!
lvs
[root@compute1 ~]# #1.pv卷
[root@compute1 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@compute1 ~]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.
[root@compute1 ~]#
[root@compute1 ~]# #2.卷组
[root@compute1 ~]# vgcreate cinder-ssd /dev/sdb
  Volume group "cinder-ssd" successfully created
[root@compute1 ~]# vgcreate cinder-sata /dev/sdc
  Volume group "cinder-sata" successfully created
[root@compute1 ~]#
[root@compute1 ~]# pvs
  PV         VG          Fmt  Attr PSize   PFree
  /dev/sdb   cinder-ssd  lvm2 a--  <30.00g <30.00g
  /dev/sdc   cinder-sata lvm2 a--  <10.00g <10.00g
[root@compute1 ~]#
[root@compute1 ~]# vgs
  VG          #PV #LV #SN Attr   VSize   VFree
  cinder-sata   1   0   0 wz--n- <10.00g <10.00g
  cinder-ssd    1   0   0 wz--n- <30.00g <30.00g
[root@compute1 ~]#
[root@compute1 ~]# lvs

1. 注意:如果没有命令,则安装软件lvm2

#先决条件
yum install lvm2 -y
systemctl enable lvm2-lvmetad.service
systemctl start lvm2-lvmetad.service

2. 逻辑卷原理图

img_36.png

4. 修改lvm.conf配置文件

###修改/etc/lvm/lvm.conf
vim /etc/lvm/lvm.conf

#在130下面插入一行:
filter = [ "a/sdb/", "a/sdc/","r/.*/"]
# 这一行的意思是,把sdb和sdc加入到过滤器中,只允许实例使用,详情见官方文档!!!
# 它不需要重启就生效了!!!

5. 安装cinder相关软件

#安装
yum install openstack-cinder targetcli python-keystone -y

6. 修改cinder.conf配置文件

vim /etc/cinder/cinder.conf
# 写入以下内容
[DEFAULT]
rpc_backend = rabbit
auth_strategy = keystone
my_ip = 192.168.178.31  #注意修改这里的IP,不要把这行复制到配置文件!
glance_api_servers = http://192.168.178.32:9292 #注意修改这里的IP,不要把这行复制到配置文件!
enabled_backends = ssd,sata
[BACKEND]
[BRCD_FABRIC_EXAMPLE]
[CISCO_FABRIC_EXAMPLE]
[COORDINATION]
[FC-ZONE-MANAGER]
[KEYMGR]
[cors]
[cors.subdomain]
[database]
connection = mysql+pymysql://cinder:CINDER_DBPASS@controller/cinder
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = CINDER_PASS
[matchmaker_redis]
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
[oslo_messaging_amqp]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = RABBIT_PASS
[oslo_middleware]
[oslo_policy]
[oslo_reports]
[oslo_versionedobjects]
[ssl]
[ssd]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-ssd
iscsi_protocol = iscsi
iscsi_helper = lioadm
volume_backend_name = ssd
[sata]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-sata
iscsi_protocol = iscsi
iscsi_helper = lioadm
volume_backend_name = sata

7. 启动cinder-volume服务和target服务

systemctl enable openstack-cinder-volume.service target.service
systemctl start openstack-cinder-volume.service target.service

8. 查看cinder服务列表

#controller
cinder service-list
[root@controller ~]# cinder service-list
+------------------+---------------+------+---------+-------+----------------------------+-----------------+
|      Binary      |      Host     | Zone |  Status | State |         Updated_at         | Disabled Reason |
+------------------+---------------+------+---------+-------+----------------------------+-----------------+
| cinder-scheduler |   controller  | nova | enabled |   up  | 2021-12-05T12:02:48.000000 |        -        |
|  cinder-volume   | compute1@sata | nova | enabled |   up  | 2021-12-05T12:02:48.000000 |        -        |
|  cinder-volume   |  compute1@ssd | nova | enabled |   up  | 2021-12-05T12:02:48.000000 |        -        |
+------------------+---------------+------+---------+-------+----------------------------+-----------------+

9. 创建卷测试

1. 浏览器中创建卷

# 192.168.178.31/dashboard/
# 点击左侧的项目-卷,然后右上角的创建卷,输入卷名称:test,然后点击创建卷

img_43.png

2. cinder存储节点查看

# compute1
lvs
[root@compute1 ~]# lvs
  LV                                          VG         Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  volume-4c031015-db74-4265-9074-eeb08872e680 cinder-ssd -wi-a----- 1.00g
#发现4c031015-db74-4265-9074-eeb08872e680这个id与浏览器中的test一致!

img_44.png

10. 给实例添加硬盘

1. 进入实例中,查看磁盘

# 远程登录到实例中
ssh cirros@192.168.178.115
fdisk -l
sudo su -
fdisk -l
[root@controller ~]# ssh cirros@192.168.178.115
cirros@192.168.178.115's password:
$
$
$ fdisk -l
$
$ sudo su -
#
# fdisk -l

Disk /dev/vda: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders, total 2097152 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     2088449     1036192+  83  Linux

2. 给实例添加硬盘

# 点击左侧额项目-卷,然后找到test卷,在最右侧的下拉中,点击管理连接

img_42.png

# 在连接至实例下拉中,选择刚刚远程连接到的实例!

img_40.png

3. 再次进入实例,查看磁盘

fdisk -l
# 发现多出来一个/dev/vdb,大小为1G
# fdisk -l

Disk /dev/vda: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders, total 2097152 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     2088449     1036192+  83  Linux

Disk /dev/vdb: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders, total 2097152 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

4. 将新硬盘格式化

mkfs.ext4 /dev/vdb
# mkfs.ext4 /dev/vdb
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
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

#

5. 挂载新硬盘

#查看硬盘
df -h

#挂载
mount /dev/vdb /mnt

#再次查看硬盘,看是否挂载成功!
df -h
# #查看硬盘
# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev                     21.3M         0     21.3M   0% /dev
/dev/vda1                23.2M     18.0M      4.0M  82% /
tmpfs                    24.8M         0     24.8M   0% /dev/shm
tmpfs                   200.0K     68.0K    132.0K  34% /run
#
# #挂载
# mount /dev/vdb /mnt
#
# #再次查看硬盘
# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev                     21.3M         0     21.3M   0% /dev
/dev/vda1                23.2M     18.0M      4.0M  82% /
tmpfs                    24.8M         0     24.8M   0% /dev/shm
tmpfs                   200.0K     68.0K    132.0K  34% /run
/dev/vdb               1007.9M     33.3M    923.4M   3% /mnt

6. 放入文件测试

cp /etc/services /mnt
ls -l /mnt
# cp /etc/services /mnt
# ls -l /mnt
total 28
drwx------    2 root     root         16384 Dec  5 12:37 lost+found
-rw-------    1 root     root         10873 Dec  5 12:39 services

11. 扩容卷

1. 取消挂载

#1.先取消挂载
umount /dev/vdb

df -h
# umount /dev/vdb
#
# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev                     21.3M         0     21.3M   0% /dev
/dev/vda1                23.2M     18.0M      4.0M  82% /
tmpfs                    24.8M         0     24.8M   0% /dev/shm
tmpfs                   200.0K     68.0K    132.0K  34% /run
#

2. 分离卷

#2.分离卷
# 点击项目-卷,下拉中点击管理卷,然后点击分离卷!

img_41.png

3. 扩展卷

#3.扩展卷
# 在右侧下拉中,点击扩展卷,在新大小中输入:2,然后点击扩展

img_45.png

4. 再次将卷连接至实例

# 在卷最右侧的下拉中,点击管理卷,然后连接至实例:test!

5. 实例中查看硬盘

# fdisk -l

Disk /dev/vda: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders, total 2097152 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     2088449     1036192+  83  Linux

Disk /dev/vdb: 2147 MB, 2147483648 bytes
16 heads, 63 sectors/track, 4161 cylinders, total 4194304 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

6. 再次挂载

#test实例中
mount /dev/vdb /mnt
df -h
# 发现硬盘还是1G
# mount /dev/vdb /mnt
# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev                     21.3M         0     21.3M   0% /dev
/dev/vda1                23.2M     18.0M      4.0M  82% /
tmpfs                    24.8M         0     24.8M   0% /dev/shm
tmpfs                   200.0K     68.0K    132.0K  34% /run
/dev/vdb               1007.9M     33.3M    923.4M   3% /mnt

7. 执行resize

resize2fs /mnt
df -h
# 发现硬盘已经变成2G了
# resize2fs /mnt
resize2fs 1.42.2 (27-Mar-2012)
open: Is a directory while opening /mnt
# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev                     21.3M         0     21.3M   0% /dev
/dev/vda1                23.2M     18.0M      4.0M  82% /
tmpfs                    24.8M         0     24.8M   0% /dev/shm
tmpfs                   200.0K     68.0K    132.0K  34% /run
/dev/vdb                  2.0G     67.0M      1.8G   4% /mnt

8. 查看文件

ls -l /mnt
#发现之前的文件还在!!!
# ls -l /mnt
total 28
drwx------    2 root     root         16384 Dec  5 12:37 lost+found
-rw-------    1 root     root         10873 Dec  5 12:39 services

12. 老师演示云主机上数据不安全

1. 查看逻辑卷

#compute1
lvs
[root@compute1 ~]# lvs
  LV                                          VG         Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  volume-4c031015-db74-4265-9074-eeb08872e680 cinder-ssd -wi-ao---- 2.00g

2. dd逻辑卷

#将你的逻辑卷完整的dd出来就行了
cd /opt
dd if=/dev/mapper/cinder--ssd-volume--4c031015--db74--4265--9074--eeb08872e680 of=/opt/test.raw
ls -l
[root@compute1 opt]# dd if=/dev/mapper/cinder--ssd-volume--4c031015--db74--4265--9074--eeb08872e680 of=/opt/test.raw
4194304+0 records in
4194304+0 records out
2147483648 bytes (2.1 GB) copied, 8.27173 s, 260 MB/s
[root@compute1 opt]# ls -l
total 2338876
-rw-r--r-- 1 root root  247468369 Dec  1 19:36 openstack_rpm.tar.gz
drwxr-xr-x 3 root root      36864 Jul 19  2017 repo
-rw-r--r-- 1 root root 2147483648 Dec  5 21:04 test.raw

3. 查看格式

qemu-img info test.raw
#发现是raw格式!
[root@compute1 opt]# qemu-img info test.raw
image: test.raw
file format: raw
virtual size: 2.0G (2147483648 bytes)
disk size: 2.0G

4. 挂载该文件

mount -o loop /opt/test.raw /srv
df -h
[root@compute1 opt]# mount -o loop /opt/test.raw /srv
[root@compute1 opt]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        48G  5.9G   43G  13% /
devtmpfs        983M     0  983M   0% /dev
tmpfs           993M     0  993M   0% /dev/shm
tmpfs           993M  8.9M  984M   1% /run
tmpfs           993M     0  993M   0% /sys/fs/cgroup
/dev/sr0        4.3G  4.3G     0 100% /mnt
tmpfs           199M     0  199M   0% /run/user/0
/dev/loop0      2.0G  3.1M  1.8G   1% /srv

5. 进入/srv下查看

cd /srv
ls -l
# 所有数据都在这里能看到!!!
[root@compute1 srv]# ls -l
total 28
drwx------ 2 root root 16384 Dec  5 20:49 lost+found
-rw------- 1 root root 10873 Dec  5 21:00 services

6. 老师建议

# 小公司可能看不上,大公司的话,尽量物理机或者自建机房!!!

13. 创建卷类型

# 因为新的硬盘不能自己选择,所以添加卷类型实现自己选择!

1. 查看配置文件

cat /etc/cinder/cinder.conf
#查看最后几行
[ssd]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-ssd
iscsi_protocol = iscsi
iscsi_helper = lioadm
volume_backend_name = ssd
[sata]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-sata
iscsi_protocol = iscsi
iscsi_helper = lioadm
volume_backend_name = sata
# 得到区分字段:volume_backend_name

2. 创建卷类型

# 点击左侧的管理员-卷,然后点击右上角的创建卷类型,输入名称:sata,然后创建

img_46.png

3. 创建卷类型extra spec

# 找到刚才新建的卷类型,在最右侧的下拉中,点击extra spec,然后点击已创建

img_47.png

# 键:填入前面得到的区分字段:volume_backend_name
# 值:sata

img_48.png

4. 再创建一个卷类型——ssd

# 创建卷类型ssd,然后添加额外属性ssd

img_49.png

14. 创建带卷类型的卷

1. 创建卷

#点击左侧的项目-卷,然后右上角的创建卷,输入卷名称:ssd-test,类型选择ssd,大小5G,然后创建

img_50.png

# 按同样方法,在创建一个,卷名称:sata-test,类型:sata,大小2G,创建

img_51.png

2. 查看

# compute1
lvs
[root@compute1 ~]# lvs
  LV                                          VG          Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  volume-7971fe2a-846a-47df-879f-73297c2bee79 cinder-sata -wi-a----- 2.00g  #这是刚才建的第二个卷
  volume-4c031015-db74-4265-9074-eeb08872e680 cinder-ssd  -wi-ao---- 2.00g
  volume-de15a147-6683-41a7-9a81-e4dfc6686a39 cinder-ssd  -wi-a----- 5.00g  #这是刚才建的第一个卷

3. 结论

# 通过设置卷类型,就可以实现自己选择要挂载到什么类型的硬盘上了!!!

最后更新: 2022-02-20 04:00:12