以下操作均在控制节点(Controller)中执行
1. 创建glance用户
openstack user create --domain default --project service --password 123456 glance
2. 赋予 glance 用户 admin 权限
openstack role add --project service --user glance admin
3. 创建glance服务
openstack service create --name glance --description "OpenStack Image service" image
4. 定义 controller 管理网 IP
export controller=10.1.1.11
5. 创建 public 的 endpoint
openstack endpoint create --region RegionOne image public http://$controller:9292
6. 创建 internal 的 endpoint
openstack endpoint create --region RegionOne image internal http://$controller:9292
7. 创建 admin 的 endpoint
openstack endpoint create --region RegionOne image admin http://$controller:9292
8. 创建数据库
mysql -uroot -p123456
连接进数据库后进行操作:
MariaDB [(none)]> create database glance;
MariaDB [(none)]> grant all privileges on glance.* to glance@'localhost' identified by '123456';
MariaDB [(none)]> grant all privileges on glance.* to glance@'%' identified by '123456';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
Bye
9. 安装软件包
yum -y install openstack-glance
10. 修改配置文件glance-api.conf
将原来的配置文件名称修改,以做备份。
mv /etc/glance/glance-api.conf /etc/glance/glance-api.conf.org
新建一个配置文件并编辑
vim /etc/glance/glance-api.conf
添加进以下内容:
[DEFAULT]
bind_host = 0.0.0.0
notification_driver = noop
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
[database]
connection = mysql+pymysql://glance:123456@10.1.1.11/glance
[keystone_authtoken]
auth_uri = http://10.1.1.11:5000
auth_url = http://10.1.1.11:35357
memcached_servers = 10.1.1.11:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = 123456
[paste_deploy]
flavor = keystone
11. 修改配置文件glance-registry.conf
将原来的配置文件名称修改,以做备份。
mv /etc/glance/glance-registry.conf /etc/glance/glance-registry.conf.org
新建一个配置文件并编辑
vim /etc/glance/glance-registry.conf
添加进以下内容:
[DEFAULT]
bind_host = 0.0.0.0
notification_driver = noop
[database]
connection = mysql+pymysql://glance:123456@10.1.1.11/glance
[keystone_authtoken]
auth_uri = http://10.1.1.11:5000
auth_url = http://10.1.1.11:35357
memcached_servers = 10.1.1.11:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = 123456
[paste_deploy]
flavor = keystone
12. 修改文件权限
chmod 640 /etc/glance/glance-api.conf /etc/glance/glance-registry.conf
chown root:glance /etc/glance/glance-api.conf /etc/glance/glance-registry.conf
13. 创建数据库表结构
su -s /bin/bash glance -c "glance-manage db_sync"
14. 启动服务并设置开机启动
systemctl start openstack-glance-api openstack-glance-registry
systemctl enable openstack-glance-api openstack-glance-registry
验证
1. 引用环境变量
source ~/keystonerc
2. 下载镜像(下载到当前目录)
wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
3. 加载镜像
openstack image create "cirros" \
--file cirros-0.3.4-x86_64-disk.img \
--disk-format qcow2 --container-format bare \
--public
示例结果
其它镜像(根据个人需要)
下载镜像
wget http://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P /var/kvm/images
加载镜像
openstack image create "Ubuntu1604" --file /var/kvm/images/ubuntu-16.04-servercloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare --public
4. 查看镜像
openstack image list