openstack之glance部署

本文档详细介绍了如何在OpenStack环境中部署Glance服务,包括创建数据库实例和用户、配置OpenStack Glance用户、安装软件包、修改配置文件以及初始化数据库。通过这些步骤,确保Glance能为虚拟机提供镜像支持。
摘要由CSDN通过智能技术生成

1.创建数据库实例和数据库用户

[root@ct conf.d]# mysql -u root -p
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.003 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> show grants for glance;
+-------------------------------------------------------------------------------------------------------+
| Grants for glance@%                                                                                   |
+-------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'glance'@'%' IDENTIFIED BY PASSWORD '*C0CE56F2C0C7234791F36D89700B02691C1CAB8E' |
| GRANT ALL PRIVILEGES ON `glance`.* TO 'glance'@'%'                                                    |
+-------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
MariaDB [(none)]>  flush privileges;
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> exit
Bye

2.创建用户、修改配置文件

创建OpenStack的Glance用户

创建用户前,需要首先执行管理员环境变量脚本(此处已经在~/.bashrc 中定义过了)

[root@ct conf.d]# openstack user create --domain default --password GLANCE_PASS glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | cf51b285e71a4aa9959f2770b5e163a9 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
#将glance用户添加到service项目中,并且针对这个项目拥有admin权限;注册glance的API,需要对service项目有admin权限
[root@ct conf.d]# openstack role add --project service --user glance admin
创建一个service服务,service名称为glance,类型为image;创建完成后可以通过 openstack service list 查看
[root@ct conf.d]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 8f62473ff87b460ea8e4e1bb1f64cf46 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

[root@ct conf.d]# openstack service list
+----------------------------------+----------+----------+
| ID                               | Name     | Type     |
+----------------------------------+----------+----------+
| 8c73448e66e044e4a939877ba47f80ec | keystone | identity |
| 8f62473ff87b460ea8e4e1bb1f64cf46 | glance   | image    |
+----------------------------------+----------+----------+

  • 创建镜像服务 API 端点,OpenStack使用三种API端点代表三种服务:admin、internal、public
[root@ct conf.d]# openstack endpoint create --region RegionOne image public http://ct:9292
[root@ct conf.d]# openstack endpoint create --region RegionOne image internal http://ct:9292
[root@ct conf.d]# openstack endpoint create --region RegionOne image admin http://ct:9292
[root@ct conf.d]# openstack endpoint list  ##查看
+----------------------------------+-----------+--------------+--------------+---------+-----------+--------------------+
| ID                               | Region    | Service Name | Service Type | Enabled | Interface | URL                |
+----------------------------------+-----------+--------------+--------------+---------+-----------+--------------------+
| 5944f948f6294bd6a1c1192343133965 | RegionOne | glance       | image        | True    | public    | http://ct:9292     |
| 6f8f8224e6de44f2b292583e1829a3b3 | RegionOne | keystone     | identity     | True    | admin     | http://ct:5000/v3/ |
| 93d20d33474d4445a467506e50257e17 | RegionOne | keystone     | identity     | True    | internal  | http://ct:5000/v3/ |
| b566aefa380e409d9d35db73a749e5d7 | RegionOne | glance       | image        | True    | admin     | http://ct:9292     |
| da6cb24e3b3c4faeac23682174544fe5 | RegionOne | glance       | image        | True    | internal  | http://ct:9292     |
| dd91f003e66b4eb9abb3b8a0fb7d4cde | RegionOne | keystone     | identity     | True    | public    | http://ct:5000/v3/ |
+----------------------------------+-----------+--------------+--------------+---------+-----------+--------------------+

  • 安装 openstack-glance 软件包。
[root@ct ~]# yum -y install openstack-glance

//glance有两个配置文件:/etc/glance/glance-api.conf和/etc/glance/glance-registry.conf
[root@ct conf.d]# cp -a /etc/glance/glance-api.conf{,.bak}
[root@ct conf.d]# grep -Ev '^$|#' /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf

##添加glance-api.conf配置
#传入修改的参数
openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct: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/


[root@ct conf.d]# cat /etc/glance/glance-api.conf
[DEFAULT]
[cinder]
[cors]
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
[file]
[glance.store.http.store]
[glance.store.rbd.store]
[glance.store.sheepdog.store]
[glance.store.swift.store]
[glance.store.vmware_datastore.store]
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
[image_format]
[keystone_authtoken]
www_authenticate_uri = http://ct:5000
auth_url = http://ct:5000
memcached_servers = ct:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS
[oslo_concurrency]
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_middleware]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
[store_type_location_strategy]
[task]
[taskflow_executor]
  • 修改glance-registry.conf 配置文件
[root@ct conf.d]# cp -a /etc/glance/glance-registry.conf{,.bak}
[root@ct conf.d]# grep -Ev '^$|#' /etc/glance/glance-registry.conf.bak > /etc/glance/glance-registry.conf

openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://ct:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://ct:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers ct:11211
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password GLANCE_PASS
openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
#修改参数(配置与glance-api.conf相同
[root@ct conf.d]# cat /etc/glance/glance-registry.conf
[DEFAULT]
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
[keystone_authtoken]
www_authenticate_uri = http://ct:5000
auth_url = http://ct:5000
memcached_servers = ct:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
  • 初始化glance数据库,生成相关表结构;(不管有多少个controler,只需要初始化一次即可)
[root@ct conf.d]# su -s /bin/sh -c "glance-manage db_sync" glance
···
Database is synced successfully.
  • 开启glance服务(此处开启之后会生成存放镜像的目录/var/lib/glance/image)
[root@ct conf.d]# systemctl enable openstack-glance-api.service
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service.
[root@ct conf.d]# systemctl start openstack-glance-api.service

##查看端口(也可以使用lsof -i:9292 )
[root@ct conf.d]# netstat -natp | grep 9292
tcp        0      0 0.0.0.0:9292            0.0.0.0:*               LISTEN      29909/python2   
[root@ct conf.d]# ss -anpt | grep 9292
LISTEN     0      128          *:9292                     *:*                   users:(("glance-api",pid=29924,fd=4),("glance-api",pid=29923,fd=4),("glance-api",pid=29922,fd=4),("glance-api",pid=29921,fd=4),("glance-api",pid=29909,fd=4))
[root@ct conf.d]# lsof -i:9292
COMMAND     PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
glance-ap 29909 glance    4u  IPv4 120699      0t0  TCP *:armtechdaemon (LISTEN)
glance-ap 29921 glance    4u  IPv4 120699      0t0  TCP *:armtechdaemon (LISTEN)
glance-ap 29922 glance    4u  IPv4 120699      0t0  TCP *:armtechdaemon (LISTEN)
glance-ap 29923 glance    4u  IPv4 120699      0t0  TCP *:armtechdaemon (LISTEN)
glance-ap 29924 glance    4u  IPv4 120699      0t0  TCP *:armtechdaemon (LISTEN)
  • 赋予openstack-glance-api.service服务对存储设备的可写权限(-h:值对符号连接/软链接的文件修改)
[root@ct conf.d]# chown -hR glance:glance /var/lib/glance/
[root@ct conf.d]# cd

##上传cirros-0.3.5-x86_64-disk到虚拟机root下,然后导入glance,最后查看是否创建成功
[root@ct ~]# openstack image create --file cirros-0.3.5-x86_64-disk.img --disk-format qcow2 --container-format bare --public cirros
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | f8ab98ff5e73ebab884d80c9dc9c7290                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2020-12-21T12:00:43Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/981fdfd3-1fb8-42ad-8328-74086a107c01/file                                                                                                                                       |
| id               | 981fdfd3-1fb8-42ad-8328-74086a107c01                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | cirros                                                                                                                                                                                     |
| owner            | bfb52d3213454300804cd20c6e14ced6                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f919ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 13267968                                                                                                                                                                                   |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2020-12-21T12:00:43Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | public                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

[root@ct ~]# openstack image list  ##查看镜像
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 981fdfd3-1fb8-42ad-8328-74086a107c01 | cirros | active |
+--------------------------------------+--------+--------+

总结

OpenStack上创建虚拟机需要镜像支持,所以先行进行部署

部署思路:

1、创建数据库、授权

2、创建openstack用户、授权、管理

3、修改配置文件(glance-api.conf、glance-registry.conf)

4、初始化数据库、上传实例镜像

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值