安装glance镜像服务:

官方文档:https://docs.openstack.org/keystone/queens/install/keystone-install-rdo.html

1. 创建glance数据库,创建glance用户,并授权

mysql -uroot -p000000

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

2. 创建glance用户并赋予admin角色

获得 admin 凭证来获取只有管理员能执行的命令的访问权限:
source admin-openrc
openstack user create --domain default --password-prompt glance

[root@controller ~]# openstack user create --domain default --password-prompt glance
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | c7dd30904a9c4466898f0f512036d3d2 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

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

3. 创建glance服务,并创建endpoint(public,internal,admin)

每个glance服务都有自己的endpoint(public,internal,admin这三种)
 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 internal http://controller:9292

[root@controller ~]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 7d443f3f0f7c4dbdb9a835dce79d74ad |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
[root@controller ~]#  openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | c0b9012c64b142649e9f09b9885d98b8 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 7d443f3f0f7c4dbdb9a835dce79d74ad |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@controller ~]#  openstack endpoint create --region RegionOne image internal http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | ea435d1f541e432aa89b966339835ba0 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 7d443f3f0f7c4dbdb9a835dce79d74ad |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@controller ~]#  openstack endpoint create --region RegionOne image internal http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 26f19b7a39404ca9a2afe91e4f78db9b |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 7d443f3f0f7c4dbdb9a835dce79d74ad |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

4. 安装包:openstack-glance

yum install `openstack-glance -y`

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

vim `/etc/glance/glance-api.conf`

[database]
     connection = mysql+pymysql://glance:000000@controller/glance
[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 = 000000
[paste_deploy]
     flavor = keystone
[glance_store]
     stores = file,http
     default_store = file
     filesystem_store_datadir = /var/lib/glance/images/

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

vim /etc/glance/glance-registry.conf

[database]
     connection = mysql+pymysql://glance:000000@controller/glance
[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 = 000000
[paste_deploy]
     flavor = keystone

7. 同步数据库

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

8. 启动glance-api和glance-registry服务

 systemctl enable openstack-glance-api.service \<br /> openstack-glance-registry.service
 systemctl start openstack-glance-api.service \<br /> openstack-glance-registry.service
 
查看运行状态:

[root@controller ~]# systemctl status openstack-glance-api.service openstack-glance-registry.service
● openstack-glance-api.service - OpenStack Image Service (code-named Glance) API server
   Loaded: loaded (/usr/lib/systemd/system/openstack-glance-api.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2020-05-15 15:08:12 CST; 1min 44s ago
 Main PID: 4728 (glance-api)
   CGroup: /system.slice/openstack-glance-api.service
           ├─4728 /usr/bin/python2 /usr/bin/glance-api
           ├─4750 /usr/bin/python2 /usr/bin/glance-api
           └─4752 /usr/bin/python2 /usr/bin/glance-api

5月 15 15:08:14 controller glance-api[4728]: /usr/lib/python2.7/site-packages/paste/deplo...y.
5月 15 15:08:14 controller glance-api[4728]: return pkg_resources.EntryPoint.parse("x=" +...e)
5月 15 15:08:14 controller glance-api[4728]: /usr/lib/python2.7/site-packages/paste/deplo...y.
5月 15 15:08:14 controller glance-api[4728]: return pkg_resources.EntryPoint.parse("x=" +...e)
5月 15 15:08:15 controller glance-api[4728]: /usr/lib/python2.7/site-packages/paste/deplo...y.
5月 15 15:08:15 controller glance-api[4728]: return pkg_resources.EntryPoint.parse("x=" +...e)
5月 15 15:08:15 controller glance-api[4728]: /usr/lib/python2.7/site-packages/paste/deplo...y.
5月 15 15:08:15 controller glance-api[4728]: return pkg_resources.EntryPoint.parse("x=" +...e)
5月 15 15:08:15 controller glance-api[4728]: /usr/lib/python2.7/site-packages/paste/deplo...er
5月 15 15:08:15 controller glance-api[4728]: val = callable(*args, **kw)

● openstack-glance-registry.service - OpenStack Image Service (code-named Glance) Registry server
   Loaded: loaded (/usr/lib/systemd/system/openstack-glance-registry.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2020-05-15 15:08:12 CST; 1min 44s ago
 Main PID: 4729 (glance-registry)
   CGroup: /system.slice/openstack-glance-registry.service
           ├─4729 /usr/bin/python2 /usr/bin/glance-registry
           ├─4751 /usr/bin/python2 /usr/bin/glance-registry
           └─4753 /usr/bin/python2 /usr/bin/glance-registry

9. 下载一个基础镜像cirror

 

10. 上传镜像

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

[root@controller ~]# openstack image create "cirros" \
>    --file cirros-0.3.5-x86_64-disk.img \
>    --disk-format qcow2 --container-format bare \
>    --public
+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | f8ab98ff5e73ebab884d80c9dc9c7290                     |
| container_format | bare                                                 |
| created_at       | 2020-05-15T07:18:29Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/6d4ba40e-97eb-47b8-a855-4e0c114cdb2c/file |
| id               | 6d4ba40e-97eb-47b8-a855-4e0c114cdb2c                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | 0c2f860c54b94c158aa945e1683bf644                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13267968                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2020-05-15T07:18:30Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+

qcow2:指的是磁盘格式
-0.3.5-x86_64-disk:指的是版本号

11. 查看镜像

 openstack image list

[root@controller ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 6d4ba40e-97eb-47b8-a855-4e0c114cdb2c | cirros | active |
+--------------------------------------+--------+--------+

这个镜像是我们以后创建虚拟机时需要使用的,和iso镜像不同

最后修改:2024 年 03 月 14 日
如果觉得我的文章对你有用,请随意赞赏