安裝OpenStack Glance 組件
本篇主要記錄一下 如何安裝 OpenStack 的 Glance 鏡像管理組件
和上一篇一樣 選擇的是 queens 版本
操作系統(tǒng):Centos7
1.官網(wǎng)地址
有一些前置條件 如 mariadb 、 NTP 同步 催享、MQ 等 需要提前安裝好 詳細在上一篇Keystone中
https://docs.openstack.org/glance/queens/install/install-rdo.html
2.配置 glance 前置條件
2.1 創(chuàng)建 glance 數(shù)據(jù)庫
mysql -u root -p
MariaDB [(none)]> CREATE DATABASE glance;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'root123'; #密碼可以自定義
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY 'root123';
2.2 創(chuàng)建一個 glance 用戶
openstack user create --domain default --password-prompt glance
輸入密碼:#自定義密碼 我的是root123
重復(fù)輸入密碼:
2.3 把glance用戶賦予 admin 角色
openstack role add --project service --user glance admin
#This command provides no output. 就是這一行輸入完后 沒有任何輸出
2.4 創(chuàng)建 glance service
openstack service create --name glance \
--description "OpenStack Glance Image" image
2.5 創(chuàng)建 glance 的 endpoint
上一篇有提到 endpoint 分為3種類型杭隙, public、internal因妙、admin 痰憎,所以glance 的endpoint 也是要去創(chuàng)建這3種類型
2.5.1 創(chuàng)建 public endpoint
openstack endpoint create --region RegionOne \
image public http://controller:9292
2.5.2 創(chuàng)建 internal endpoint
openstack endpoint create --region RegionOne \
image internal http://controller:9292
2.5.3 創(chuàng)建 admin endpoint
openstack endpoint create --region RegionOne \
image admin http://controller:9292
3.安裝 glance 組件
3.1 安裝glance packages
yum install openstack-glance #我安裝的時候很慢 最后科學(xué)上網(wǎng)才安裝成功
3.2 編輯/etc/glance/glance-api.conf
3.2.1 配置 數(shù)據(jù)庫連接
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance #注意替換grance密碼
3.2.2 配置 keystone_authtoken 和 paste_deploy
[keystone_authtoken]
# ...
auth_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 = glance
password = GLANCE_PASS
[paste_deploy]
# ...
flavor = keystone
3.2.3 配置 glance_store 鏡像存儲地址
[glance_store]
# ...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
3.3 編輯 /etc/glance/glance-registry.conf
和上面的兩步一樣
3.3.1 配置 數(shù)據(jù)庫連接
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance #注意替換grance密碼
3.3.2 配置 keystone_authtoken 和 paste_deploy
[keystone_authtoken]
# ...
auth_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 = glance
password = GLANCE_PASS
[paste_deploy]
# ...
flavor = keystone
3.4 執(zhí)行 db_sync 腳本
su -s /bin/sh -c "glance-manage db_sync" glance
執(zhí)行完成后 可以去數(shù)據(jù)庫里查看到 對應(yīng)的glance 的表
3.5 設(shè)置開機自啟 和 啟動
systemctl enable openstack-glance-api.service \
openstack-glance-registry.service
systemctl start openstack-glance-api.service \
openstack-glance-registry.service
4.測試 glance 上傳鏡像
至此 glance 已經(jīng)安裝完畢,那我們來測試一下 它的 上傳鏡像 基礎(chǔ)功能
4.1 下載官方cirros 鏡像
專門openstack 用于 測試用的小型鏡像 下載地址 https://download.cirros-cloud.net/0.5.2/
4.2 上傳鏡像
glance image-create --name "cirros-0.5.2-x86_64-disk.img" --file /root/cirros-0.5.2-x86_64-disk.img --container-format bare --disk-format qcow2 --progress
4.3 查看鏡像
openstack image list
4.4 通過 Api查詢鏡像
http://192.168.56.30:9292/v2/images?
注意需要帶上 X-Auth-Token 去是keystone 拿
5.擴展
5.1 Disk和Container格式
當(dāng)我們添加一個鏡像到glance時攀涵,你必須指定虛擬機的disk格式和container格式铣耘,關(guān)于disk格式請自行研究kvm等虛擬。
disk和container格式是每個部署的基本配置以故,常用的格式如下:
1.Disk Format
不同的虛擬化應(yīng)用的廠針有不同的虛擬機鏡像的disk格式:
-
raw
This is an unstructured disk image format
-
vhd
This is the VHD disk format, a common disk format used by virtual machine monitors from VMware, Xen, Microsoft, VirtualBox, and others
-
vhdx
This is the VHDX disk format, an enhanced version of the vhd format which supports larger disk sizes among other features.
-
vmdk
Another common disk format supported by many common virtual machine monitors
-
vdi
A disk format supported by VirtualBox virtual machine monitor and the QEMU emulator
-
iso
An archive format for the data contents of an optical disc (e.g. CDROM).
-
ploop
A disk format supported and used by Virtuozzo to run OS Containers
-
qcow2
A disk format supported by the QEMU emulator that can expand dynamically and supports Copy on Write
-
aki
This indicates what is stored in Glance is an Amazon kernel image
-
ari
This indicates what is stored in Glance is an Amazon ramdisk image
-
ami
This indicates what is stored in Glance is an Amazon machine image
5.2 Container Format
容器container格式是指虛擬機映像是否包含一個文件格式涡拘,該文件格式還包含有關(guān)實際虛擬機的元數(shù)據(jù)。
需要注意的是:容器格式字符串在當(dāng)前并不會被glance或其他OpenStack組件的使用据德,所以如果你不確定鳄乏,簡單的將容器格式指定bare是安全的跷车。
你可以設(shè)置如下容器格式:
-
bare
This indicates there is no container or metadata envelope for the image
-
ovf
This is the OVF container format
-
aki
This indicates what is stored in Glance is an Amazon kernel image
-
ari
This indicates what is stored in Glance is an Amazon ramdisk image
-
ami
This indicates what is stored in Glance is an Amazon machine image
-
ova
This indicates what is stored in Glance is an OVA tar archive file
-
docker
This indicates what is stored in Glance is a Docker tar archive of the container filesystem
總結(jié):
本篇主要記錄一下 安裝 OpenStack 的 Glance 鏡像管理組件的全過程,最后再進行測試glance 的上傳鏡像功能橱野,以及通過API的方式獲取查詢鏡像
歡迎大家訪問 個人博客 Johnny小屋