centos7+openstack (8) cinder 创建云硬盘

Submitted by Lizhe on Fri, 07/21/2017 - 10:18


两台电脑上(控制节点和计算节点)都需要安装cinder, 不过我们前边已经装过了

yum install -y openstack-cinder python-cinderclient

创建数据库, 之前也做过了

下面内容都在控制节点上操作, 要切换到计算节点时我会标注出来

cat /etc/cinder/cinder.conf|grep -v "^#"|grep -v "^$"

[DEFAULT] 
glance_host = 192.168.1.151 
auth_strategy = keystone 
rpc_backend = rabbit 
[BRCD_FABRIC_EXAMPLE] 
[CISCO_FABRIC_EXAMPLE] 
[cors] 
[cors.subdomain] 
[database] 
connection = mysql://cinder:cinder@192.168.1.151/cinder 
[fc-zone-manager] 
[keymgr] 
[keystone_authtoken] 
auth_uri = http://192.168.1.151:5000 
auth_url = http://192.168.1.151:35357 
auth_plugin = password 
project_domain_id = default 
user_domain_id = default 
project_name = service 
username = cinder 
password = cinder 
[matchmaker_redis] 
[matchmaker_ring] 
[oslo_concurrency] 
lock_path = /var/lib/cinder/tmp 
[oslo_messaging_amqp] 
[oslo_messaging_qpid] 
[oslo_messaging_rabbit] 
rabbit_host = 192.168.1.151 
rabbit_port = 5672 
rabbit_userid = openstack 
rabbit_password = openstack 
[oslo_middleware] 
[oslo_policy] 
[oslo_reports] 
[profiler]


vim /etc/nova/nova.conf
[cinder]
os_region_name=RegionOne

同步数据库
su -s /bin/sh -c "cinder-manage db sync" cinder

创建 keystone 用户
[root@centos_admin ~]# source admin-openrc.sh
[root@centos_admin ~]# openstack user create --domain default --password-prompt cinder
password: cinder



 

194

 

openstack role add --project service --user cinder admin

systemctl restart openstack-nova-api.service

systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service

 

创建cinder的service, v1和v2都要创建


[root@centos_admin ~]# source admin-openrc.sh 


[root@centos_admin ~]# openstack service create --name cinder --description "OpenStack Block Storage" volume
 

[root@centos_admin ~]# openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
 

195

 

注册endpoint
openstack endpoint create --region RegionOne volume public http://192.168.1.151:8776/v1/%\(tenant_id\)s
openstack endpoint create --region RegionOne volume internal http://192.168.1.151:8776/v1/%\(tenant_id\)s
openstack endpoint create --region RegionOne volume admin http://192.168.1.151:8776/v1/%\(tenant_id\)s


openstack endpoint create --region RegionOne volumev2 public http://192.168.1.151:8776/v2/%\(tenant_id\)s
openstack endpoint create --region RegionOne volumev2 internal http://192.168.1.151:8776/v2/%\(tenant_id\)s
openstack endpoint create --region RegionOne volumev2 admin http://192.168.1.151:8776/v2/%\(tenant_id\)s

196

197


计算节点添加硬盘并创建VG

在计算节点服务器添加一个硬盘,这里我用的是vmware

198

199

500

以下内容在计算节点上操作

fdisk -l 看看硬盘 

可以看到一块没有被mount的硬盘/dev/sdb
这里如果看不到sdb硬盘, 就重启一下

Disk /dev/sdb: 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


vim /etc/lvm/lvm.conf

如果是非lvm磁盘使用下面的内容 ( 我现在的情况 )

a 表示同意, r 是不同意
devices {
    filter = [ "a/sdb/", "r/.*/"]

如果是lvm

devices {
        filter = [ "a|^/dev/mapper/centos-home$|", "r|.*/|" ]
}


[root@centos_compute_1 ~]# pvcreate /dev/sdb

[root@centos_compute_1 ~]# vgcreate cinder-volumes /dev/sdb
 

502

 

 
 
在控制节点(151)上
[root@centos_admin ~]# scp /etc/cinder/cinder.conf 192.168.1.152:/etc/cinder/cinder.conf


在计算节点(152)上
vi /etc/cinder/cinder.conf

[DEFAULT]
enabled_backends = lvm

[lvm] (在文件底部自己建立一个,默认没有)
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver 
volume_group = cinder-volumes
iscsi_protocol = iscsi 
iscsi_helper = lioadm

503

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

控制节点(151)可以看到list
[root@centos_admin ~]# cinder service-list
+------------------+----------------------+------+---------+-------+----------------------------+-----------------+
|      Binary      |         Host         | Zone |  Status | State |         Updated_at         | Disabled Reason |
+------------------+----------------------+------+---------+-------+----------------------------+-----------------+
| cinder-scheduler |     centos_admin     | nova | enabled |   up  | 2017-07-20T13:37:55.000000 |        -        |
|  cinder-volume   | centos_compute_1@lvm | nova | enabled |   up  | 2017-07-20T13:37:47.000000 |        -        |
+------------------+----------------------+------+---------+-------+----------------------------+-----------------+
[root@centos_admin ~]# 

504
 

505

506

507

508

此时在虚拟机lz1上可以看到这个被链接进来的1G云硬盘

509