OpenStack-Glance组件部署
一、创建数据库实例和数据库用户
[root@ct ~]# mysql -u root -p123456 //登陆数据库
MariaDB [(none)]> CREATE DATABASE glance; //创建glance
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS'; //本地授权
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS'; //所有网段授权
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges; //刷新
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> exit //推出
Bye
二、创建用户、修改配置文件
2.1、创建OpenStack的Glance用户
创建用户前,需要首先执行管理员环境变量脚本(此处已经在~/.bashrc 中定义过了)
[root@ct ~]# openstack user create --domain default --password GLANCE_PASS glance //创建glane用户
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | 4b6da27ddb654e8ebca208d332ca8a4d |
| name | glance |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
[root@ct ~]# openstack role add --project service --user glance admin
//将glance用户添加到service项目中,并且针对这个项目拥有admin权限;注册glance的API,需要对service项目有admin权限
[root@ct ~]# openstack service create --name glance --description "OpenStack Image" image
//创建一个service服务,service名称为glance,类型为image;创建完成后可以通过 openstack service list 查看
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 2e31acd35820444daac734cd0bb70d66 |
| name | glance |
| type | image |
+-------------+----------------------------------+
2.2、创建镜像服务 API 端点,OpenStack使用三种API端点代表三种服务:admin(管理员)、internal(私有)、public(公有)
[root@ct ~]# openstack endpoint create --region RegionOne imaghttp://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 91e6d746a0c64deebe103b3c9aa06351 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 2e31acd35820444daac734cd0bb70d66 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
[root@ct ~]# openstack endpoint create --region RegionOne imagl http://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | dfcf4351eb4c4348ace713067c31f4d4 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 2e31acd35820444daac734cd0bb70d66 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
[root@ct ~]# openstack endpoint create --region RegionOne imagttp://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 6cc35616523d4c458c2148c135fb2656 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 2e31acd35820444daac734cd0bb70d66 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
2.3、安装 openstack-glance 软件包。
[root@ct ~]# yum -y install openstack-glance
2.4、修改glance配置文件
glance有两个配置文件:
/etc/glance/glance-api.conf
/etc/glance/glance-registry.conf
[root@ct ~]# cp -a /etc/glance/glance-api.conf{,.bak} //备份配置文件
[root@ct ~]# grep -Ev '^$|#' /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf //去掉空格和带#号的行
[root@ct ~]# cp -a /etc/glance/glance-registry.conf{,.bak}
[root@ct ~]# grep -Ev '^$|#' /etc/glance/glance-registry.conf.bak > /etc/glance/glance-registry.conf
[root@ct ~]# vim glance-api.conf.sh
#!/bin/bash
#传入修改的参数
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 ~]# vim glance-registry.conf.sh
#!/bin/bash
#修改配置文件参数
openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@t/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
运行命令脚本
[root@ct ~]# sh glance-api.conf.sh
[root@ct ~]# sh glance-registry.conf.sh
查看glance-api.conf配置文件
[root@ct ct]# 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 #存储类型,file:文件,http:基于api调用的方式,把镜像放到其他存储上
default_store = file #默认存储方式
filesystem_store_datadir = /var/lib/glance/images/ ##指定镜像存放的本地目录
[image_format]
[keystone_authtoken]
www_authenticate_uri = http://ct:5000 ##指定认证的keystone的URL
auth_url = http://ct:5000
memcached_servers = ct:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service #glance用户针对service项目拥有admin权限
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 #指定提供认证的服务器为keystone
[profiler]
[store_type_location_strategy]
[task]
[taskflow_executor]
修改参数(配置与glance-api.conf相同)
[root@ct ~]# cat /etc/glance/glance-registry.conf
[DEFAULT]
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@t/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
username = glance
password = GLANCE_PASS
project_name = service
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
2.5、初始化glance数据库,生成相关表结构;(不管有多少个controler,只需要初始化一次即可)
[root@ct ~]# su -s /bin/sh -c "glance-manage db_sync" glance
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
/usr/lib/python2.7/site-packages/pymysql/cursors.py:170: Warning: (1280, u"Name 'alembic_version_pkc' ignored for PRIMARY key.")
.
.
.
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Database is synced successfully.
2.6、开启glance服务和查看端口
此处开启之后会生成存放镜像的目录/var/lib/glance/image
[root@ct ~]# 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 ~]# systemctl start openstack-glance-api.service //开启glance-api
[root@ct ~]# netstat -anpt | grep 9292 //查看端口 (也可以使用lsof -i:9292 )
tcp 0 0 0.0.0.0:9292 0.0.0.0:* LISTEN 17703/python2
2.7、授权
赋予openstack-glance-api.service服务对存储设备的可写权限(-h:值对符号连接/软链接的文件修改)
[root@ct ~]# chown -hR glance:glance /var/lib/glance/
2.8、镜像导入
先上传cirros镜像到控制节点的/root,然后导入glance,最后查看是否创建成功
导入cirros-0.3.5-x86_64-disk.img镜像
[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 | 2021-02-22T06:59:58Z |
| disk_format | qcow2 |
| file | /v2/images/8d14e463-c30b-4677-9d52-82a1e830214b/file |
| id | 8d14e463-c30b-4677-9d52-82a1e830214b |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 66751330acbc40178f9983cfabaf66ed |
| 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 | 2021-02-22T06:59:58Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2.9、查看镜像的两种方式
[root@ct ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 8d14e463-c30b-4677-9d52-82a1e830214b | cirros | active |
+--------------------------------------+--------+--------+
[root@ct ~]# glance image-list
+--------------------------------------+--------+
| ID | Name |
+--------------------------------------+--------+
| 8d14e463-c30b-4677-9d52-82a1e830214b | cirros |
+--------------------------------------+--------+
小结
因为OpenStack上创建虚拟机需要镜像支持,所以先行进行部署
部署思路:
1、创建数据库、授权
2、创建openstack用户、授权、管理
3、修改配置文件(glance-api.conf、glance-registry.conf)
4、初始化数据库、上传实例镜像