OpenStack-镜像服务

【基于此文章的环境】点我快速打开文章

1、安装和配置

控制节点(controller)

1.1 创库授权 glance

mysql

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';

用一个合适的密码替换 GLANCE_DBPASS

openstack 镜像命令 openstack的镜像服务_运维

openstack 镜像命令 openstack的镜像服务_开发工具_02

1.2 创建服务证书

1. 创建 glance 用户
openstack user create --domain default --password GLANCE_PASS glance

用一个合适的密码替换 GLANCE_PASS

openstack 镜像命令 openstack的镜像服务_openstack 镜像命令_03

openstack 镜像命令 openstack的镜像服务_openstack 镜像命令_04

2. 添加 admin 角色到 glance 用户和 service 项目上
openstack role add --project service --user glance admin

openstack 镜像命令 openstack的镜像服务_运维_05

openstack 镜像命令 openstack的镜像服务_openstack 镜像命令_06

3. 创建服务,注册 api 地址
openstack service create --name glance \
--description "OpenStack Image" image

openstack endpoint create --region RegionOne \
image public http://controller:9292

openstack endpoint create --region RegionOne \
image internal http://controller:9292

openstack endpoint create --region RegionOne \
image admin http://controller:9292

openstack 镜像命令 openstack的镜像服务_开发工具_07

openstack 镜像命令 openstack的镜像服务_数据库_08

1.3 安装配置 glance

1. 安装其软件包
yum install openstack-glance -y &>/dev/null

echo $?

openstack 镜像命令 openstack的镜像服务_开发工具_09

openstack 镜像命令 openstack的镜像服务_数据库_10

2. 修改配置文件
1. 备份初始配置文件,然后重定向写入配置文件
cp /etc/glance/glance-api.conf{,.bak}

egrep -v '^$|#' /etc/glance/glance-api.conf.bak >/etc/glance/glance-api.conf

openstack 镜像命令 openstack的镜像服务_开发工具_11

openstack 镜像命令 openstack的镜像服务_mysql_12

2. 编辑文件 /etc/glance/glance-api.conf 并完成如下动作:
vim /etc/glance/glance-api.conf
  • [database] 部分,配置数据库访问
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

GLANCE_DBPASS 替换为你为镜像服务选择的密码

  • 在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问
[keystone_authtoken]
# ...
auth_uri = http://controller:5000
auth_url = http://controller:35357
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

将 GLANCE_PASS 替换为你为认证服务中你为 glance 用户选择的密码。

  • 在 [glance_store] 部分,配置本地文件系统存储和镜像文件位置
[glance_store]
# ...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

openstack 镜像命令 openstack的镜像服务_运维_13

openstack 镜像命令 openstack的镜像服务_mysql_14

3. 备份初始配置文件,然后重定向写入配置文件
cp /etc/glance/glance-registry.conf{,.bak}

egrep -v '^$|#' /etc/glance/glance-registry.conf.bak >/etc/glance/glance-registry.conf

openstack 镜像命令 openstack的镜像服务_运维_15

openstack 镜像命令 openstack的镜像服务_数据库_16

4. 编辑文件 /etc/glance/glance-registry.conf 并完成如下动作:
vim /etc/glance/glance-registry.conf
  • 在 [database] 部分,配置数据库访问
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

GLANCE_DBPASS 替换为你为镜像服务选择的密码。

  • 在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问
[keystone_authtoken]
# ...
auth_uri = http://controller:5000
auth_url = http://controller:35357
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

将 GLANCE_PASS 替换为你为认证服务中你为 glance 用户选择的密码。

openstack 镜像命令 openstack的镜像服务_运维_17

openstack 镜像命令 openstack的镜像服务_数据库_18

3. 写入其数据库
su -s /bin/sh -c "glance-manage db_sync" glance

openstack 镜像命令 openstack的镜像服务_运维_19

openstack 镜像命令 openstack的镜像服务_数据库_20

验证操作

mysql glance -e 'show tables;'|wc -l

openstack 镜像命令 openstack的镜像服务_mysql_21

openstack 镜像命令 openstack的镜像服务_运维_22

4. 启动和自启动
systemctl enable openstack-glance-api.service \
  openstack-glance-registry.service
  
systemctl start openstack-glance-api.service \
  openstack-glance-registry.service

openstack 镜像命令 openstack的镜像服务_开发工具_23

openstack 镜像命令 openstack的镜像服务_运维_24

1.3 验证操作

1.3.1 验证端口
netstat -lntup|grep -E '9191|9292'

openstack 镜像命令 openstack的镜像服务_运维_25

openstack 镜像命令 openstack的镜像服务_openstack 镜像命令_26

1.3.2 验证镜像
1. 官方镜像

【官方文档】点我快速打开文章

2. 本地镜像

本地上传镜像

ls

rz

ls

openstack 镜像命令 openstack的镜像服务_mysql_27

openstack 镜像命令 openstack的镜像服务_运维_28

命令行上传镜像

file cirros-0.4.0-x86_64-disk.img

openstack image create "cirros" \
  --file cirros-0.4.0-x86_64-disk.img \
  --disk-format qcow2 --container-format bare \
  --public

openstack 镜像命令 openstack的镜像服务_运维_29

openstack 镜像命令 openstack的镜像服务_数据库_30

确认镜像的上传并验证属性

openstack image list

openstack 镜像命令 openstack的镜像服务_运维_31

openstack 镜像命令 openstack的镜像服务_mysql_32