官方文档:https://docs.openstack.org/ocata/install-guide-rdo/glance-install.html
Glance主要有两个重要的服务:
Glance-api:接受云系统镜像创建、删除、读取请求。Glance-Registry:云系统的镜像注册服务。 加载admin的环境变量:source /admin-openstack.shvim /admin-openstack.shexport OS_USERNAME=adminexport OS_PASSWORD=adminexport OS_PROJECT_NAME=adminexport OS_USER_DOMAIN_NAME=defaultexport OS_PROJECT_DOMAIN_NAME=defaultexport OS_AUTH_URL=http://192.168.2.11:35357/v3export OS_IDENTITY_API_VERSION=3export OS_IMAGE_API_VERSION=2注意:只要有用到openstack就要加载环境变量//创建glance用户(控制节点)
openstack user create --domain default --password-prompt glanceopenstack role add --project service --user glance admin
//安装glance服务组件(控制节点)yum install -y openstack-glance//编辑文件 /etc/glance/glance-api.conf 并完成如下动作(控制节点)
vim /etc/glance/glance-api.conf****************************************************[database]1823 connection = mysql+pymysql://glance:glance@192.168.2.11/glance
(打开注释并修改)
[keystone_authtoken] 3282 在这个模块下面添加如下
auth_uri = http://192.168.2.11:5000auth_url = http://192.168.2.11:35357memcached_servers = 192.168.2.11:11211auth_type = passwordproject_domain_name = defaultuser_domain_name = defaultproject_name = serviceusername = glancepassword = glance(添加内容)
4235 #flavor = keystone(打开注释)
[glance_store]
# ...stores = file,httpdefault_store = filefilesystem_store_datadir = /var/lib/glance/images/(添加内容)
//编辑文件 /etc/glance/glance-registry.conf 并完成如下动作(控制节点)vim /etc/glance/glance-registry.conf[database]1141 connection = mysql+pymysql://glance:glance@192.168.2.11/glance(打开注释并修改 )
[keystone_authtoken]
auth_uri = http://192.168.2.11:5000auth_url = http://192.168.2.11:35357memcached_servers = 192.168.2.11:11211auth_type = passwordproject_domain_name = defaultuser_domain_name = defaultproject_name = serviceusername = glancepassword = glance(添加内容)
2159 #flavor = keystone(打开注释)
同步glance数据库su -s /bin/sh -c "glance-manage db_sync" glance查看是否同步成功mysql -h 192.168.2.11 -uglance -pglance -e "use glance;show tables;"修改memcached的配置文件:vim /etc/sysconfig/memcached
PORT="11211"USER="memcached"MAXCONN="1024"CACHESIZE="64"OPTIONS="-l 192.168.2.11,::1"systemctl enable memcached
systemctl start memcached设置开机自启动并启动glance-api,glance-registry服务
systemctl enable openstack-glance-api.service openstack-glance-registry.servicesystemctl start openstack-glance-api.service openstack-glance-registry.service
注册:
openstack service create --name glance --description "OpenStack Image" image
[root@localhost log]# openstack service create --name glance \> --description "OpenStack Image" image+-------------+----------------------------------+| Field | Value |+-------------+----------------------------------+| description | OpenStack Image || enabled | True || id | 37c0c42ff7ab4629bb0309e6affe1316 || name | glance || type | image |+-------------+----------------------------------+
openstack endpoint create --region RegionOne image public http://192.168.2.11:9292
[root@localhost log]# openstack endpoint create --region RegionOne \> image public http://192.168.2.11:9292+--------------+----------------------------------+| Field | Value |+--------------+----------------------------------+| enabled | True || id | 07c702eebf5c485da26849e4a2094c72 || interface | public || region | RegionOne || region_id | RegionOne || service_id | 37c0c42ff7ab4629bb0309e6affe1316 || service_name | glance || service_type | image || url | http://192.168.2.11:9292 |+--------------+----------------------------------+
openstack endpoint create --region RegionOne image internal http://192.168.2.11:9292
[root@localhost log]# openstack endpoint create --region RegionOne image internal http://192.168.2.11:9292
+--------------+----------------------------------+| Field | Value |+--------------+----------------------------------+| enabled | True || id | 8d120557b1a644a0ab1762704717faff || interface | internal || region | RegionOne || region_id | RegionOne || service_id | 37c0c42ff7ab4629bb0309e6affe1316 || service_name | glance || service_type | image || url | http://192.168.2.11:9292 |+--------------+----------------------------------+
openstack endpoint create --region RegionOne image admin http://192.168.2.11:9292
[root@localhost log]# openstack endpoint create --region RegionOne image admin http://192.168.2.11:9292
+--------------+----------------------------------+| Field | Value |+--------------+----------------------------------+| enabled | True || id | a7cb98957cda4c0b86c9b0c0604def9a || interface | admin || region | RegionOne || region_id | RegionOne || service_id | 37c0c42ff7ab4629bb0309e6affe1316 || service_name | glance || service_type | image || url | http://192.168.2.11:9292 |+--------------+----------------------------------+[root@localhost log]# openstack endpoint list
+----------------------------------+-----------+--------------+--------------+---------+-----------+-------------------------------+| ID | Region | Service Name | Service Type | Enabled | Interface | URL |+----------------------------------+-----------+--------------+--------------+---------+-----------+-------------------------------+| 07c702eebf5c485da26849e4a2094c72 | RegionOne | glance | image | True | public | http://192.168.2.11:9292 || 09279edb612341f38f85884b2bfcdb78 | RegionOne | keystone | identity | True | public | http://19.168.2.11:5000/v3 || 09b6e07b2be943b59af2a87d7303215c | RegionOne | keystone | identity | True | internal | http://192.168.2.11:5000/v3 || 8d120557b1a644a0ab1762704717faff | RegionOne | glance | image | True | internal | http://192.168.2.11:9292 || a7cb98957cda4c0b86c9b0c0604def9a | RegionOne | glance | image | True | admin | http://192.168.2.11:9292 || ed2e3a4c9d9c43a9819ad2a49c058522 | RegionOne | keystone | identity | True | admin | http://192.168.2.11:35357/v3/ |+----------------------------------+-----------+--------------+--------------+---------+-----------+-------------------------------+验证是否正常
[root@localhost log]# openstack image list[root@localhost log]#
(没有报错就说明服务正常)wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
openstack image create "cirros" \
--file cirros-0.3.4-x86_64-disk.img \--disk-format qcow2 --container-format bare \--public [root@localhost log]# openstack image list+--------------------------------------+--------+--------+| ID | Name | Status |+--------------------------------------+--------+--------+| 958a9dd4-5eef-44f7-a0a0-c16b09227958 | cirros | active |+--------------------------------------+--------+--------+