How to Install and Configure OpenStack glance

In this tutorial, How to Install and Configure OpenStack glance. In previous, My post has How to install OpenStack all in one Centos 7. If you have not yet installed OpenStack Glance then step install as below

Step by step Install and Configure OpenStack glance

Create a User and Database on MariaDB for Glance.

[vagrant@DevopsRoles ~]# mysql -u root -p 
MariaDB [(none)]> create database glance;
MariaDB [(none)]> grant all privileges on glance.* to glance@'localhost' identified by 'password'; 
MariaDB [(none)]> grant all privileges on glance.* to glance@'%' identified by 'password'; 
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit

Add users and others for Glance in Keystone.

# add glance user (set in service project)
[vagrant@DevopsRoles ~(keystone)]# openstack user create --domain default --project service --password servicepassword glance
# add glance user in admin role
[vagrant@DevopsRoles ~(keystone)]# openstack role add --project service --user glance admin
# add service entry for glance
[vagrant@DevopsRoles ~(keystone)]# openstack service create --name glance --description "OpenStack Image service" image 
# define keystone host
[vagrant@DevopsRoles ~(keystone)]# export controller=10.0.2.15
# add endpoint for glance (public)
[vagrant@DevopsRoles ~(keystone)]# openstack endpoint create --region RegionOne image public http://$controller:9292 
# add endpoint for glance (internal)
[vagrant@DevopsRoles ~(keystone)]# openstack endpoint create --region RegionOne image internal http://$controller:9292 
# add endpoint for glance (admin)
[vagrant@DevopsRoles ~(keystone)]# openstack endpoint create --region RegionOne image admin http://$controller:9292 

Install Glance.

# install from Stein, EPEL
[vagrant@DevopsRoles ~(keystone)]# yum --enablerepo=centos-openstack-stein,epel -y install openstack-glance

Configure OpenStack Glance.

[vagrant@DevopsRoles ~(keystone)]# mv /etc/glance/glance-api.conf /etc/glance/glance-api.conf.org 
[vagrant@DevopsRoles ~(keystone)]# vi /etc/glance/glance-api.conf
# create new bind host
 [DEFAULT]
bind_host = 0.0.0.0

[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

[database]
# MariaDB connection info for Glance
connection = mysql+pymysql://glance:password@10.0.2.15/glance

# keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://10.0.2.15:5000
auth_url = http://10.0.2.15:5000
memcached_servers = 10.0.2.15:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = servicepassword

[paste_deploy]
flavor = keystone

[vagrant@DevopsRoles ~(keystone)]# chmod 640 /etc/glance/glance-api.conf 
[vagrant@DevopsRoles ~(keystone)]# chown root:glance /etc/glance/glance-api.conf
[vagrant@DevopsRoles ~(keystone)]# su -s /bin/bash glance -c "glance-manage db_sync" 
[vagrant@DevopsRoles ~(keystone)]# systemctl start openstack-glance-api 
[vagrant@DevopsRoles ~(keystone)]# systemctl enable openstack-glance-api 

If SELinux is enabled on Centos 7


[vagrant@DevopsRoles ~]# setsebool -P glance_api_can_network on 

Allow ports for services with Firewalld is running

[vagrant@DevopsRoles ~(keystone)]# firewall-cmd --add-port=9292/tcp --permanent
[vagrant@DevopsRoles ~(keystone)]# firewall-cmd --reload 

OpenStack Add Virtual Machine Image

For example, I will create and add CentOS 7 Virtual machine image. Your system has to install KVM HyperVisor.

1. Create CentosOS 7 image on Glance Host

[vagrant@DevopsRoles ~(keystone)]# mkdir -p /var/kvm/images
[vagrant@DevopsRoles ~(keystone)]# qemu-img create -f qcow2 /var/kvm/images/centos7.img 15G

# install
[vagrant@DevopsRoles ~(keystone)]# virt-install \
--name centos7 \
--ram 2048 \
--disk path=/var/kvm/images/centos7.img,format=qcow2 \
--vcpus 2 \
--os-type linux \
--os-variant rhel7 \
--graphics none \
--console pty,target_type=serial \
--location=/home/huupv/iso/CentOS-7-x86_64-Minimal-1810.iso \
--extra-args 'console=ttyS0,115200n8 serial'

Note: After Installation, You need to change settings in Virtual machine as follows.

  • Delete the line [HWADDR] and [UUID] in [/etc/sysconfig/network-scripts/ifcfg-eth0]
  • Set [dhcp] for [BOOTPROTO] in [/etc/sysconfig/network-scripts/ifcfg-eth0] file
  • Install [cloud-init] package and enable [cloud-init] service, and also add a user whose name is [centos]

2. Add the virtual image to Glance.

[vagrant@DevopsRoles ~(keystone)]# openstack image create "CentOS7" --file /var/kvm/images/centos7.img --disk-format qcow2 --container-format bare --public 
[vagrant@DevopsRoles ~(keystone)]# openstack image list 

Another method, You can get an image from the internet.

[vagrant@DevopsRoles ~(keystone)]# wget http://cloud-images.ubuntu.com/releases/18.04/release/ubuntu-18.04-server-cloudimg-amd64.img -P /var/kvm/images
[vagrant@DevopsRoles ~(keystone)]# openstack image create "Ubuntu1804" --file /var/kvm/images/ubuntu-18.04-server-cloudimg-amd64.img --disk-format qcow2 --container-format bare --public

You have to install and configure OpenStack Glance. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.