您的位置:首页 > 运维架构 > Linux

OpenStack-M版(Mitaka)搭建基于(Centos7.2)+++四、Openstack镜像服务(glance)

2017-11-28 22:22 656 查看
四、Openstack镜像服务(glance)

简单介绍:

Glance主要有两个组件:glance-api、glance-registry

glance-api:接受镜像api调用,镜像发现、恢复、存储

glance-registry:存储、处理和恢复镜像的元数据

安装

glance安装在控制节点

进入SQL创建keystone数据库并授予权限

mysql -uroot -p

CREATE DATABASE glance;

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY '123456';

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY '123456';


创建glance用户

需要管理员权限

. admin-openrc


openstack user create --domain default --password-prompt glance

添加 admin 角色到 glance 用户和 service 项目上

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

创建``glance``服务实体

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

创建镜像服务的 API 端点

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[/code] 
安装glance软件包

yum install openstack-glance


修改配置文件/etc/glance/glance-api.conf

vi /etc/glance/glance-api.conf

数据库连接
[database]
connection = mysql+pymysql://glance:123456@controller/glance

认证
[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 = 123456(你为glance设置的密码)

[paste_deploy]
flavor = keystone

存储和镜像位置
[glance_store]
stores = file,http
default_store = file
filesyst
d801
em_store_datadir = /var/lib/glance/images/


修改配置文件/etc/glance/glance-registry.conf

vi /etc/glance/glance-registry.conf

数据库访问
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

认证
[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(你为glance设置的密码)
password = 123456

[paste_deploy]
flavor = keystone


同步数据库

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


查看glance数据库是否有数据

[root@controller ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 229
Server version: 10.1.12-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use glance;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [glance]> show tables;
+----------------------------------+
| Tables_in_glance                 |
+----------------------------------+
| artifact_blob_locations          |
| artifact_blobs                   |
| artifact_dependencies            |
| artifact_properties              |
| artifact_tags                    |
| artifacts                        |
| image_locations                  |
| image_members                    |
| image_properties                 |
| image_tags                       |
| images                           |
| metadef_namespace_resource_types |
| metadef_namespaces               |
| metadef_objects                  |
| metadef_properties               |
| metadef_resource_types           |
| metadef_tags                     |
| migrate_version                  |
| task_info                        |
| tasks                            |
+----------------------------------+
20 rows in set (0.01 sec)

MariaDB [glance]>


如果没有数据检查[database]下connection=是否正确,如果没有问题可能是赋予glance数据库权限时有误,重新赋予。

启动镜像服务、配置他们随机启动

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


验证glance

获取管理员权限

. admin-openrc


下载镜像(wget下载有点慢,推荐直接下载再上传自虚拟机)

wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img[/code] 创建镜像命令

image是指操作的资源

create表示对资源执行的操作创建一个image

cirros表示名称

--file指定镜像的地址

--disk-format指定image磁盘格式(qcow2,raw,vhd,vmdk,vdi,iso,aki,ari,ami)

container-format指定image容器的格式(bare,ovf,aki,ari,ami)

public表示该镜像可以本公共访问

[root@controller ~]# openstack image create "cirros" \
>   --file cirros-0.3.4-x86_64-disk.img \
>   --disk-format qcow2 --container-format bare \
>   --public
+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6                     |
| container_format | bare                                                 |
| created_at       | 2017-11-16T20:16:03Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/31cdbfff-c441-4740-a597-05f542ff845c/file |
| id               | 31cdbfff-c441-4740-a597-05f542ff845c                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | af24a3c94886470183c864ef0f161b4c                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13287936                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2017-11-16T20:16:09Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+
创建成功说明ok

如果创建失败可以检查配置文件认证那块设置是否有误

镜像管理基本命令

查看镜像

[root@controller ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 31cdbfff-c441-4740-a597-05f542ff845c | cirros | active |
+--------------------------------------+--------+--------+

查看镜像详细信息

[root@controller ~]# glance image-show 31cdbfff-c441-4740-a597-05f542ff845c
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6     |
| container_format | bare                                 |
| created_at       | 2017-11-16T20:16:03Z                 |
| disk_format      | qcow2                                |
| id               | 31cdbfff-c441-4740-a597-05f542ff845c |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | cirros                               |
| owner            | af24a3c94886470183c864ef0f161b4c     |
| protected        | False                                |
| size             | 13287936                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2017-11-16T20:16:09Z                 |
| virtual_size     | None                                 |
| visibility       | public                               |
+------------------+--------------------------------------+


删除镜像

openstack image delete 31cdbfff-c441-4740-a597-05f542ff845c
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐