这是搭建Openstack云平台的第四堂课,主要讲解镜像服务glance的配置过程。Glance负责管理Openstack中所有镜像,这是创建虚拟机的基本服务,因此也需要优先完成配置。
创建数据库用户
mysql -uroot -pMariadb123
create database glance; grant all privileges on glance.* to 'glance'@'localhost' identified by 'Glance123'; grant all privileges on glance.* to 'glance'@'%' identified by 'Glance123'; flush privileges; exit
配置glance服务凭证
创建glance服务凭证
# source /opt/scripts/admin # 开始创建用户 openstack user create \ --domain default \ --password-prompt glance
输入密码(Glance123)后继续:
openstack role add \ --project service \ --user glance admin openstack service create \ --name glance \ --description "OpenStack Image" image
创建endpoint
openstack endpoint create \ --region RegionOne image public http://controller:9292 openstack endpoint create \ --region RegionOne image internal http://controller:9292 openstack endpoint create \ --region RegionOne image admin http://controller:9292
配置控制节点上的镜像服务
安装glance
yum -y install openstack-glance
配置 glance api
修改配置/etc/glance/glance-api.conf:
[DEFAULT] bind_host = 10.10.100.150 enable_v1_api = False [database] connection = mysql+pymysql://glance:Glance123@controller/glance [glance_store] stores = file,http default_store = file filesystem_store_datadir = /var/lib/glance/images/ #以下是使用ceph存储的配置,使用ceph时删除cinder参数 #stores = glance.store.rbd.Store #default_store = rbd #rbd_store_pool = images #rbd_store_user = glance #ceph_conf = /etc/ceph/ceph.conf [keystone_authtoken] auth_uri = http://controller:5000 auth_url = http://controller:35357 memcached_servers = controller:11211 auth_type = password project_domain_name = Default user_domain_name = Default project_name = service username = glance password = Glance123 [paste_deploy] flavor = keystone
注意:如果要迁移镜像目录,例如/data/glance/images,需要对该目录授权:
chown -R glance:nobody /data/glance/images
配置 glance registry
修改配置/etc/glance/glance-registry.conf:
[DEFAULT] bind_host = 10.10.100.150 [database] connection = mysql+pymysql://glance:Glance123@controller/glance [keystone_authtoken] auth_uri = http://controller:5000 auth_url = http://controller:35357 memcached_servers = controller:11211 auth_type = password project_domain_name = Default user_domain_name = Default project_name = service username = glance password = Glance123 [paste_deploy] flavor = keystone
初始化数据
su -s /bin/sh -c "glance-manage db_sync" glance
启动应用
systemctl enable openstack-glance-api openstack-glance-registry systemctl start openstack-glance-api openstack-glance-registry
验证结果
现在可以登录web界面上传镜像,或先下载一个镜像至glance目录,然后执行以下命令:
openstack image create "CentOS7.5" \ --file CentOS-7-x86_64-DVD-1804.iso \ --disk-format qcow2 --container-format bare \ --public
常用镜像操作命令:
openstack image list glance image-list openstack image delete <image_id> glance image-delete <image_name>
原创文章禁止转载:技术学堂 » Openstack云平台搭建课程四·镜像服务Glance