12 安装块存储设备
12.1 安装配置控制节点
12.1.1 安装准备
- 配置数据库 数据库安装在控制节点上。
$ mysql -u root -p
创建 cinder 数据库
CREATE DATABASE cinder;
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' \
IDENTIFIED BY 'openstack';
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' \
IDENTIFIED BY 'openstack';
- 用切换到管理员身份
$ source admin-openrc.sh
- 创建服务凭证
创建 cinder 用户
$ keystone user-create --name cinder --pass openstack
+----------+----------------------------------+
| Property | Value |
+----------+----------------------------------+
| email | |
| enabled | True |
| id | fd7b1e90d1144b669d20040b9c334d88 |
| name | cinder |
| username | cinder |
+----------+----------------------------------+
为 cinder 用户添加admin角色:
$ keystone user-role-add --user cinder --tenant service --role admin
创建 cinder 服务实体:
注意 块存储服务需要两个不同的实体以支持v1和v2版本的API.
$ keystone service-create --name cinder --type volume \
--description "OpenStack Block Storage"
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| description | OpenStack Block Storage |
| enabled | True |
| id | c6a863efddac421cbb6e1585ae0c026d |
| name | cinder |
| type | volume |
+-------------+----------------------------------+
$ keystone service-create --name cinderv2 --type volumev2 \
--description "OpenStack Block Storage"
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| description | OpenStack Block Storage |
| enabled | True |
| id | 61c641af06544f8eb74a99f4c30b65ee |
| name | cinderv2 |
| type | volumev2 |
+-------------+----------------------------------+
创建块存储服务 API 端点:
当然也是两个
$ keystone endpoint-create \
--service-id $(keystone service-list | awk '/ volume / {print $2}') \
--publicurl http://controller:8776/v1/%\(tenant_id\)s \
--internalurl http://controller:8776/v1/%\(tenant_id\)s \
--adminurl http://controller:8776/v1/%\(tenant_id\)s \
--region regionOne
+-------------+-----------------------------------------+
| Property | Value |
+-------------+-----------------------------------------+
| adminurl | http://controller:8776/v1/%(tenant_id)s |
| id | 1dadfd1345034f5bbec0a37fbb362e9c |
| internalurl | http://controller:8776/v1/%(tenant_id)s |
| publicurl | http://controller:8776/v1/%(tenant_id)s |
| region | regionOne |
| service_id | c6a863efddac421cbb6e1585ae0c026d |
+-------------+-----------------------------------------+
$ keystone endpoint-create \
--service-id $(keystone service-list | awk '/ volumev2 / {print $2}') \
--publicurl http://controller:8776/v2/%\(tenant_id\)s \
--internalurl http://controller:8776/v2/%\(tenant_id\)s \
--adminurl http://controller:8776/v2/%\(tenant_id\)s \
--region regionOne
+-------------+-----------------------------------------+
| Property | Value |
+-------------+-----------------------------------------+
| adminurl | http://controller:8776/v2/%(tenant_id)s |
| id | 8e40819ec3174b52a0d553d5fdec5a98 |
| internalurl | http://controller:8776/v2/%(tenant_id)s |
| publicurl | http://controller:8776/v2/%(tenant_id)s |
| region | regionOne |
| service_id | 61c641af06544f8eb74a99f4c30b65ee |
+-------------+-----------------------------------------+
12.1.2 安装配置存储控制组件
1 安装包
# apt-get install cinder-api cinder-scheduler Python-cinderclient
2 编辑 /etc/cinder/cinder.conf 完成下列操作:
[database]
...
connection = mysql://cinder:openstack@controller/cinder
[DEFAULT]
...
rpc_backend = rabbit
rabbit_host = controller
rabbit_password = openstack
my_ip = 10.0.0.11
verbose = True
...
auth_strategy = keystone
[keystone_authtoken]
...
#Comment out any auth_host, auth_port, and auth_protocol options because the identity_uri option replaces them.
auth_uri = http://controller:5000/v2.0
identity_uri = http://controller:35357
admin_tenant_name = service
admin_user = cinder
admin_password = openstack
3 组装数据库
# su -s /bin/sh -c "cinder-manage db sync" cinder
12.1.3 完成安装
重启服务
# service cinder-scheduler restart
# service cinder-api restart
删除没用的sqlite文件.
# rm -f /var/lib/cinder/cinder.sqlite
12.2 安装配置一个存储节点
12.2.1 To configure prerequisites
需要一台新的虚拟机,当然你要配置安装Ubuntu Cloud的keyring和仓库,配置时间同步,请参考 基础环境 那一节
设置hostname为block1
配置管理IP
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.234.206
netmask 255.255.255.0
gateway 192.168.234.1
# management interface
auto eth0:1
iface eth0:1 inet static
address 10.0.0.41
netmask 255.255.255.0
配置 /etc/hosts 加入下面内容
# block1
10.0.0.41 block1
其它的三个节点的hosts文件里也要加入这一行.
安装lvm包
# aptitude install lvm2 -y
我为这个存储节点添加了一块新的虚拟硬盘,可以用fdisk查看一下
# fdisk -l
Disk /dev/xvda: 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: 0x000db5b8
Device Boot Start End Blocks Id System
/dev/xvda1 2048 499711 248832 83 Linux
/dev/xvda2 501758 20969471 10233857 5 Extended
/dev/xvda5 501760 20969471 10233856 8e Linux LVM
Disk /dev/xvdb: 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/xvdb doesn't contain a valid partition table
Disk /dev/mapper/ubuntu1404server--vg-root: 9944 MB, 9944694784 bytes
255 heads, 63 sectors/track, 1209 cylinders, total 19423232 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/mapper/ubuntu1404server--vg-root doesn't contain a valid partition table
Disk /dev/mapper/ubuntu1404server--vg-swap_1: 532 MB, 532676608 bytes
255 heads, 63 sectors/track, 64 cylinders, total 1040384 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/mapper/ubuntu1404server--vg-swap_1 doesn't contain a valid partition table
可以看到新加的disk没有分区,我们来把它分成lvm的分区,具体请参考我的这篇blog. 分区完成后我们再看看分区表
# fdisk -l
Disk /dev/xvda: 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: 0x000db5b8
Device Boot Start End Blocks Id System
/dev/xvda1 2048 499711 248832 83 Linux
/dev/xvda2 501758 20969471 10233857 5 Extended
/dev/xvda5 501760 20969471 10233856 8e Linux LVM
Disk /dev/xvdb: 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: 0x38c87633
Device Boot Start End Blocks Id System
/dev/xvdb1 2048 41943039 20970496 8e Linux LVM
Disk /dev/mapper/ubuntu1404server--vg-root: 9944 MB, 9944694784 bytes
255 heads, 63 sectors/track, 1209 cylinders, total 19423232 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/mapper/ubuntu1404server--vg-root doesn't contain a valid partition table
Disk /dev/mapper/ubuntu1404server--vg-swap_1: 532 MB, 532676608 bytes
255 heads, 63 sectors/track, 64 cylinders, total 1040384 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/mapper/ubuntu1404server--vg-swap_1 doesn't contain a valid partition table
/dev/xvdb1 已经是lvm的了,用它创建一个物理卷.
# pvcreate /dev/xvdb1
Physical volume "/dev/xvdb1" successfully created
这样我们就创建了一个物理卷,名叫/dev/xvdb1,跟它的设备名是一样的.
创建一个卷组(Volume Group),这个物理加到这个卷组中.
# vgcreate cinder-volumes /dev/xvdb1
Volume group "cinder-volumes" successfully created
cinder-volumes是cinder默认使用的卷组,如果你的卷组不叫这个也没关系,可以在cinder.conf中修改. 创建完卷组就OK了,创建逻辑卷的工作就交给OpenStack了.
有一项非常重要的工作要做. 默认的lvm卷扫描工具会扫描 /dev目录来查看包含逻辑卷的设备,如果tenant创建了一个lvm的卷的话,那存储节点上的lvm会发现并缓存他们,会导致存储节点和tenant的主机都有问题.所以我们要限制lvm只扫描包含"cinder-volumes"的设备
编辑 /etc/lvm/lvm.conf
devices {
...
filter = [ "a/xvda/","a/xvdb/", "r/.*/"]
我为什么会把"a/xvda/“这个加到过滤器里,是因为我的节点的操作系统ubuntu是装在lvm上的,所以我必须允许lvm扫描这个设备. 你可以使用vgs -vvvv来测试你的过滤器.
如果你的计算节点也使用了lvm,你也要同时设置扫描过滤器.
12.2.2 安装包
1
# apt-get install cinder-volume python-mysqldb
编辑 /etc/cinder/cinder.conf 完成下列操作:
[DEFAULT]
...
rpc_backend = rabbit
rabbit_host = controller
rabbit_password = openstack
my_ip = 10.0.0.41
glance_host = controller
verbose = True
auth_strategy = keystone
[keystone_authtoken]
...
auth_uri = http://controller:5000/v2.0
identity_uri = http://controller:35357
admin_tenant_name = service
admin_user = cinder
admin_password = openstack
[database]
...
connection = mysql://cinder:openstack@controller/cinder
12.2.3 完成安装
# service tgt restart
# service cinder-volume restart
# rm -f /var/lib/cinder/cinder.sqlite
12.3 验证安装
请在控制节点上运行下面的命令
$ source admin-openrc.sh
# cinder service-list
+------------------+------------+------+---------+-------+----------------------------+-----------------+
| Binary | Host | Zone | Status | State | Updated_at | Disabled Reason |
+------------------+------------+------+---------+-------+----------------------------+-----------------+
| cinder-scheduler | controller | nova | enabled | up | 2015-03-20T03:46:57.000000 | None |
| cinder-volume | block1 | nova | enabled | up | 2015-03-20T03:46:53.000000 | None |
+------------------+------------+------+---------+-------+----------------------------+-----------------+
切换成demo租户
$ source demo-openrc.sh
创建一个卷
$ cinder create --display-name demo-volume1 1
查看这个新建的卷
$ cinder list
