OpenStack实践系列③镜像服务Glance
3.5 Glance部署
修改glance-api和glance-registry的配置文件,同步数据库
[root@node1 ~]# vim /etc/glance/glance-api.conf
connection=mysql://glance:glance@192.168.3.199/glance [root@node1 ~]# vim /etc/glance/glance-registry.conf
connection=mysql://glance:glance@192.168.3.199/glance [root@node1 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
No handlers could be found for logger "oslo_config.cfg"
/usr/lib64/python2./site-packages/sqlalchemy/engine/default.py:: Warning: Duplicate index `ix_image_properties_image_id_name`. This is deprecated and will be disallowed in a future release.
cursor.execute(statement, parameters)(可以忽略)
检查导入glance库的表情况
[root@node1 httpd]# mysql -h192.168.3. -uglance -pglance
MariaDB [(none)]> use glance
Database changed
MariaDB [glance]> show tables;
+----------------------------------+
| Tables_in_glance |
+----------------------------------+
| artifact_blob_locations |
| artifact_blobs |
| artifact_dependencies |
| artifact_properties |
| artifact_tags |
| artifacts |
| 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 |
+----------------------------------+
rows in set (0.00 sec)
配置glance连接keystone,对于keystone,每个服务都要有一个用户连接keystone
[root@node1 ~]# source admin-openrc.sh
[root@node1 ~]# openstack user create --domain default --password=glance glance
+-----------+----------------------------------+
| Field | Value |
+-----------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | 8f1bc013d4f04784886c852cd678e756 |
| name | glance |
+-----------+----------------------------------+
[root@node1 ~]# openstack role add --project service --user glance admin
修改glance-api配置文件,结合keystone和mysql
# vim /etc/glance/glance-api.conf
[keystone_authtoken] 部分加入如下配置:
auth_uri = http://192.168.3.199:5000
auth_url = http://192.168.3.199:35357
memcached_servers = 192.168.3.199:
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = glance
password = glance
[paste_deploy] 部分修改:
flavor=keystone
[default] 部分修改:
notification_driver = noop # 镜像服务不需要使用消息队列
verbose=True # 打开debug
[glance_store] 部分:
default_store=file # 镜像存放成文件
filesystem_store_datadir=/var/lib/glance/images/ # 镜像存放位置
编辑/etc/glance/glance-registry.conf文件,并完成以下操作:
verbose=True
notification_driver = noop
在[database]部分中,配置数据库访问
[database]
...
connection=mysql://glance:glance@192.168.3.199/glance
在[keystone_authtoken]和[paste_deploy]部分,配置认证服务访问
[keystone_authtoken]
...
auth_uri = http://192.168.3.199:5000
auth_url = http://192.168.3.199:35357
memcached_servers = 192.168.3.199:
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = glance
password = glance
[paste_deploy]
...
flavor = keystone
检查glance修改过的配置
[root@node1 ~]# grep -n '^[a-z]' /etc/glance/glance-api.conf
:verbose=True
:notification_driver = noop
:connection=mysql://glance:glance@192.168.3.199/glance
:default_store=file
:filesystem_store_datadir=/var/lib/glance/images/
:auth_uri = http://192.168.3.199:5000
:auth_url = http://192.168.3.199:35357
:memcached_servers = 192.168.3.199:
:auth_plugin = password
:project_domain_id = default
:user_domain_id = default
:project_name = service
:username = glance
:password = glance
:flavor=keystone
[root@node1 ~]# grep -n '^[a-z]' /etc/glance/glance-registry.conf
:verbose=True
:notification_driver = noop
:connection=mysql://glance:glance@192.168.3.199/glance
:auth_uri = http://192.168.3.199:5000
:auth_url = http://192.168.3.199:35357
:memcached_servers = 192.168.3.199:
:auth_plugin = password
:project_domain_id = default
:user_domain_id = default
:project_name = service
:username = glance
:password = glance
:flavor=keystone
对glance设置开机启动并启动glance服务
[root@node1 glance]# systemctl enable openstack-glance-api
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service.
[root@node1 glance]# systemctl enable openstack-glance-registry
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service to /usr/lib/systemd/system/openstack-glance-registry.service.
[root@node1 glance]# systemctl start openstack-glance-api
[root@node1 glance]# systemctl start openstack-glance-registry
查看galnce占用端口情况,其中9191是registry占用端口,9292是api占用端口
[root@node1 glance]# netstat -lntup | egrep '9191|9292'
tcp 0.0.0.0: 0.0.0.0:* LISTEN /python2
tcp 0.0.0.0: 0.0.0.0:* LISTEN /python2
让glance服务在keystone上注册,才可以允许其他服务调用glance
[root@node1 ~]# source admin-openrc.sh
[root@node1 ~]# openstack service create --name glance --description "OpenStack Image service" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image service |
| enabled | True |
| id | 7e931b709a444c13bac5611fb19b9a05 |
| name | glance |
| type | image |
+-------------+----------------------------------+ [root@node1 ~]# openstack endpoint create --region RegionOne image public http://192.168.3.199:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 4ea9ed1557dc4e548c76cdf0f3d4fbdc |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 7e931b709a444c13bac5611fb19b9a05 |
| service_name | glance |
| service_type | image |
| url | http://192.168.3.199:9292 |
+--------------+----------------------------------+ [root@node1 ~]# openstack endpoint create --region RegionOne image internal http://192.168.3.199:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | cef79d1f235c4fbe9eb2679c101edc15 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 7e931b709a444c13bac5611fb19b9a05 |
| service_name | glance |
| service_type | image |
| url | http://192.168.3.199:9292 |
+--------------+----------------------------------+ [root@node1 ~]# openstack endpoint create --region RegionOne image admin http://192.168.3.199:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | b8012edc462a4d82b68b6a138b47cc94 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 7e931b709a444c13bac5611fb19b9a05 |
| service_name | glance |
| service_type | image |
| url | http://192.168.3.199:9292 |
+--------------+----------------------------------+
在admin和demo中加入glance的环境变量,告诉其他服务glance使用的环境变量,一定要在admin-openrc.sh的路径下执行
[root@node1 ~]# echo "export OS_IMAGE_API_VERSION=2" | tee -a admin-openrc.sh demo-openrc.sh
export OS_IMAGE_API_VERSION=
[root@node1 ~]# tail - admin-openrc.sh
export OS_IMAGE_API_VERSION=
[root@node1 ~]# tail - demo-openrc.sh
export OS_IMAGE_API_VERSION=
报错记录:
[root@node1 ~]# openstack service create --name glance --description "OpenStack Image service" image
An unexpected error prevented the server from fulfilling your request. (HTTP 500) (Request-ID: req-323c5997-7c34-418e-af7b-8dbb4f4fdd0f)
解决办法:
重启keystone相关服务即可
[root@node1 ~]# systemctl restart httpd.service
[root@node1 ~]# systemctl restart memcached.service
如果出现以下情况,表示glance配置成功,由于没有镜像,所以看不到
[root@node1 ~]# glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
验证Glance服务操作
使用CirrOS,一个很小的Linux镜像,可以帮助测试OpenStack部署镜像服务是否正常下载一个镜像,上传镜像到glance,要在上一步所下载的镜像当前目录执行
[root@node1 ~]# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
将图像上传至使用QCOW2磁盘格式,因此所有的项目都可以访问它的服务
[root@node1 ~]# glance image-create --name "cirros" --file cirros-0.3.-x86_64-disk.img --disk-format qcow2 --container-format bare --visibility public --progress
[=============================>] %
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | ee1eca47dc88f4879d8a229cc70a07c6 |
| container_format | bare |
| created_at | --26T02::15Z |
| disk_format | qcow2 |
| id | 447ef14f-5ab2-4a69-af46-cf4331f45967 |
| min_disk | |
| min_ram | |
| name | cirros |
| owner | 7340dd86a8b14e73ac36b6d6385c689c |
| protected | False |
| size | |
| status | active |
| tags | [] |
| updated_at | --26T02::15Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------+
查看上传镜像
[root@node1 ~]# glance image-list
+--------------------------------------+--------+
| ID | Name |
+--------------------------------------+--------+
| 447ef14f-5ab2-4a69-af46-cf4331f45967 | cirros |
+--------------------------------------+--------+
[root@node1 ~]# cd /var/lib/glance/images/
[root@node1 images]# ls
447ef14f-5ab2-4a69-af46-cf4331f45967 (和image-list中的id一致)