块存储 (Block Storage):Cinder。为运行实例提供稳定的数据块存储服务,它的插件驱动架构有利于块设备的创建和管理,如创建卷、删除卷,在实例上挂载和卸载卷。自Folsom版本集成到项目中。
单独的说,假如我运行的虚拟化实例的硬盘不够了该怎么办?我们就可以使用Cinder来解决该问题。
一、我们在控制节点安装块存储服务
1. 约定: Keystone使用MySQL数据库存储相关数据,相关参数如下:
库名: cinder
账户: cinderdbadmin
密码: cinder4smtest
2. 安装块存储服务包
sudo apt-get install cinder-api cinder-scheduler
sm@controller:~$ sudo apt-get install cinder-api cinder-scheduler Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: cinder-common python-cinder python-concurrent.futures python-networkx python-taskflow Suggested packages: python-ceph python-hp3parclient python-scipy python-pydot The following NEW packages will be installed: cinder-api cinder-common cinder-scheduler python-cinder python-concurrent.futures python-networkx python-taskflow 0 upgraded, 7 newly installed, 0 to remove and 122 not upgraded. Need to get 1,515 kB of archives. After this operation, 31.6 MB of additional disk space will be used. Do you want to continue? [Y/n] y WARNING: The following packages cannot be authenticated! python-concurrent.futures python-networkx python-taskflow python-cinder cinder-common cinder-api cinder-scheduler Install these packages without verification? [y/N] y Get:1 http://192.168.3.199/openstack/ trusty/icehouse python-concurrent.futures all 2.1.6-3 [32.8 kB] Get:2 http://192.168.3.199/openstack/ trusty/icehouse python-networkx all 1.8.1-0ubuntu3 [506 kB] Get:3 http://192.168.3.199/openstack/ trusty/icehouse python-taskflow all 0.1.3-0ubuntu3 [105 kB] Get:4 http://192.168.3.199/openstack/ trusty/icehouse python-cinder all 1:2014.1.3-0ubuntu1.1 [852 kB] Get:5 http://192.168.3.199/openstack/ trusty/icehouse cinder-common all 1:2014.1.3-0ubuntu1.1 [12.4 kB] Get:6 http://192.168.3.199/openstack/ trusty/icehouse cinder-api all 1:2014.1.3-0ubuntu1.1 [3,434 B] Get:7 http://192.168.3.199/openstack/ trusty/icehouse cinder-scheduler all 1:2014.1.3-0ubuntu1.1 [3,490 B] Fetched 1,515 kB in 0s (5,286 kB/s) Selecting previously unselected package python-concurrent.futures. (Reading database ... 85107 files and directories currently installed.) Preparing to unpack .../python-concurrent.futures_2.1.6-3_all.deb ... Unpacking python-concurrent.futures (2.1.6-3) ... Selecting previously unselected package python-networkx. Preparing to unpack .../python-networkx_1.8.1-0ubuntu3_all.deb ... Unpacking python-networkx (1.8.1-0ubuntu3) ... Selecting previously unselected package python-taskflow. Preparing to unpack .../python-taskflow_0.1.3-0ubuntu3_all.deb ... Unpacking python-taskflow (0.1.3-0ubuntu3) ... Selecting previously unselected package python-cinder. Preparing to unpack .../python-cinder_1%3a2014.1.3-0ubuntu1.1_all.deb ... Unpacking python-cinder (1:2014.1.3-0ubuntu1.1) ... Selecting previously unselected package cinder-common. Preparing to unpack .../cinder-common_1%3a2014.1.3-0ubuntu1.1_all.deb ... Unpacking cinder-common (1:2014.1.3-0ubuntu1.1) ... Selecting previously unselected package cinder-api. Preparing to unpack .../cinder-api_1%3a2014.1.3-0ubuntu1.1_all.deb ... Unpacking cinder-api (1:2014.1.3-0ubuntu1.1) ... Selecting previously unselected package cinder-scheduler. Preparing to unpack .../cinder-scheduler_1%3a2014.1.3-0ubuntu1.1_all.deb ... Unpacking cinder-scheduler (1:2014.1.3-0ubuntu1.1) ... Processing triggers for man-db (2.6.7.1-1) ... Processing triggers for ureadahead (0.100.0-16) ... Setting up python-concurrent.futures (2.1.6-3) ... Setting up python-networkx (1.8.1-0ubuntu3) ... Setting up python-taskflow (0.1.3-0ubuntu3) ... Setting up python-cinder (1:2014.1.3-0ubuntu1.1) ... Setting up cinder-common (1:2014.1.3-0ubuntu1.1) ... Adding system user `cinder' (UID 117) ... Adding new user `cinder' (UID 117) with group `cinder' ... Not creating home directory `/var/lib/cinder'. 2015-04-26 13:44:11.786 17960 INFO migrate.versioning.api [-] 0 -> 1... 2015-04-26 13:44:11.855 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:11.855 17960 INFO migrate.versioning.api [-] 1 -> 2... 2015-04-26 13:44:11.886 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:11.886 17960 INFO migrate.versioning.api [-] 2 -> 3... 2015-04-26 13:44:11.898 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:11.898 17960 INFO migrate.versioning.api [-] 3 -> 4... 2015-04-26 13:44:11.957 17960 INFO 004_volume_type_to_uuid [-] Created foreign key None 2015-04-26 13:44:11.962 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:11.963 17960 INFO migrate.versioning.api [-] 4 -> 5... 2015-04-26 13:44:11.974 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:11.975 17960 INFO migrate.versioning.api [-] 5 -> 6... 2015-04-26 13:44:11.987 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:11.987 17960 INFO migrate.versioning.api [-] 6 -> 7... 2015-04-26 13:44:12.008 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.008 17960 INFO migrate.versioning.api [-] 7 -> 8... 2015-04-26 13:44:12.019 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.020 17960 INFO migrate.versioning.api [-] 8 -> 9... 2015-04-26 13:44:12.033 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.033 17960 INFO migrate.versioning.api [-] 9 -> 10... 2015-04-26 13:44:12.047 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.047 17960 INFO migrate.versioning.api [-] 10 -> 11... 2015-04-26 13:44:12.064 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.064 17960 INFO migrate.versioning.api [-] 11 -> 12... 2015-04-26 13:44:12.078 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.078 17960 INFO migrate.versioning.api [-] 12 -> 13... 2015-04-26 13:44:12.157 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.157 17960 INFO migrate.versioning.api [-] 13 -> 14... 2015-04-26 13:44:12.172 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.172 17960 INFO migrate.versioning.api [-] 14 -> 15... 2015-04-26 13:44:12.184 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.184 17960 INFO migrate.versioning.api [-] 15 -> 16... 2015-04-26 13:44:12.212 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.212 17960 INFO migrate.versioning.api [-] 16 -> 17... 2015-04-26 13:44:12.243 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.243 17960 INFO migrate.versioning.api [-] 17 -> 18... 2015-04-26 13:44:12.267 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.267 17960 INFO migrate.versioning.api [-] 18 -> 19... 2015-04-26 13:44:12.279 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.279 17960 INFO migrate.versioning.api [-] 19 -> 20... 2015-04-26 13:44:12.294 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.295 17960 INFO migrate.versioning.api [-] 20 -> 21... 2015-04-26 13:44:12.311 17960 INFO 021_add_default_quota_class [-] Added default quota class data into the DB. 2015-04-26 13:44:12.317 17960 INFO migrate.versioning.api [-] done 2015-04-26 13:44:12.317 17960 INFO migrate.versioning.api [-] 21 -> 22... 2015-04-26 13:44:12.364 17960 INFO migrate.versioning.api [-] done Setting up cinder-api (1:2014.1.3-0ubuntu1.1) ... cinder-api start/running, process 18006 Setting up cinder-scheduler (1:2014.1.3-0ubuntu1.1) ... cinder-scheduler start/running, process 18045 Processing triggers for ureadahead (0.100.0-16) ...
3. 编辑 /etc/cinder/cinder.conf 【sudo vi /etc/cinder/cinder.conf 】,设置数据库、消息服务及IP相关参数,内容大致如下
[database] connection = mysql://cinderdbadmin:[email protected]/cinder
sm@controller:~$ sudo rm /var/lib/cinder/cinder.sqlite
5、创建数据库、账户并配置权限
sm@controller:~$ sudo mysql -uroot -p#db4smtest# -e 'CREATE DATABASE cinder;' sm@controller:~$ sudo mysql -uroot -p#db4smtest# -e 'CREATE USER cinderdbadmin;' sm@controller:~$ sudo mysql -uroot -p#db4smtest# -e "GRANT ALL PRIVILEGES ON cinder.* TO 'cinderdbadmin'@'localhost' IDENTIFIED BY 'cinder4smtest';" sm@controller:~$ sudo mysql -uroot -p#db4smtest# -e "GRANT ALL PRIVILEGES ON cinder.* TO 'cinderdbadmin'@'%' IDENTIFIED BY 'cinder4smtest';" sm@controller:~$ sudo mysql -uroot -p#db4smtest# -e "SET PASSWORD FOR 'cinderdbadmin'@'%' = PASSWORD('cinder4smtest');"
6、创建Cinder 服务表
sm@controller:~$ sudo cinder-manage db sync 2015-04-26 13:47:57.443 18490 INFO migrate.versioning.api [-] 0 -> 1... 2015-04-26 13:47:57.859 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:57.859 18490 INFO migrate.versioning.api [-] 1 -> 2... 2015-04-26 13:47:58.074 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.075 18490 INFO migrate.versioning.api [-] 2 -> 3... 2015-04-26 13:47:58.145 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.145 18490 INFO migrate.versioning.api [-] 3 -> 4... 2015-04-26 13:47:58.330 18490 INFO 004_volume_type_to_uuid [-] Created foreign key volume_type_extra_specs_ibfk_1 2015-04-26 13:47:58.336 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.336 18490 INFO migrate.versioning.api [-] 4 -> 5... 2015-04-26 13:47:58.356 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.356 18490 INFO migrate.versioning.api [-] 5 -> 6... 2015-04-26 13:47:58.376 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.377 18490 INFO migrate.versioning.api [-] 6 -> 7... 2015-04-26 13:47:58.402 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.403 18490 INFO migrate.versioning.api [-] 7 -> 8... 2015-04-26 13:47:58.419 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.419 18490 INFO migrate.versioning.api [-] 8 -> 9... 2015-04-26 13:47:58.455 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.456 18490 INFO migrate.versioning.api [-] 9 -> 10... 2015-04-26 13:47:58.482 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.482 18490 INFO migrate.versioning.api [-] 10 -> 11... 2015-04-26 13:47:58.506 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.506 18490 INFO migrate.versioning.api [-] 11 -> 12... 2015-04-26 13:47:58.525 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.525 18490 INFO migrate.versioning.api [-] 12 -> 13... 2015-04-26 13:47:58.543 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.543 18490 INFO migrate.versioning.api [-] 13 -> 14... 2015-04-26 13:47:58.572 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.572 18490 INFO migrate.versioning.api [-] 14 -> 15... 2015-04-26 13:47:58.583 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.583 18490 INFO migrate.versioning.api [-] 15 -> 16... 2015-04-26 13:47:58.602 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.602 18490 INFO migrate.versioning.api [-] 16 -> 17... 2015-04-26 13:47:58.681 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.681 18490 INFO migrate.versioning.api [-] 17 -> 18... 2015-04-26 13:47:58.754 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.754 18490 INFO migrate.versioning.api [-] 18 -> 19... 2015-04-26 13:47:58.771 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.771 18490 INFO migrate.versioning.api [-] 19 -> 20... 2015-04-26 13:47:58.809 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.809 18490 INFO migrate.versioning.api [-] 20 -> 21... 2015-04-26 13:47:58.819 18490 INFO 021_add_default_quota_class [-] Added default quota class data into the DB. 2015-04-26 13:47:58.823 18490 INFO migrate.versioning.api [-] done 2015-04-26 13:47:58.823 18490 INFO migrate.versioning.api [-] 21 -> 22... 2015-04-26 13:47:58.837 18490 INFO migrate.versioning.api [-] done
7、创建cinder Service 账号并设置角色
sm@controller:~$ keystone user-create --name=cinder --pass=cinder4smtest [email protected] +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | email | [email protected] | | enabled | True | | id | f43dfa180c1b4e6da70a9b4e2a9a6421 | | name | cinder | | username | cinder | +----------+----------------------------------+ sm@controller:~$ keystone user-role-add --user=cinder --tenant=service --role=admin
8、编辑vi /etc/cinder/cinder.conf配置文件,添加如下项
[database] connection = mysql://cinderdbadmin:[email protected]/cinder auth_strategy = keystone rpc_backend = cinder.openstack.common.rpc.impl_kombu rabbit_host = 192.168.3.180 rabbit_port = 5672 rabbit_userid = guest rabbit_password = mq4smtest [keystone_authtoken] auth_uri = http://192.168.3.180:5000 auth_host = 192.168.3.180 auth_port = 35357 auth_protocol = http admin_tenant_name = service admin_user = cinder admin_password = cinder4smtest
9、创建服务
sm@controller:~$ keystone service-create --name=cinder --type=volume --description="OpenStack Block Storage" +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack Block Storage | | enabled | True | | id | 34d2e3bd7ebe40e397afd1dcb8e491f1 | | name | cinder | | type | volume | +-------------+----------------------------------+ sm@controller:~$ keystone service-create --name=cinderv2 --type=volumev2 --description="OpenStack Block Storage v2" +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack Block Storage v2 | | enabled | True | | id | df230bd9e2fb4a6485b4d4d41f0cc896 | | name | cinderv2 | | type | volumev2 | +-------------+----------------------------------+
10、创建接入端点
sm@controller:~$ keystone endpoint-create --service-id=$(keystone service-list | awk '/ volume / {print $2}') -- publicurl=http://192.168.3.180:8776/v1/%\(tenant_id\)s --internalurl=http://192.168.3.180:8776/v1/%\(tenant_id\)s --adminurl=http://192.168.3.180:8776/v1/%\(tenant_id\)s +-------------+--------------------------------------------+ | Property | Value | +-------------+--------------------------------------------+ | adminurl | http://192.168.3.180:8776/v1/%(tenant_id)s | | id | 863b1a4fc3984aa88c8a1dde7354c67c | | internalurl | http://192.168.3.180:8776/v1/%(tenant_id)s | | publicurl | http://192.168.3.180:8776/v1/%(tenant_id)s | | region | regionOne | | service_id | 34d2e3bd7ebe40e397afd1dcb8e491f1 | +-------------+--------------------------------------------+ sm@controller:~$ keystone endpoint-create --service-id=$(keystone service-list | awk '/ volumev2 / {print $2}') -- publicurl=http://192.168.3.180:8776/v2/%\(tenant_id\)s --internalurl=http://192.168.3.180:8776/v2/%\(tenant_id\)s --adminurl=http://192.168.3.180:8776/v2/%\(tenant_id\)s +-------------+--------------------------------------------+ | Property | Value | +-------------+--------------------------------------------+ | adminurl | http://192.168.3.180:8776/v2/%(tenant_id)s | | id | 19627c5cdcad4a33a58f9c4d9fec3820 | | internalurl | http://192.168.3.180:8776/v2/%(tenant_id)s | | publicurl | http://192.168.3.180:8776/v2/%(tenant_id)s | | region | regionOne | | service_id | df230bd9e2fb4a6485b4d4d41f0cc896 | +-------------+--------------------------------------------+
11、启动相关服务
sm@controller:~$ sudo service cinder-scheduler restart cinder-scheduler stop/waiting cinder-scheduler start/running, process 19209 sm@controller:~$ sudo service cinder-api restart cinder-api stop/waiting cinder-api start/running, process 19241
二、在提供块存储的节点安装
例如,我的计算节点192.168.3.181提供这个服务,我就在这个computer节点安装该服务。
首先,我需要给我的VM Workstation添加一块硬盘,默认20GB。
sm@computer:~$ sudo fdisk -l Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders, total 251658240 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: 0x000c5fc7 Device Boot Start End Blocks Id System /dev/sda1 * 2048 194559 96256 83 Linux /dev/sda2 194560 156444671 78125056 83 Linux /dev/sda3 156444672 164257791 3906560 82 Linux swap / Solaris Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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/sdb doesn't contain a valid partition table
我们可以看到添加后的硬盘为/dev/sdb,系统提示还没有分区。用户可以直接在sdb硬盘上进行lvm,也可以先对sdb进行分区,然后在对某个区进行lvm,我使用了后者。
关于怎么对sdb进行分区,可以参考:http://blog.csdn.net/linghe301/article/details/17279841
分区之后的相关信息如下,我分了一个8GB的sdb1区
sm@computer:~$ sudo fdisk -l Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders, total 251658240 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: 0x000c5fc7 Device Boot Start End Blocks Id System /dev/sda1 * 2048 194559 96256 83 Linux /dev/sda2 194560 156444671 78125056 83 Linux /dev/sda3 156444672 164257791 3906560 82 Linux swap / Solaris Disk /dev/sdb: 21.5 GB, 21474836480 bytes 213 heads, 34 sectors/track, 5791 cylinders, total 41943040 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: 0x3909c82f Device Boot Start End Blocks Id System /dev/sdb1 16777216 41943039 12582912 83 Linux
1、安装组件
sudo apt-get install lvm2
2、创建LVM卷
sm@computer:~$ sudo pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created sm@computer:~$ sudo vgcreate cinder-volumes /dev/sdb1 Volume group "cinder-volumes" successfully created
3、编辑sudo vi /etc/lvm/lvm.conf,修改filter对应项
devices { ..... filter = [ "a/sda1/","a/sdb1/","r/.*/" ] ..... }
4、安装cinder-volume组件
sm@computer:~$ sudo apt-get install cinder-volume
5、编辑配置文件/etc/cinder/cinder.conf
rpc_backend = cinder.openstack.common.rpc.impl_kombu rabbit_host = 192.168.3.180 rabbit_port = 5672 rabbit_userid = guest rabbit_password = mq4smtest glance_host = 192.168.3.180 [DEFAULT] auth_strategy = keystone [keystone_authtoken] auth_uri = http://192.168.3.180:5000 auth_host = 192.168.3.180 auth_port = 35357 auth_protocol = http admin_tenant_name = service admin_user = cinder admin_password = cinder4smtest [database] connection = mysql://cinderdbadmin:[email protected]/cinder
5、重启服务即可
sm@computer:~$ sudo service cinder-volume restart cinder-volume stop/waiting cinder-volume start/running, process 12892 sm@computer:~$ sudo service tgt restart tgt stop/waiting tgt start/running, process 12931安装完毕!
控制节点
三、我们创建一个Volume
sm@computer:~$ cinder create --display-name myVolume 1 +---------------------+--------------------------------------+ | Property | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | created_at | 2015-04-26T06:40:09.225052 | | display_description | None | | display_name | myVolume | | encrypted | False | | id | 65e3f4c6-108e-497f-b7c9-9bbfcb6a7d23 | | metadata | {} | | size | 1 | | snapshot_id | None | | source_volid | None | | status | creating | | volume_type | None | +---------------------+--------------------------------------+
查看一下volume列表
sm@computer:~$ cinder list +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+ | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to | +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+ | 65e3f4c6-108e-497f-b7c9-9bbfcb6a7d23 | available | myVolume | 1 | None | false | | +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
也可以在Horzion里面查看相关信息
将创建好的云硬盘,挂接到某个虚拟机实例上