使用场景
openstack的region,通常对应地域或地区。例如,北京,上海,深圳的机房各自部署一套openstack系统。在没有region概念的时候,处于不同地理位置的openstack系统可以独立运行,也只能独立运行。从系统运行的角度,让系统保持独立有好处,例如每个系统的规模较小;各系统互不干扰,没有资源依赖;各种资源都在本地获取,使得代价低,性能最优,等等。所以独立运行是合理和自然的方式。不过,从系统管理的角度,管理员仍然希望有一个集中管理的位置,可以监控和操作所有的系统。例如,在一个管理界面上,创建位于不同地域的虚拟机实例。多region平衡了系统运行需求和管理需求。
基本原理
一个openstack系统由多个服务组成,服务之间相对独立又有一定依赖关系。基本的服务有认证服务keystone,镜像服务glance,存储服务cinder,网络服务neutron,计算服务nova等。keystone服务是一个基础服务,其他服务运行需要首先经过keystone认证。在keystone的概念体系中,除了用户,角色之外,还定义了endpoint,即端点。每个端点是一个服务URL引用。各种外部的客户端如何访问openstack服务?用户在经过keystone认证之后,根据服务端点信息,向服务发起REST API调用。openstack的每一种服务也需要在keystone中认证自己。服务通过在配置文件中定义keystone认证URL,用户名,密码,记录所需信息。在keystone支持region之后,允许每一个region定义自己的一套服务端点,包括keystone,glance,cinder,neutron,nova等。通过在一个keystone中定义不同的region,实现对不同区域openstack系统的管理。
多region方案
实现多region,基本思路是keystone服务共用一个,其他服务不变。不同region共用一个keystone服务,只要涉及到访问keystone,都指向同一个keystone端点。其他服务的端点不变,保证对存储,计算资源的访问仍然保留在region本地。
试验环境
两套独立的openstack系统。
第一个系统的控制节点 10.10.44.6 tnhost-44-6
第二个系统的控制节点 10.10.44.7 tnhost-44-7
keystone服务运行在控制节点上。
为了实现多region,这里的方案是,将第二个openstack系统的keystone认证端点,修改为指向第一个openstack系统的keystone服务。
除了两套系统共用一个keystone服务,其他的服务保持各自独立。
第二个系统放在一个新的region分区regionTwo。
注意:在packstack应答文件中有两类密码。
1. keystone用户密码。
packstack的CONFIG_KEYSTONE_IDENTITY_BACKEND参数设置keystone用户密码保存在mysql或ldap。
例如neutron用户
# Password to use for OpenStack Networking (neutron) to authenticate with the Identity service.
CONFIG_NEUTRON_KS_PW=d462c5e7c5e74a18
用户有glance,neutron,nova,cinder,heat等。
2. mysql用户密码。
# The password to use for OpenStack Networking to access the database.
CONFIG_NEUTRON_DB_PW=56be9c96255a4ddd
用户有glance,neutron,nova,cinder,heat等。
操作过程
1.
修改
/etc/openstack-dashboard/local_settings。第二个系统的控制节点执行。
OPENSTACK_KEYSTONE_URL = "http://10.10.44.6:5000/v2.0"
重启apache。
# systemctl restart httpd
2. 修改 auth_uri identity_uri
auth_url。第二个系统的控制节点执行。
# find /etc/ -type f -exec sed -i '/^auth_ur[il][[:space:]]*=/s/10.10.44.7/10.10.44.6/' {} \;
# find /etc/ -type f -exec sed -i '/^identity_uri[[:space:]]*=/s/10.10.44.7/10.10.44.6/' {} \;
3. 设置环境变量。
第一个系统的控制节点执行。
设置newregion为新的region名称。设置ansfile为第一个openstack系统生成的packstack应答文件。
# controller1="10.10.44.6"
# controller2="10.10.44.7"
# newregion="regionTwo"
# ansfile="/root/ans-file.txt"
# CONFIG_NEUTRON_KS_PW=$(crudini --get ${ansfile} general CONFIG_NEUTRON_KS_PW); \
CONFIG_NOVA_KS_PW
=$(crudini --get ${ansfile} general CONFIG_NOVA_KS_PW); \
CONFIG_HEAT_KS_PW
=$(crudini --get ${ansfile} general CONFIG_HEAT_KS_PW); \
CONFIG_GLANCE_KS_PW
=$(crudini --get ${ansfile} general CONFIG_GLANCE_KS_PW); \
CONFIG_CINDER_KS_PW
=$(crudini --get ${ansfile} general CONFIG_CINDER_KS_PW)
# ssh ${controller2} " \
crudini --set /etc/neutron/neutron.conf keystone_authtoken admin_password ${CONFIG_NEUTRON_KS_PW}; \
crudini --set /etc/nova/nova.conf keystone_authtoken admin_password ${CONFIG_NOVA_KS_PW}; \
crudini --set /etc/heat/heat.conf keystone_authtoken admin_password ${CONFIG_HEAT_KS_PW}; \
crudini --set /etc/glance/glance-registry.conf keystone_authtoken admin_password ${CONFIG_GLANCE_KS_PW}; \
crudini --set /etc/glance/glance-api.conf keystone_authtoken admin_password ${CONFIG_GLANCE_KS_PW}; \
crudini --set /etc/cinder/cinder.conf keystone_authtoken admin_password ${CONFIG_CINDER_KS_PW}; \
crudini --set /etc/neutron/neutron.conf keystone_authtoken admin_password ${CONFIG_NEUTRON_KS_PW}; \
crudini --set /etc/neutron/api-paste.ini filter:authtoken admin_password ${CONFIG_NEUTRON_KS_PW}; \
crudini --set /etc/neutron/neutron.conf nova password ${CONFIG_NOVA_KS_PW}; \
crudini --set /etc/neutron/neutron.conf nova region_name ${newregion}; \
crudini --set /etc/nova/nova.conf neutron password ${CONFIG_NEUTRON_KS_PW}; \
crudini --set /etc/nova/nova.conf neutron region_name ${newregion}; \
crudini --set /etc/nova/nova.conf cinder os_region_name ${newregion}; \
crudini --set /etc/nova/nova.conf cinder endpoint_template
http://${controller2}:8776/v2/%(project_id)s;
\
"
5.
为新的region创建keystone endpoint。第一个系统的控制节点执行。
# keystone endpoint-create \
--service-id $(keystone service-list | awk '/ identity / {print $2}') \
--publicurl http://${controller1}:5000/v2.0 \
--internalurl http://${controller1}:5000/v2.0 \
--adminurl http://${controller1}:35357/v2.0 \
--region ${newregion}
# keystone endpoint-create \
--service-id $(keystone service-list | awk '/ image / {print $2}') \
--publicurl http://${controller2}:9292 \
--internalurl http://${controller2}:9292 \
--adminurl http://${controller2}:9292 \
--region ${newregion}
# keystone endpoint-create \
--service-id $(keystone service-list | awk '/ compute / {print $2}') \
--publicurl "http://${controller2}:8774/v2/%(tenant_id)s" \
--internalurl "http://${controller2}:8774/v2/%(tenant_id)s" \
--adminurl "http://${controller2}:8774/v2/%(tenant_id)s" \
--region ${newregion}
# keystone endpoint-create \
--service-id $(keystone service-list | awk '/
computev3 / {print $2}') \
--publicurl "http://${controller2}:8774/v3" \
--internalurl "http://${controller2}:8774/v3" \
--adminurl "http://${controller2}:8774/v3" \
--region ${newregion}
# keystone endpoint-create \
--service-id $(keystone service-list | awk '/ network / {print $2}') \
--publicurl http://${controller2}:9696 \
--adminurl http://${controller2}:9696 \
--internalurl http://${controller2}:9696 \
--region ${newregion}
## 如果是nova network不需要开network endpoint
# keystone endpoint-create \
--service-id $(keystone service-list | awk '/ volume / {print $2}') \
--publicurl "http://${controller2}:8776/v1/%(tenant_id)s" \
--internalurl "http://${controller2}:8776/v1/%(tenant_id)s" \
--adminurl "http://${controller2}:8776/v1/%(tenant_id)s" \
--region ${newregion}
# keystone endpoint-create \
--service-id $(keystone service-list | awk '/ volumev2 / {print $2}') \
--publicurl "http://${controller2}:8776/v2/%(tenant_id)s" \
--internalurl "http://${controller2}:8776/v2/%(tenant_id)s" \
--adminurl "http://${controller2}:8776/v2/%(tenant_id)s" \
--region ${newregion}
# keystone endpoint-create \
--service-id $(keystone service-list | awk '/ volumev3 / {print $2}') \
--publicurl "http://${controller2}:8776/v3/%(tenant_id)s" \
--internalurl "http://${controller2}:8776/v3/%(tenant_id)s" \
--adminurl "http://${controller2}:8776/v3/%(tenant_id)s" \
--region ${newregion}