glance架构图:
glance架构:
由图可看到glance由三部分组成glance-api、glance-registry,db 1.glance-api是后台运行的进程,对外提供RESTAPI,响应image查询获取和存储的调用,glance-api不会真正的处理请求,端口是9292 2.glance-registry是后台运行的服务进程,负责处理和存储Image的metadata,例如image的大小和类型,这部分数据是存在DB中的。端口是9191 3.DB存储着Image的metadata信息,默认是mysql,端口是3306
配置:
#修改glance-api.conf和 glance-registry.conf配置文件 [root@master1 ~]# egrep -v "^$|^[#|[]" /etc/glance/glance-api.conf connection = mysql+pymysql://glance:glance@192.168.142.166/glance ##连接数据库部分 stores = file,http ##指定镜像存储方式和位置 default_store = file filesystem_store_datadir = /var/lib/glance/images/ auth_uri = http://192.168.142.166:5000 ##配置keystone auth_url = http://192.168.142.166:35357 memcached_servers = 192.168.142.166:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = glance flavor = keystone [root@master1 ~]# egrep -v "^$|^[#|[]" /etc/glance/glance-registry.conf connection = mysql+pymysql://glance:glance@192.168.142.166/glance auth_uri = http://192.168.142.166:5000 auth_url = http://192.168.142.166:35357 memcached_servers = 192.168.142.166:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = glance flavor = keystone #同步数据库 su -s /bin/sh -c "glance-manage db_sync" glance #验证 [root@master1 ~]# mysql -uglance -pglance -e "use 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 | +----------------------------------+
启动和开机自启动:
#设置开机启动并启动服务 [root@master1 ~]# 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@master1 ~]# systemctl enable openstack-glance-registry.service Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service to /usr/lib/systemd/system/openstack-glance-registry.service. [root@master1 ~]# systemctl start openstack-glance-api.service [root@master1 ~]# systemctl start openstack-glance-registry.service [root@master1 ~]# netstat -tulnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 192.168.142.166:3306 0.0.0.0:* LISTEN 2047/mysqld tcp 0 0 0.0.0.0:9292 0.0.0.0:* LISTEN 27891/python2 tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1521/sshd tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 919/beam tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2264/master tcp 0 0 0.0.0.0:9191 0.0.0.0:* LISTEN 27908/python2 tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 919/beam tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 924/httpd tcp6 0 0 :::22 :::* LISTEN 1521/sshd tcp6 0 0 ::1:25 :::* LISTEN 2264/master tcp6 0 0 :::35357 :::* LISTEN 924/httpd tcp6 0 0 :::5672 :::* LISTEN 919/beam tcp6 0 0 :::5000 :::* LISTEN 924/httpd udp 0 0 127.0.0.1:323 0.0.0.0:* 644/chronyd udp 0 0 0.0.0.0:47474 0.0.0.0:* 714/dhclient udp 0 0 0.0.0.0:68 0.0.0.0:* 714/dhclient udp6 0 0 :::31455 :::* 714/dhclient udp6 0 0 ::1:323 :::* 644/chronyd
#创建glance的service和endpoint [root@master1 ~]# openstack service create --name glance --description "Openstack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | Openstack Image | | enabled | True | | id | 5afa06c614ae49d490ed75df9557ca83 | | name | glance | | type | image | +-------------+----------------------------------+ [root@master1 ~]# openstack service list +----------------------------------+----------+----------+ | ID | Name | Type | +----------------------------------+----------+----------+ | 1677633e96b94161a265154f1412800b | keystone | identity | | 5afa06c614ae49d490ed75df9557ca83 | glance | image | +----------------------------------+----------+----------+ [root@master1 ~]# openstack endpoint create --region RegionOne image public http://192.168.142.166:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | f31a37215ffa4d0190e5144f82b16697 | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | 5afa06c614ae49d490ed75df9557ca83 | | service_name | glance | | service_type | image | | url | http://192.168.142.166:9292 | +--------------+----------------------------------+ [root@master1 ~]# openstack endpoint create --region RegionOne image internal http://192.168.142.166:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 8d6c17e786ad47b2835a0e8b2056d957 | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | 5afa06c614ae49d490ed75df9557ca83 | | service_name | glance | | service_type | image | | url | http://192.168.142.166:9292 | +--------------+----------------------------------+ [root@master1 ~]# openstack endpoint create --region RegionOne image admin http://192.168.142.166:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | b1767ca08bb744ad937048113d0ce8d7 | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | 5afa06c614ae49d490ed75df9557ca83 | | service_name | glance | | service_type | image | | url | http://192.168.142.166:9292 | +--------------+----------------------------------+ [root@master1 ~]# openstack endpoint list +----------------------------------+-----------+--------------+--------------+---------+-----------+---------------------------------+ | ID | Region | Service Name | Service Type | Enabled | Interface | URL | +----------------------------------+-----------+--------------+--------------+---------+-----------+---------------------------------+ | 123331222f2642858293d16952da34f8 | RegionOne | keystone | identity | True | admin | http://192.168.142.166:35357/v3 | | 506f61f1ced645ac86a17d9ac5825bf8 | RegionOne | keystone | identity | True | public | http://192.168.142.166:5000/v3 | | 8d6c17e786ad47b2835a0e8b2056d957 | RegionOne | glance | image | True | internal | http://192.168.142.166:9292 | | b1767ca08bb744ad937048113d0ce8d7 | RegionOne | glance | image | True | admin | http://192.168.142.166:9292 | | d5a953110c4049a4ac9f0b338d5d7145 | RegionOne | keystone | identity | True | internal | http://192.168.142.166:5000/v3 | | f31a37215ffa4d0190e5144f82b16697 | RegionOne | glance | image | True | public | http://192.168.142.166:9292 | +----------------------------------+-----------+--------------+--------------+---------+-----------+---------------------------------+ [root@master1 ~]# ls admin.sh anaconda-ks.cfg checkUrl.sh pstack.sh [root@master1 ~]# openstack image list [root@master1 ~]# glance image-list +----+------+ | ID | Name | +----+------+ +----+------+
上传镜像:
[root@master1 ~]# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img --2017-07-11 14:25:41-- http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img 正在解析主机 download.cirros-cloud.net (download.cirros-cloud.net)... 64.90.42.85, 2607:f298:6:a036::bd6:a72a 正在连接 download.cirros-cloud.net (download.cirros-cloud.net)|64.90.42.85|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:13287936 (13M) [text/plain] 正在保存至: “cirros-0.3.4-x86_64-disk.img” 100%[===============================================================================================================================>] 13,287,936 840KB/s 用时 61s 2017-07-11 14:26:44 (211 KB/s) - 已保存 “cirros-0.3.4-x86_64-disk.img” [13287936/13287936]) [root@master1 ~]# openstack image create "cirros" > --file cirros-0.3.4-x86_64-disk.img > --disk-format qcow2 --container-format bare > --public +------------------+------------------------------------------------------+ | Field | Value | +------------------+------------------------------------------------------+ | checksum | ee1eca47dc88f4879d8a229cc70a07c6 | | container_format | bare | | created_at | 2017-07-11T06:27:47Z | | disk_format | qcow2 | | file | /v2/images/af67976a-92ea-4d08-8296-86cb76e3954b/file | | id | af67976a-92ea-4d08-8296-86cb76e3954b | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | 3e83baa0b3d64188b036ce423002aac7 | | protected | False | | schema | /v2/schemas/image | | size | 13287936 | | status | active | | tags | | | updated_at | 2017-07-11T06:27:49Z | | virtual_size | None | | visibility | public | +------------------+------------------------------------------------------+ [root@master1 ~]# openstack image list +--------------------------------------+--------+--------+ | ID | Name | Status | +--------------------------------------+--------+--------+ | af67976a-92ea-4d08-8296-86cb76e3954b | cirros | active | +--------------------------------------+--------+--------+
glance常用命令
[root@master1 ~]# glance image-list +--------------------------------------+--------+ | ID | Name | +--------------------------------------+--------+ | 1b5bb43d-1589-46c0-8d86-b2868c840fdf | | | af67976a-92ea-4d08-8296-86cb76e3954b | cirros | +--------------------------------------+--------+
[root@master1 ~]# glance image-show af67976a-92ea-4d08-8296-86cb76e3954b #af...4b 是image-id +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | ee1eca47dc88f4879d8a229cc70a07c6 | | container_format | bare | | created_at | 2017-07-11T06:27:47Z | | disk_format | qcow2 | | id | af67976a-92ea-4d08-8296-86cb76e3954b | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | 3e83baa0b3d64188b036ce423002aac7 | | protected | False | | size | 13287936 | | status | active | | tags | [] | | updated_at | 2017-07-11T06:27:49Z | | virtual_size | None | | visibility | public | +------------------+--------------------------------------+
[root@master1 ~]# glance image-create +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | None | | container_format | None | | created_at | 2017-07-15T05:34:10Z | | disk_format | None | | id | 1b5bb43d-1589-46c0-8d86-b2868c840fdf | | min_disk | 0 | | min_ram | 0 | | name | None | | owner | 3e83baa0b3d64188b036ce423002aac7 | | protected | False | | size | None | | status | queued | | tags | [] | | updated_at | 2017-07-15T05:34:10Z | | virtual_size | None | | visibility | private | +------------------+--------------------------------------+
[root@master1 ~]# glance image-delete 1b5bb43d-1589-46c0-8d86-b2868c840fdf
glance遇到问题如何troubleshooting
01.开启debug
[root@master1 log]# grep "debug" /etc/glance/glance-api.conf # The hostname/IP of the pydev process listening for debug connections #pydev_worker_debug_host = <None> #pydev_worker_debug_port = 5678 #debug = false #设置为true即可 #logging_debug_format_suffix = %(funcName)s %(pathname)s:%(lineno)d # Verbosity of SQL debugging information: 0=None, 100=Everything. # Deprecated group/name - [DEFAULT]/sql_connection_debug #connection_debug = 0
02.查看/var/log/glance目录下的日志