openstack-train安装 · 2022年10月7日 0

手动部署OpenStack Train双节点-安装glance

一、安装与配置glance镜像服务

1、安装Glance软件包

[root@controller ~]# yum -y install openstack-glance
在安装“openstack-glance”软件包的时候,会自动在CentOS Linux中生成一个名为“glance”的用户和同名用户组。
(1)查看用户信息
[root@controller ~]# cat /etc/passwd | grep glance
(2)查看用户组信息
[root@controller ~]# cat /etc/group | grep glance

2、创建Glance的数据库并授权

第1步,用下面的方法进入MariaDB数据库服务器。
[root@controller ~]# mysql -uroot -p000000
第2步,新建“glance”数据库。
MariaDB [(none)]> CREATE DATABASE glance;
第3步,给用户授权使用新建数据库。

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY '000000';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY '000000';

3、修改Glance配置文件

(1)将配置文件去掉注释和空行
第1步,备份配置文件。
[root@controller ~]# cp /etc/glance/glance-api.conf /etc/glance/glance-api.bak
第2步,去掉所有注释和空行,生成新的配置文件。
[root@controller ~]# grep -Ev '^$|#' /etc/glance/glance-api.bak > /etc/glance/glance-api.conf
这里的正则表达式“^|#”的具体含义为:匹配空行(“^”,其中“^”是一行的开头,“$”是一行的结尾),或者(符号“|”表示或者)匹配第一个字符为“#”的行。结合反向匹配参数“-v”,最终匹配的是所有不为空和不以注释符号“#”开头的行。
(2)编辑新的配置文件
第1步,打开配置文件进行编辑。
[root@controller ~]# nano /etc/glance/glance-api.conf

[cinder]
[cors]
[database]
[file]
[glance.store.http.store]
[glance.store.rbd.store]
[glance.store.sheepdog.store]
[glance.store.swift.store]
[glance.store.vmware_datastore.store]
[glance_store]
[image_format]
[keystone_authtoken]
[oslo_concurrency]
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_middleware]
[oslo_policy]
[paste_deploy]
[profiler]
[store_type_location_strategy]
[task]
[taskflow_executor]

第2步,修改“[database]”部分,实现与数据库连接。
connection =mysql+pymysql://glance:000000@controller/glance
第3步,修改“[keystone_authtoken]”和“[paste_deploy]”部分,实现与Keystone交互。

[keystone_authtoken]
www_authenticate_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 = project
username = glance
password = 000000
[paste_deploy]
flavor = keystone

第4步,修改“[glance_store]”部分,指定后端存储系统。

[glance_store]
stores = file,http
default_store = file                #默认存储系统为本地文件系统
filesystem_store_datadir = /var/lib/glance/images/    #镜像文件实际存储的目录

注释:“/var/lib/glance/”文件夹是在安装Glance的时候自动生成的,“glance”用户具有该文件夹的完全操作权限,请不要随意将其更改为其他“glance”用户没有权限的目录。

4、初始化Glance的数据库

(1)同步数据库
Glance安装文件提供了数据库的基础表数据,此时还没有将数据导入“glance”数据库中,需要手动将数据同步导入数据库中。
[root@controller ~]# su glance -s /bin/sh -c "glance-manage db_sync"
“su glance”:su命令用于用户切换。这里切换到“glance”用户,该用户已经拥有对“glance”数据库的管理权限。
“-s /bin/sh”:-s为su命令的选项,指定用什么编译器(Shell)来执行命令,“/bin/sh”就是指定的编译器。
“-c”:su命令的选项,在其后引号内的是具体执行的命令。"
glance-manage db_sync"实现了数据同步到数据库。
(2)检查数据库是否同步成功

[root@controller ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.20-MariaDB MariaDB Server

Copyright (c) 2000, 2018, 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 table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
MariaDB [glance]> show tables;
+----------------------------------+
| Tables_in_glance                 |
+----------------------------------+
| alembic_version                  |
| 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                            |
+----------------------------------+
15 rows in set (0.000 sec)

MariaDB [glance]> quit
Bye
[root@controller ~]#

如果在glance数据库中存在以上数据表,则表示数据库已经同步成功!

二、Glance组件初始化

Glance安装与配置成功以后,需要给Glance初始化用户及密码并分配用户角色、初始化服务和服务端点等,使Glance组件可以启用。

1、创建glance用户并分配角色

第1步,导入环境变量模拟登录。
[root@controller ~]# . admin-login
第2步,在OpenStack云计算平台中创建用户“glance”。

[root@controller ~]#  openstack user create --domain default --password 000000 glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | dca20880c28a4830981539df34696202 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

第3步,给用户“glance”分配“admin”角色
[root@controller ~]# openstack role add --project project --user glance admin

2、创建Glance服务及端点

(1)创建服务
创建名为“glance”、类型为“image”的服务。

[root@controller ~]# openstack service create --name glance image
+---------+----------------------------------+
| Field   | Value                            |
+---------+----------------------------------+
| enabled | True                             |
| id      | 110cf2cd177f4e70a347406899e1042a |
| name    | glance                           |
| type    | image                            |
+---------+----------------------------------+

(2)创建镜像服务端点
OpenStack组件的服务端点有3种,分别对应Admin用户(admin)、内部组件(internal)、公众用户(public)服务的地址。
第1步,创建公众用户访问的服务端点。

[root@controller ~]# openstack endpoint create --region RegionOne glance public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | c419685c51b8431db4ce2ec610b0c5de |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 110cf2cd177f4e70a347406899e1042a |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

第2步,创建内部组件访问的服务端点。

[root@controller ~]# openstack endpoint create --region RegionOne glance internal http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | bc7e6cac588e4806b66968217f72c383 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 110cf2cd177f4e70a347406899e1042a |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

第3步,创建Admin用户访问端点。

[root@controller ~]# openstack endpoint create --region RegionOne glance admin http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | a6f3bbe9eedf4b3f84ad84e25e6bf969 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 110cf2cd177f4e70a347406899e1042a |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

3、启动Glance服务

首先,设置开机启动Glance服务。
[root@controller ~]# systemctl enable openstack-glance-api
然后,立即启动Glance服务。
[root@controller ~]# systemctl start openstack-glance-api

三、验证glance服务

1.查看端口占用情况
由于Glance服务要占用9292端口,查看9292端口的状态就可以判断服务是否运行。

[root@controller ~]# netstat -tnlup|grep 9292
tcp        0      0 0.0.0.0:9292            0.0.0.0:*              LISTEN      5805/python2

可见9292端口正处于“LISTEN”监听状态,因此服务为正常开启。
2.查看服务运行状态
也可以通过systemctl status命令查看服务的运行状态。

[root@controller ~]# systemctl status openstack-glance-api
● 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 五 2022-10-07 21:21:54 CST; 14min ago
 Main PID: 14569 (glance-api)
   CGroup: /system.slice/openstack-glance-api.service
           ├─14569 /usr/bin/python2 /usr/bin/glance-api
           ├─14607 /usr/bin/python2 /usr/bin/glance-api
           ├─14608 /usr/bin/python2 /usr/bin/glance-api
           └─14609 /usr/bin/python2 /usr/bin/glance-api

10月 07 21:21:54 controller systemd[1]: Started OpenStack Image Service (code-named Glance) API server.
10月 07 21:21:55 controller glance-api[14569]: /usr/lib/python2.7/site-packages/paste/deploy/loadwsgi.py:22: PkgResourcesDeprecationWarning...arately.
10月 07 21:21:55 controller glance-api[14569]: return pkg_resources.EntryPoint.parse("x=" + s).load(False)
Hint: Some lines were ellipsized, use -l to show in full.

当结果出现“activie(running)”时说明该服务正处于运行状态。

四、用Glance制作镜像

CirrOS是一种很小的Linux操作系统,仅有十几兆字节大小,这里Glance将用它来制作一个镜像。
1.制作镜像

[root@controller ~]# openstack image create --file cirros-0.5.1-x86_64-disk.img --disk-format qcow2 --container-format bare --public cirros
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | 1d3062cd89af34e419f7100277f38b2b                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2022-10-07T13:23:02Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/66acb9d3-f683-48ca-9132-082175ff30d3/file                                                                                                                                       |
| id               | 66acb9d3-f683-48ca-9132-082175ff30d3                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | cirros                                                                                                                                                                                     |
| owner            | c80af2a6b06842c4b2f4598f97e67828                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='553d220ed58cfee7dafe003c446a9f197ab5edf8ffc09396c74187cf83873c877e7ae041cb80f3b91489acf687183adcd689b53b38e3ddd22e627e7f98a09c46', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 16338944                                                                                                                                                                                   |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2022-10-07T13:23:02Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | public                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

2.查看镜像
(1)查看镜像列表
可以通过openstack命令查阅镜像元数据而获知镜像的相关信息,也可以到后端存储中直接查看物理镜像文件。

[root@controller ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 66acb9d3-f683-48ca-9132-082175ff30d3 | cirros | active |
+--------------------------------------+--------+--------+

(2)查看镜像物理文件

[root@controller ~]# ll /var/lib/glance/images/
总用量 15956
-rw-r-----. 1 glance glance 16338944 10月  7 21:23 66acb9d3-f683-48ca-9132-082175ff30d3