OpenStack-Glance组件部署

一、创建数据库实例和数据库用户

 mysql -u root -p123456
 create database glance;
grant all privileges on glance.* to 'glance'@'%' identified by 'glance_dbpass';
grant all privileges on glance.* to 'glance'@'localhost' identified by 'glance_dbpass';pass';
flush privileges;
exit;

二、创建用户、修改配置文件

创建OpenStack的Glance用户

创建用户前,需要首先执行管理员环境变量脚本(此处已经在~/.bashrc 中定义过了)

  1. 创建glance用户
openstack user create --domain default --password glance_pass glance
  1. 将glance用户添加到service项目中,并且针对这个项目拥有admin权限;注册glance的API,需要对service项目有admin权限
openstack role add --project service --user glance admin
  1. 创建一个service服务,service名称为glance,类型为image;
openstack service create --name glance --description "OpenStack Image" image

  1. 创建完成后可以通过 openstack service list 查看
    OpenStack-Glance组件部署_第1张图片

创建镜像服务 API 端点

OpenStack使用三种API端点代表三种服务:admin、internal、public

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

安装 openstack-glance 软件包

yum -y install openstack-glance 

修改glance配置文件

glance有两个配置文件:
/etc/glance/glance-api.conf
/etc/glance/glance-registry.conf

cp -a /etc/glance/glance-api.conf{,.bak}
grep -Ev '^$|#' /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf
cp -a /etc/glance/glance-registry.conf{,.bak}

添加glance-api.conf配置

openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:glance_dbpass@controller/glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://controller:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://controller:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers controller:11211
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password glance_pass
openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/

修改glance-registry.conf 配置文件

openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:glance_dbpass@controller/glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct:11211
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password glance_pass
openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/
openstack-config --set /etc/glance/glance-registry.conf database connection  mysql+pymysql://glance:glance_dbpass@controller/glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri   http://controller:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url  http://ct:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers controller:11211
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type  password
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name  Default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name  Default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name  service
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username  glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password glance_pass
openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor  keystone

初始化glance数据库,生成相关表结构;

不管有多少个controler,只需要初始化一次即可

su -s /bin/sh -c "glance-manage db_sync" glance

开启glance服务

此处开启之后会生成存放镜像的目录/var/lib/glance/image

systemctl enable openstack-glance-api.service
systemctl start openstack-glance-api.service

查看端口(也可以使用lsof -i:9292 )

netstat -natp | grep 9292

赋予openstack-glance-api.service服务对存储设备的可写权限

-h:值对符号连接/软链接的文件修改

chown -hR glance:glance /var/lib/glance/

三 、镜像导入

先上传cirros镜像到控制节点的/root,然后导入glance

openstack image create --file cirros-0.3.5-x86_64-disk.img --disk-format qcow2 --container-format bare --public cirros

查看是否创建成功

  1. 法一:
openstack image list

OpenStack-Glance组件部署_第2张图片
2. 法二:

glance image-list

OpenStack-Glance组件部署_第3张图片

小结

因为OpenStack上创建虚拟机需要镜像支持,所以先行进行部署;
部署思路:
1、创建数据库、授权;
2、创建openstack用户、授权、管理;
3、修改配置文件(glance-api.conf、glance-registry.conf);
4、初始化数据库、上传实例镜像

你可能感兴趣的:(openstack)