openstack之kilo安装 镜像服务

这周在折腾openstack,下面是过程小记。

参考:Chapter 4. Add the Image service

镜像服务安装在控制节点,默认存在目录 /var/lib/glance/images/。

Install and configure

在安装和配置镜像服务前,先创建数据库,服务认证和API endpoint。
创建 glance database:

#
mysql -u root -p

MariaDB [(none)]>

CREATE DATABASE glance;
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'GLANCE_DBPASS';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY 'GLANCE_DBPASS';

exit

Source the admin credentials to gain access to admin-only CLI commands:

#
source admin-openrc.sh

创建glance user:

#
openstack user create glance --password glance

添加 admin role to the glance user and service project:

#
openstack role add --project service --user glance admin

创建glance service entity:

#
openstack service create --name glance \
--description "OpenStack Image service" image

创建Image service API endpoint:

#
openstack endpoint create \
--publicurl http://controller:9292 \
--internalurl http://controller:9292 \
--adminurl http://controller:9292 \
--region RegionOne \
image

安装 packages:

#
yum install -y openstack-glance python-glance python-glanceclient

编辑 /etc/glance/glance-api.conf 文件:

#
cp /etc/glance/glance-api.conf /etc/glance/glance-api.confbak
echo "[DEFAULT]
notification_driver = noop
verbose = True
[database]
connection = mysql://glance:GLANCE_DBPASS@controller/glance
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = glance
password = glance
[paste_deploy]
flavor = keystone
[glance_store]
default_store = file
filesystem_store_datadir = /var/lib/glance/images/" >/etc/glance/glance-api.conf

编辑 /etc/glance/glance-registry.conf文件:

#
cp /etc/glance/glance-registry.conf /etc/glance/glance-registry.confbak
echo "[DEFAULT]
verbose = True
notification_driver = noop
[database]
connection = mysql://glance:GLANCE_DBPASS@controller/glance
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = glance
password = glance
[paste_deploy]
flavor = keystone"> /etc/glance/glance-registry.conf

同步 Image service database:

#
su -s /bin/sh -c "glance-manage db_sync" glance

启动镜像服务并开机自启动:

#
systemctl enable openstack-glance-api.service openstack-glance-registry.service
systemctl start openstack-glance-api.service openstack-glance-registry.service

Verify operation

Verify operation of the Image service using CirrOS, a small Linux image that helps you test your OpenStack deployment.

In each client environment script, configure the Image service client to use API version 2.0:

#
echo "export OS_IMAGE_API_VERSION=2" | tee -a admin-openrc.sh demo-openrc.sh

执行admin-openrc.sh获取admin权限:

#
source admin-openrc.sh

创建临时文件夹:

#
mkdir /tmp/images

下载镜像到临时目录:

#
wget -P /tmp/images http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
#或者
curl -o /tmp/images/cirros-0.3.4-x86_64-disk.img http://192.178.102.249/os/cirros-0.3.4-x86_64-disk.img

使用QCOW2磁盘格式上传镜像:

#
glance image-create --name "cirros-0.3.4-x86_64" --file /tmp/images/cirros-0.3.4-x86_64-disk.img \
--disk-format qcow2 --container-format bare --visibility public --progress

确认上传镜像是否正常:

#
glance image-list

删除临时目录和源镜像:

#
rm -r /tmp/images