OpenStack Train版-3.安装glance镜像服务

Posted wang-hongwei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenStack Train版-3.安装glance镜像服务相关的知识,希望对你有一定的参考价值。

1. 创建数据库并授权

[root@controller ~]# mysql -u root 
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO ‘glance‘@‘localhost‘ IDENTIFIED BY ‘GLANCE_DBPASS‘;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO ‘glance‘@‘%‘ IDENTIFIED BY ‘GLANCE_DBPASS‘;
Query OK, 0 rows affected (0.000 sec)

2. 创建glance用户

[root@controller ~]# openstack user create --domain default --password GLANCE_PASS glance
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | c9cccf601ece444a86fcba967b4633ad |
| name | glance |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
给glance用户授权
[root@controller ~]# openstack role add --project service --user glance admin

3. 创建glance服务实体

[root@controller ~]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 165c4d71d9354940a7efe60a9bb71211 |
| name | glance |
| type | image |
+-------------+----------------------------------+

4. 创建镜像服务API访问端点

[root@controller ~]# openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 94a3dac1cadd419f9d40e29a8dd8fed2 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 165c4d71d9354940a7efe60a9bb71211 |
| 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 | c2be9485f8a7412490ca1af815041461 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 165c4d71d9354940a7efe60a9bb71211 |
| 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 | 806cde326a604e15b9bd6ecbb9340787 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 165c4d71d9354940a7efe60a9bb71211 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+

5. 安装glance软件包

[root@controller ~]# yum install openstack-glance 

6. 编辑glance的配置文件

cp -a /etc/glance/glance-api.conf{,.bak}
cp -a /etc/glance/glance-registry.conf{,.bak}
grep -Ev ‘^$|#‘ /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf
grep -Ev ‘^$|#‘ /etc/glance/glance-registry.conf.bak > /etc/glance/glance-registry.conf

openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://controller:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://controller:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers controller:11211
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password GLANCE_PASS
openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone

openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/

7. 填充glance数据库

[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance

8. 启动glance服务并设置开机自启

[root@controller ~]# systemctl enable openstack-glance-api.service
[root@controller ~]# systemctl start openstack-glance-api.service

启动好之后,查看端口情况,如果有9292端口,则表示glance启动成功。
[root@controller ~]# lsof -i:9292
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
glance-ap 9333 glance 4u IPv4 48361 0t0 TCP *:armtechdaemon (LISTEN)
glance-ap 9913 glance 4u IPv4 48361 0t0 TCP *:armtechdaemon (LISTEN)

9.下载cirros镜像,验证glance的安装

[root@controller ~]# wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
[root@controller ~]# openstack image create --file /root/cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --public cirros
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum | 443b7623e27ecf03dc9e01ee93f67afe |
| container_format | bare |
| created_at | 2020-01-09T14:30:34Z |
| disk_format | qcow2 |
| file | /v2/images/060d49e3-5346-4bbd-ba42-7247f2daead5/file |
| id | 060d49e3-5346-4bbd-ba42-7247f2daead5 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 8dd2972e6c0b4d99b100d087e35ad439 |
| properties | os_hash_algo=‘sha512‘, os_hash_value=‘6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78‘, os_hidden=‘False‘ |
| protected | False |
| schema | /v2/schemas/image |
| size | 12716032 |
| status | active |
| tags | |
| updated_at | 2020-01-09T14:30:35Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

(官方文档坑点之一,这里不要使用官方文档里面的glance image-create这样的写法,新版本的OpenStack已经不支持,尽量统一使用以openstack开头的命令写法)

[root@controller ~]# glance image-list
+--------------------------------------+--------+
| ID | Name |
+--------------------------------------+--------+
| 060d49e3-5346-4bbd-ba42-7247f2daead5 | cirros |
+--------------------------------------+--------+

查看镜像的物理文件
[root@controller ~]# ll /var/lib/glance/images/
total 12420
-rw-r----- 1 glance glance 12716032 Jan 9 22:30 060d49e3-5346-4bbd-ba42-7247f2daead5

以上是关于OpenStack Train版-3.安装glance镜像服务的主要内容,如果未能解决你的问题,请参考以下文章

OpenStack Train版-1.环境安装

OpenStack Train版-2.安装keystone身份认证服务

OpenStack Train版-2.安装keystone身份认证服务

OpenStack Train版-1.安装基础环境&服务

OpenStack Train版-8.安装neutron网络服务(控制节点)

#打卡不停更#[图文并茂]Packstack部署train版openstack