配置glance使用NFS后端

时间:2021-12-25 06:22:25

首先先使用“glance image-delete”命令删除所有镜像,释放磁盘空间。

停止glance服务:
service openstack-glance-api stop
service openstack-glance-registry stop

停止swift服务:
service openstack-swift-proxy stop
service openstack-swift-account stop
service openstack-swift-account-auditor stop
service openstack-swift-account-reaper stop
service openstack-swift-account-replicator stop
service openstack-swift-container stop
service openstack-swift-container-auditor stop
service openstack-swift-container-replicator stop
service openstack-swift-container-updater stop
service openstack-swift-object stop
service openstack-swift-object-auditor stop
service openstack-swift-object-replicator stop
service openstack-swift-object-updater stop

禁用swift服务:
chkconfig openstack-swift-proxy off
chkconfig openstack-swift-account off
chkconfig openstack-swift-account-auditor off
chkconfig openstack-swift-account-reaper off
chkconfig openstack-swift-account-replicator off
chkconfig openstack-swift-container off
chkconfig openstack-swift-container-auditor off
chkconfig openstack-swift-container-replicator off
chkconfig openstack-swift-container-updater off
chkconfig openstack-swift-object off
chkconfig openstack-swift-object-auditor off
chkconfig openstack-swift-object-replicator off
chkconfig openstack-swift-object-updater off

备份glance配置文件:
cp -a /etc/glance/glance-api.conf /etc/glance/glance-api.conf.bak
cat /etc/glance/glance-api.conf.bak|grep -v '#'|grep -v '^$'>/etc/glance/glance-api.conf

[glance_store]
stores=glance.store.swift.Store,glance.store.http.Store
swift_store_auth_version=2
swift_store_auth_address=http://168.5.23.2:5000/v2.0/
swift_store_user=services:glance
swift_store_key=bF5x7NId
swift_store_container=glance
swift_store_create_container_on_put=True
swift_store_large_object_size=5120
default_store=swift
swift_store_endpoint_type=internalURL
改为:
[glance_store]
default_store=file
filesystem_store_datadir=/var/lib/glance/images

卸载挂载点并授权:
umount /var/lib/glance
rm -rf /var/lib/glance/*
mkdir -p /var/lib/glance/images
chown -R glance:glance /var/lib/glance

挂载NFS:
mount 168.5.22.100:/images /var/lib/glance/images
chown -R glance:glance /var/lib/glance/images
chmod 755 /var/lib/glance/images

修改fstab文件:
vi /etc/fstab
UUID=bb4264a8-3eb0-4ac1-93a2-0ef17821c40a /var/lib/glance xfs defaults 0 0
改为:
168.5.22.100:/images /var/lib/glance/images nfs defaults 0 0

查看glance用户密码:
cat /etc/glance/glance-api.conf|grep sql_connection
sql_connection=mysql://glance:6caYCZH8@168.5.23.2/glance?read_timeout=60
密码是:6caYCZH8

在任一节点重建数据库:
mysql -h 168.5.23.2 -u glance -p -e 'drop database glance;'
mysql -h 168.5.23.2 -u glance -p -e 'create database glance;'
su -s /bin/sh -c "glance-manage db sync" glance

在任一节点:
source openrc
keystone endpoint-delete 41dca7df60244d7a8b509e019560c1d9
keystone service-delete b7409203b63348d9acefe5463e3880e3

启动glance服务:
service openstack-glance-api start
service openstack-glance-registry start

测试上传镜像:
glance image-create --name "TestVM" --file /root/TestVM.img --disk-format qcow2 --container-format bare --is-public True --progress