了解 ImageStoreConnectionString 设置Understand the ImageStoreConnectionString setting

在某些文档中,我们简单提及存在“ImageStoreConnectionString”参数,但没有介绍它实际意味着什么。In some of our documentation, we briefly mention the existence of an "ImageStoreConnectionString" parameter without describing what it really means. 在阅读了使用 PowerShell 部署和删除应用程序之类的文章之后,你所要做的似乎就是复制/粘贴目标群集的群集清单中所示的值。And after going through an article like Deploy and remove applications using PowerShell, it looks like all you do is copy/paste the value as shown in the cluster manifest of the target cluster. 因此,每个群集的设置都必须是可配置的,但你通过 Azure 门户创建群集时,没有用于配置此设置的选项,它始终是“fabric:ImageStore”。So the setting must be configurable per cluster, but when you create a cluster through the Azure portal, there's no option to configure this setting and it's always "fabric:ImageStore". 那么,此设置的存在有何作用?What's the purpose of this setting then?

群集清单

Service Fabric 一开始被许多不同的团队用作 Azure 内部消耗平台,因此,其某些方面是高度可自定义的,“映像存储 (Image Store)”就是这样的存在。Service Fabric started off as a platform for internal Azure consumption by many diverse teams, so some aspects of it are highly customizable - the "Image Store" is one such aspect. 映像存储区实质上是用于存储应用程序包的可插入存储库。Essentially, the Image Store is a pluggable repository for storing application packages. 应用程序部署到群集中的节点时,该节点会从映像存储区下载应用程序包的内容。When your application is deployed to a node in the cluster, that node downloads the contents of your application package from the Image Store. ImageStoreConnectionString 是一项设置,它包含客户端和节点用于查找给定群集的正确映像存储区的所有必要信息。The ImageStoreConnectionString is a setting that includes all the necessary information for both clients and nodes to find the correct Image Store for a given cluster.

目前,有三种可能的映像存储区提供程序类型,这些类型及其对应的连接字符串如下所示:There are currently three possible kinds of Image Store providers and their corresponding connection strings are as follows:

  1. 映像存储区服务:“fabric:ImageStore”Image Store Service: "fabric:ImageStore"

  2. 文件系统:“file:[file system path]”File System: "file:[file system path]"

  3. Azure 存储:“xstore:DefaultEndpointsProtocol=https;AccountName=[...];AccountKey=[...];Container=[...];EndpointSuffix=core.chinacloudapi.cn”Azure Storage: "xstore:DefaultEndpointsProtocol=https;AccountName=[...];AccountKey=[...];Container=[...];EndpointSuffix=core.chinacloudapi.cn"

在生产中使用的提供程序类型为映像存储区服务,它是可通过 Service Fabric Explorer 查看的有状态持久化系统服务。The provider type used in production is the Image Store Service, which is a stateful persisted system service that you can see from Service Fabric Explorer.

映像存储区服务

在群集内的系统服务中托管映像存储区可清除包存储库的外部依赖项,并让我们能够更好地控制存储的位置。Hosting the Image Store in a system service within the cluster itself eliminates external dependencies for the package repository and gives us more control over the locality of storage. 将来的映像存储区增强功能就算没有专门针对映像存储区提供程序,也很可能以它为优先目标。Future improvements around the Image Store are likely to target the Image Store provider first, if not exclusively. 客户端已连接到目标群集,因此,映像存储区服务提供程序的连接字符串不具有任何唯一的信息。The connection string for the Image Store Service provider doesn't have any unique information since the client is already connected to the target cluster. 客户端只需知道应使用面向系统服务的协议即可。The client only needs to know that protocols targeting the system service should be used.

在开发过程中,本地单机群集使用文件系统提供程序,而不使用映像存储区服务,目的在于让群集的 bootstrap 操作速度略微提升。The File System provider is used instead of the Image Store Service for local one-box clusters during development to bootstrap the cluster slightly faster. 差异通常较小,但在开发期间,它对大多数人员而言是有用的优化。The difference is typically small, but it's a useful optimization for most folks during development. 尽管可部署其他存储提供程序类型的本地单机群集,但通常没有理由这么做,因为无论使用哪种提供程序,开发/测试工作流都保持不变。It's possible to deploy a local one-box cluster with the other storage provider types as well, but there's usually no reason to do so since the develop/test workflow remains the same regardless of provider. Azure 存储提供程序仅用于为在引入映像存储服务提供程序前部署的旧群集提供旧版支持。The Azure Storage provider only exists for legacy support of old clusters deployed before the Image Store Service provider was introduced.

此外,文件系统提供程序和 Azure 存储提供程序都不应用作在多个群集之间共享映像存储的方法 - 这会导致群集配置数据损坏,因为每个群集都可以将冲突数据写入到映像存储。Furthermore, not the File System provider or the Azure Storage provider should be used as a method of sharing an Image Store between multiple clusters - this will result in corruption of cluster configuration data as each cluster can write conflicting data to the Image Store. 若要在多个群集之间共享预配的应用程序包,请改用 sfpkg 文件,可以使用下载 URI 将这些文件上传到任何外部存储。To share provisioned application packages between multiple clusters, use sfpkg files instead, which can be uploaded to any external store with a download URI.

因此,虽然 ImageStoreConnectionString 是可配置的,但只使用默认设置。So while the ImageStoreConnectionString is configurable, you just use the default setting. 通过 Visual Studio 发布到 Azure 时,该参数会相应地自动设置。When publishing to Azure through Visual Studio, the parameter is automatically set for you accordingly. 对于在 Azure 中托管的群集的编程部署,连接字符串始终是“fabric:ImageStore”。For programmatic deployment to clusters hosted in Azure, the connection string is always "fabric:ImageStore". 即使有疑问时,也始终可通过 PowerShell.NETREST 检索群集清单来验证其值。Though when in doubt, its value can always be verified by retrieving the cluster manifest by PowerShell, .NET, or REST. 同样,本地测试和生产群集应始终配置为使用映像存储区服务提供程序。Both on-premises test and production clusters should always be configured to use the Image Store Service provider as well.

后续步骤Next steps

使用 PowerShell 部署和删除应用程序Deploy and remove applications using PowerShell