一个计算机技术爱好者与学习者

0%

好好学OpenStack:Ubuntu16手动安装OpenStack——Cinder篇

1. 目标

《Ubuntu16手动安装OpenStack——修改镜像》一文中,我们通过修改镜像,实现了ssh密码访问实例。看上去,这个openstack系统已经可以投入使用了,实际上,也确实可以投入使用了。

但是,我们总是追求更好更多的服务。所以接下来,我们继续安装openstack的服务组件。本文中要安装配置的是cinder,主要参考OpenStack Queens : Configure CinderCinder Installation Guide

2. cinder简介

块存储服务(cinder)为用户实例提供块存储设备。配置和使用存储的方法由块存储驱动程序确定,或者在多后端配置的情况下由驱动程序确定。有多种驱动程序可用:NAS / SAN,NFS,iSCSI,Ceph等。Block Storage API和调度程序服务通常在控制器节点上运行。根据所使用的驱动程序,卷服务可以在控制器节点,计算节点或独立存储节点上运行。

3. 控制节点

3.1. root用户

为了避免权限问题,建议切换到root用户进行操作(否则要加很多sudo)。
sudo -i

3.2. 数据库

1、登录数据库
mysql -uroot -p,密码为openstack。

2、创建cinder数据库
create database cinder;

3、授权

1
2
3
grant all privileges on cinder.* to cinder@'localhost' identified by 'openstack';

grant all privileges on cinder.* to cinder@'%' identified by 'openstack';

4、退出数据库
flush privileges;

exit;

3.3. 证书和端点

1、使admin环境生效
. admin-openrc

2、创建cinder用户,密码为openstack
openstack user create --domain default --project service --password openstack cinder

3、给cinder用户添加admin角色
openstack role add --project service --user cinder admin

4、创建cinder服务

1
2
3
openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2

openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3

5、创建cinder服务端点

1
2
3
4
5
6
7
8
9
10
11
openstack endpoint create --region RegionOne volumev2 public http://controller:8776/v2/%\(project_id\)s

openstack endpoint create --region RegionOne volumev2 internal http://controller:8776/v2/%\(project_id\)s

openstack endpoint create --region RegionOne volumev2 admin http://controller:8776/v2/%\(project_id\)s

openstack endpoint create --region RegionOne volumev3 public http://controller:8776/v3/%\(project_id\)s

openstack endpoint create --region RegionOne volumev3 internal http://controller:8776/v3/%\(project_id\)s

openstack endpoint create --region RegionOne volumev3 admin http://controller:8776/v3/%\(project_id\)s

3.4. 安装配置

1、下载安装组件
apt-get -y install cinder-api cinder-scheduler python-cinderclient

2、备份cinder.conf
mv /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak

3、vi /etc/cinder/cinder.conf,新建cinder.conf内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# create new
[DEFAULT]
# define own IP address
my_ip = 172.16.0.105
rootwrap_config = /etc/cinder/rootwrap.conf
api_paste_confg = /etc/cinder/api-paste.ini
state_path = /var/lib/cinder
auth_strategy = keystone
# RabbitMQ connection info
transport_url = rabbit://openstack:openstack@controller

# MariaDB connection info
[database]
connection = mysql+pymysql://cinder:openstack@controller/cinder

# Keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = openstack

[oslo_concurrency]
lock_path = $state_path/tmp

4、更改权限
chmod 644 /etc/cinder/cinder.conf

chown root:cinder /etc/cinder/cinder.conf

5、生成数据库数据
su -s /bin/bash cinder -c "cinder-manage db sync"

6、重启cinder-scheduler
systemctl restart cinder-scheduler

7、查看volume
openstack volume service list

4. 存储节点

本文中,我们的存储节点和计算节点在同一个节点,该节点的IP为172.16.0.106。已经安装的服务和virtualbox计算节点(192.168.56.111)相同,包括nova-compute和neutron。

4.1. root用户

为了避免权限问题,建议切换到root用户进行操作(否则要加很多sudo)。
sudo -i

4.2. 安装配置

1、安装cinder-volume
apt-get -y install cinder-volume python-mysqldb

2、备份cinder.conf
mv /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak

3、vi /etc/cinder/cinder.conf,新建cinder.conf内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# create new
[DEFAULT]
# define own IP address
my_ip = 172.16.0.106
rootwrap_config = /etc/cinder/rootwrap.conf
api_paste_confg = /etc/cinder/api-paste.ini
state_path = /var/lib/cinder
auth_strategy = keystone
# RabbitMQ connection info
transport_url = rabbit://openstack:openstack@controller
# Glance connection info
glance_api_servers = http://controller:9292
# OK with empty value now
enabled_backends =

# MariaDB connection info
[database]
connection = mysql+pymysql://cinder:openstack@controller/cinder

# Keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = openstack

[oslo_concurrency]
lock_path = $state_path/tmp

4、更改权限
chmod 644 /etc/cinder/cinder.conf

chown root:cinder /etc/cinder/cinder.conf

5、重启cinder-volume
systemctl restart cinder-volume

5. 使用lvm卷

5.1. 存储节点

1、在存储节点添加硬盘,保证至少有两块硬盘。

2、创建物理卷
ll /dev/sd*

pvcreate /dev/sdb

3、创建volume group
vgcreate -s 32M vg_volume01 /dev/sdb

4、安装lvm相关组件
apt-get -y install tgt thin-provisioning-tools

5、vi /etc/cinder/cinder.conf,如下修改cinder.conf:

1
2
3
4
5
6
7
8
9
10
11
12
# add a value for enabled_backends
enabled_backends = lvm
# add follows to the end
[lvm]
iscsi_helper = tgtadm
# volume group name just created
volume_group = vg_volume01
# IP address of Storage Node
iscsi_ip_address = 172.16.0.106
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volumes_dir = $state_path/volumes
iscsi_protocol = iscsi

6、重启服务
systemctl restart cinder-volume tgt

5.2. 计算节点

1、vi /etc/nova/nova.conf,编辑nova.conf文件:

1
2
3
# add to the end
[cinder]
os_region_name = RegionOne

2、重启compute服务
systemctl restart nova-compute

5.3. 控制节点

以上,已经准备好了cinder服务,我们在控制节点使用cinder服务(也可以在其他机器使用)。

1、假设我们已经按照《Ubuntu16手动安装OpenStack——创建实例》一文,创建了一个cirros0实例,ip为10.0.0.206。

2、登录cirros0
ssh cirros@10.0.0.206,密码默认为gocubsgo。

3、在cirros0中查看硬盘
df -h

ls -l /dev/vd*

sudo fdisk -l


可以看到,当前虚拟机只有一块vda硬盘。

4、控制节点中修改voidking用户环境,并使环境生效
echo "export OS_VOLUME_API_VERSION=2" >> ~/voidkingrc

. voidkingrc

5、创建卷disk01,大小为1G
openstack volume create --size 1 disk01

6、查看卷
openstack volume list

7、把卷disk01添加给cirros0实例
openstack server list

openstack server add volume cirros0 disk01

8、在cirros0中查看硬盘
ls -l /dev/vd*

发现cirros0中多出了一块硬盘vdb。

9、在控制节点查看卷
openstack volume list

显示disk01已经attach到了cirros0的/dev/vdb,和我们在cirros0中看到的结果一致。

10、移除卷
openstack server remove volume cirros0 disk01

6. 后记

关于NFS(网络文件系统)的使用,参考OpenStack Queens : Use Cinder Storage (NFS)

关于LVM和NFS格式卷的混合使用,参考OpenStack Queens : Use Cinder Storage (Multi-BackEnds)

关于使用cinder备份卷,参考OpenStack Queens : Configure Cinder Backup