1.安装glance服务所需要的包
[root@controller ~]# yum install openstack-glance -y |
2.创建glance的数据库
2.1登录数据库 [root@controller ~]# mysql -u root -p000000 MariaDB [(none)]> CREATE DATABASE glance; Query OK, 1 row affected (0.01 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' -> IDENTIFIED BY '000000'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY '000000'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye |
3.创建服务实体和API端点
3.1创建glance用户 [root@controller ~]# source /etc/keystone/admin-openrc [root@controller ~]# openstack user create --domain default --password-prompt glance User Password: Repeat User Password: +-----------+----------------------------------+ | Field | Value | +-----------+----------------------------------+ | domain_id | 11c1d63da1784b51bc6d13335f635778 | | enabled | True | | id | 8ffee5ad72504eafb9249ce43badd6b3 | | name | glance | +-----------+----------------------------------+ 3.2赋予glance用户service项目admin角色 [root@controller ~]# openstack role add --project service --user glance admin 3.3创建glance服务实体与端点 [root@controller ~]# openstack service create --name glance \ --description "OpenStack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | 3277d0bac18a4c42b95baf15ff62ede8 | | name | glance | | type | image | +-------------+----------------------------------+ [root@controller ~]# openstack endpoint create --region RegionOne \ image public http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | cdbe7fa002904d71b21efdd730ba3bdc | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | 3277d0bac18a4c42b95baf15ff62ede8 | | 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 | 9ca380ceb1be48c2be823649bb8c9cbf | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | 3277d0bac18a4c42b95baf15ff62ede8 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+ [root@controller ~]# openstack endpoint create --region RegionOne \ image admin http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 89b5d2e552f7472fb8f7cff1a29be001 | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | 3277d0bac18a4c42b95baf15ff62ede8 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+ |
4.修改glance的两个配置文件(数字为行数)
4.1配置/etc/glance/glance-api.conf [root@controller ~]# vim /etc/glance/glance-api.conf 618 [database]#配置数据库访问 619 connection = mysql+pymysql://glance:000000@controller/glance 733 [glance_store]#配置本地文件系统存储和映像文件的位置 734 stores = file,http 735 default_store = file 736 filesystem_store_datadir = /var/lib/glance/images/ 1111 [keystone_authtoken]#配置身份服务访问 1112 auth_uri = http://controller:5000 1113 auth_url = http://controller:35357 1114 memcached_servers = controller:11211 1115 auth_type = password 1116 project_domain_name = default 1117 user_domain_name = default 1118 project_name = service 1119 username = glance 1120 password = 000000 1685 [paste_deploy] 1686 flavor = keystone [root@controller ~]# vim /etc/glance/glance-registry.conf 359 [database] 360 connection = mysql+pymysql://glance:000000@controller/glance 837 [keystone_authtoken] 838 auth_uri = http://controller:5000 839 auth_url = http://controller:35357 840 memcached_servers = controller:11211 841 auth_type = password 842 project_domain_name = default 843 user_domain_name = default 844 project_name = service 845 username = glance 846 password = 000000 1393 [paste_deploy] 1394 flavor = keystone |
5.同步数据库
[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance Option "verbose" from group "DEFAULT" is deprecated for removal. Its value may be silently ignored in the future. /usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1056: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade expire_on_commit=expire_on_commit, _conf=conf) /usr/lib/python2.7/site-packages/pymysql/cursors.py:170: Warning: (1831, u"Duplicate index 'ix_image_properties_image_id_name' defined on the table 'glance.image_properties'. This is deprecated and will be disallowed in a future release.") result = self._query(query) 5.1验证同步是否成功 [root@controller ~]# mysql -uglance -p000000 -e "use 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 | +----------------------------------+ |
6.启动glance,并设置开机自动启动
[root@controller ~]# systemctl enable openstack-glance-api.service \ openstack-glance-registry.service Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service. Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service to /usr/lib/systemd/system/openstack-glance-registry.service. [root@controller ~]# systemctl start openstack-glance-api.service \ openstack-glance-registry.service |
7.验证操作
7.1下载OpenStack官网提供的镜像 [root@controller ~]# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img --2018-06-29 11:34:50-- http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img Resolving download.cirros-cloud.net (download.cirros-cloud.net)... 64.90.42.85, 2607:f298:6:a036::bd6:a72a Connecting to download.cirros-cloud.net (download.cirros-cloud.net)|64.90.42.85|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 13287936 (13M) [text/plain] Saving to: ‘cirros-0.3.4-x86_64-disk.img’ 100%[======================================================>] 13,287,936 355KB/s in 38s 2018-06-29 11:35:33 (344 KB/s) - ‘cirros-0.3.4-x86_64-disk.img’ saved [13287936/13287936] [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 | 2018-06-29T03:36:03Z | | disk_format | qcow2 | | file | /v2/images/c4f689b9-a314-46ac-a995-f909a6fd16e9/file | | id | c4f689b9-a314-46ac-a995-f909a6fd16e9 | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | 84f00df4afd847248adfebd326a81a42 | | protected | False | | schema | /v2/schemas/image | | size | 13287936 | | status | active | | tags | | | updated_at | 2018-06-29T03:36:03Z | | virtual_size | None | | visibility | public | +------------------+------------------------------------------------------+ 7.3查看上传的镜像 [root@controller ~]# openstack image list +--------------------------------------+--------+--------+ | ID | Name | Status | +--------------------------------------+--------+--------+ | c4f689b9-a314-46ac-a995-f909a6fd16e9 | cirros | active | +--------------------------------------+--------+--------+ |