openstack官方安装文档的解析--glance篇(3)
# openstack-glance的安装和配置([glance 16.0.2.dev13](https://docs.openstack.org/glance/queens/index.html))
## Install and configure (Red Hat)
UPDATED: 2019-09-10 15:48
This section describes how to install and configure the Image service, code-named glance, on the controller node. For simplicity, this configuration stores images on the local file system.
## Prerequisites[¶](https://docs.openstack.org/glance/queens/install/install-rdo.html#prerequisites)
Before you install and configure the Image service, you must create a database, service credentials, and API endpoints.
#安装并配置镜像服务前,你必须新建一个数据库并暴露接口
1. To create the database, complete these steps:
- Use the database access client to connect to the database server as the `root` user:
```
$ mysql -u root -p
```
- Create the `glance` database:
```
MariaDB [(none)]> CREATE DATABASE glance;
```
- Grant proper access to the `glance` database:
```
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'GLANCE_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY 'GLANCE_DBPASS';
```
Replace `GLANCE_DBPASS` with a suitable password.
- Exit the database access client.
2. Source the `admin` credentials to gain access to admin-only CLI commands:
```
$ . admin-openrc
```
3. To create the service credentials, complete these steps:
- Create the `glance` user:
#新建用户,用户名为glance
```
$ openstack user create --domain default --password-prompt glance
#为用户glance赋予密码
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | 3f4e777c4062483ab8d9edd7dff829df |
| name | glance |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
```
- Add the `admin` role to the `glance` user and `service` project:
```
$ openstack role add --project service --user glance admin
```
#添加用户进入service项目,并提升为admin管理员
Note
This command provides no output.
- Create the `glance` service entity:
```
$ openstack service create --name glance \
--description "OpenStack Image" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| name | glance |
| type | image |
+-------------+----------------------------------+
```
#新建服务glance
4. Create the Image service API endpoints:
```
$ openstack endpoint create --region RegionOne \
image public http://controller:9292
#暴露接口,总共三个接口,下面不赘述
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 340be3625e9b4239a6415d034e98aace |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
$ openstack endpoint create --region RegionOne \
image internal http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | a6e4b153c2ae4c919eccfdbb7dceb5d2 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
$ openstack endpoint create --region RegionOne \
image admin http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 0c37ed58103f4300a84ff125a539032d |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance |
| service_type | image |
| url | http://controller:9292 |
+--------------+----------------------------------+
```
## Install and configure components[¶](https://docs.openstack.org/glance/queens/install/install-rdo.html#install-and-configure-components)
Note
Default configuration files vary by distribution. You might need to add these sections and options rather than modifying existing sections and options. Also, an ellipsis (`...`) in the configuration snippets indicates potential default configuration options that you should retain.
1. Install the packages:
#安装包
```
# yum install openstack-glance
```
1. Edit the `/etc/glance/glance-api.conf` file and complete the following actions:
#编辑`/etc/glance/glance-api.conf并完成以下选项
- In the `[database]` section, configure database access:
```
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
```
#数据库连接方式,GLANCE_DBPASS这个密码为数据库glance的密码
Replace `GLANCE_DBPASS` with the password you chose for the Image service database.
- In the `[keystone_authtoken]` and `[paste_deploy]` sections, configure Identity service access:
```
[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 = GLANCE_PASS
[paste_deploy]
# ...
flavor = keystone
```
#别忘了改这个
Replace `GLANCE_PASS` with the password you chose for the `glance` user in the Identity service.
#替换password = GLANCE_PASS 值为用户glance的密码
Note
Comment out or remove any other options in the `[keystone_authtoken]` section.
- In the `[glance_store]` section, configure the local file system store and location of image files:
```
[glance_store]
# ...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
```
#镜像的存放地址,镜像存储的方式,默认镜像存放的形式为文件形式
2. Edit the `/etc/glance/glance-registry.conf` file and complete the following actions:
编辑 `/etc/glance/glance-registry.conf` 并完成以下动作
Note
The Glance Registry Service and its APIs have been DEPRECATED in the Queens release and are subject to removal at the beginning of the ‘S’ development cycle, following the [OpenStack standard deprecation policy](https://governance.openstack.org/reference/tags/assert_follows-standard-deprecation.html).
For more information, see the Glance specification document [Actually Deprecate the Glance Registry](http://specs.openstack.org/openstack/glance-specs/specs/queens/approved/glance/deprecate-registry.html).
- In the `[database]` section, configure database access:
```
[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
```
#数据库连接方式
Replace `GLANCE_DBPASS` with the password you chose for the Image service database.
#此处密码为镜像服务的密码
- In the `[keystone_authtoken]` and `[paste_deploy]` sections, configure Identity service access:
```
[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 = GLANCE_PASS
#和glance-api里的配置一样,复制过来即可
[paste_deploy]
# ...
flavor = keystone
```
#别忘了 改这个
Replace `GLANCE_PASS` with the password you chose for the `glance` user in the Identity service.
Note
Comment out or remove any other options in the `[keystone_authtoken]` section.
3. Populate the Image service database:
```
# su -s /bin/sh -c "glance-manage db_sync" glance
```
#同步glance数据库
Note
Ignore any deprecation messages in this output.
#注意,这个同步是没有输出的,没有输出才是正常的
## Finalize installation[¶](https://docs.openstack.org/glance/queens/install/install-rdo.html#finalize-installation)
- Start the Image services and configure them to start when the system boots:
```
# systemctl enable openstack-glance-api.service \
openstack-glance-registry.service
#自启动服务 两个服务
# systemctl start openstack-glance-api.service \
openstack-glance-registry.service
#启动两个服务
```
## Verify operation
#验证操作
UPDATED: 2019-09-10 15:48
Verify operation of the Image service using [CirrOS]
(http://launchpad.net/cirros),
a small Linux image that helps you test your OpenStack deployment.
#上述网址有一个小的测试镜像帮助你检查镜像服务是否正常,请去下载,
For more information about how to download and build images,http://launchpad.net/cirros
see [OpenStack Virtual Machine Image Guide](https://docs.openstack.org/image-guide/).
For information about how to manage images, see the
[OpenStack End User Guide]
(https://docs.openstack.org/user-guide/common/cli-manage-images.html).
Note
Perform these commands on the controller node.
1. Source the `admin` credentials to gain access to admin-only CLI commands:
```
$ . admin-openrc
```
#运行环境脚本
2. Download the source image:
```
$ wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
```
#下载镜像。在上述网址
Note
Install `wget` if your distribution does not include it.
#如果没有wget命令,请yum安装该命令
3. Upload the image to the Image service using the [QCOW2]
(https://docs.openstack.org/glance/queens/glossary.html#term-qemu-copy-on-write-2-qcow2) disk format,
[bare](https://docs.openstack.org/glance/queens/glossary.html#term-bare)
container format, and public visibility so all projects can access it:
```
$ openstack image create "cirros" \
--file cirros-0.4.0-x86_64-disk.img \
--disk-format qcow2 --container-format bare \
--public
#上传镜像
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | 133eae9fb1c98f45894a4e60d8736619 |
| container_format | bare |
| created_at | 2015-03-26T16:52:10Z |
| disk_format | qcow2 |
| file | /v2/images/cc5c6982-4910-471e-b864-1098015901b5/file |
| id | cc5c6982-4910-471e-b864-1098015901b5 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | ae7a98326b9c455588edd2656d723b9d |
| protected | False |
| schema | /v2/schemas/image |
| size | 13200896 |
| status | active |
| tags | |
| updated_at | 2015-03-26T16:52:10Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
```
For information about the **openstack image create** parameters,
see [Create or update an image (glance)]
(https://docs.openstack.org/user-guide/common/cli-manage-images.html#create-or-update-an-image-glance) in the `OpenStack UserGuide`.
For information about disk and container formats for images, see [Disk and container formats for images](https://docs.openstack.org/image-guide/image-formats.html) in the `OpenStackVirtual Machine Image Guide`.
Note
OpenStack generates IDs dynamically, so you will see different values in the example command output.
4. Confirm upload of the image and validate attributes:
```
$ openstack image list
#查看镜像
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
+--------------------------------------+--------+--------+
```
#可以看到镜像,表示该服务配置成功,否则失败