【问题标题】:Moving and renaming AppFabric configuration database移动和重命名 AppFabric 配置数据库
【发布时间】:2015-09-17 22:04:03
【问题描述】:

最近我们对 AppFabric 配置数据库进行了迁移和重命名。

重命名从默认名称“AppFabricConfigurationDatabase”改为“AppFabricPreOrdersConfiguration”

DisirbutedCacheService.exe.config 已更改为新的数据库和服务器名称

<clusterConfig provider="System.Data.SqlClient" connectionString="Data Source=NEWSERVER;Initial Catalog=AppFabricPreOrdersConfiguration;Integrated Security=True" />

服务启动成功。

但从此时起,“缓存管理 powershell”不再启动,因为当调用 use-cachecluster 时,它仍会尝试连接到旧服务器/数据库。

ConnectionString 数据源=OLDSERVER 的测试连接失败;初始目录 =AppFabricCacheConfigurationDatabase;

Use-CacheCluster : ErrorCode:SubStatus:Invalid provider and c 连接字符串读取。

powershell 从哪里读取这些值?显然不是来自服务的配置文件,而是来自哪里?

【问题讨论】:

  • 尝试使用程序procmon
  • 什么也没出现。我开始认为这是某个地方的硬编码值
  • 您是否在每台主机上重新启动了 AppFabricCachingService?

标签: powershell appfabric appfabric-cache


【解决方案1】:

由于我无法停止集群,我试图查看连接字符串是否会在不重新启动的情况下更改,并且基本上只是调用 Remove-CacheAdmin 和 Add-CacheAdmin....它成功了! 当然,脚本必须在每台主机上运行,​​因此不适合大型设置,但显然不需要重新启动

param ([string] $provider, [string] $newConnectionString)

function Main {

    if ( (! $provider) -or (! $newConnectionString))
    {
        Write-Host "Usage: ChangeConnString.ps1 <provider> <newConnectionString>"
        exit(1)
    }

    Import-Module "DistributedCacheAdministration"
    Import-Module "DistributedCacheConfiguration"
    [Reflection.Assembly]::LoadWithPartialName('Microsoft.ApplicationServer.Caching.Management') | Out-Null
    [Reflection.Assembly]::LoadWithPartialName('System.Management.Automation') | Out-Null
    [Reflection.Assembly]::LoadWithPartialName('System.Management.Automation.Runspaces') | Out-Null

    Remove-CacheAdmin
    Add-CacheAdmin -Provider $provider -ConnectionString $newConnectionString  

}

【讨论】:

    【解决方案2】:

    其他用户提供的脚本对我不起作用。我遇到了异常。我可以通过编辑每台主机上的注册表并重新启动服务来解决此问题。

    连接字符串存储在这里:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\AppFabric\V1.0\Configuration

    该值被命名为“ConnectionString”

    在用户配置单元下,有另一个连接字符串实例。我不知道你是否需要改变这个,但我做到了。 HKEY_CURRENT_USER\Software\Microsoft\AppFabric\V1.0\Temp

    这对我有用。不要忘记您还需要在 C:\Program Files\AppFabric 1.1 for Windows Server 下编辑 DistributedCacheService.exe.config 中的 ClusterConfig ConnectionString

    【讨论】:

      【解决方案3】:

      您需要调用Remove-CacheAdmin 然后Add-CacheAdmin 来更改每个管理主机上的缓存管理连接

      This Microsoft Powershell script - (.EXE 下载,脚本转载如下) - 更改集群中所有主机上的连接字符串。

      param ([string] $provider, [string] $newConnectionString)
      
      function Main {
      
          if ( (! $provider) -or (! $newConnectionString))
          {
              Write-Host "Usage: ChangeConnString.ps1 <provider> <newConnectionString>"
              exit(1)
          }
      
          Import-Module "DistributedCacheAdministration"
          Import-Module "DistributedCacheConfiguration"
      
          Use-CacheCluster
      
          Write-Host "Stop the cache cluster if it is running"
          $clusterRunnig=$true
          &{
              Stop-CacheCluster -EA Stop
          }
          trap [DataCacheException] {  
              #'Error Category {0}, Error Type {1}, ID: {2}, Message: {3} {4}' -f  $_.CategoryInfo.Category, $_.Exception.GetType().FullName,  $_.FullyQualifiedErrorID, $_.Exception.Message, $_.Exception.ErrorCode;
              #12008: ErrorCode<ERRCAdmin008>:SubStatus<ES0001>:No hosts running in cluster
              if ($_.Exception.ErrorCode -eq 12008)
              {
                  write-host "Cluster is not running"
                  $clusterRunnig=$false
                  continue
              }
          }
      
          [Reflection.Assembly]::LoadWithPartialName('Microsoft.ApplicationServer.Caching.Management') | Out-Null
          [Reflection.Assembly]::LoadWithPartialName('System.Management.Automation') | Out-Null
          [Reflection.Assembly]::LoadWithPartialName('System.Management.Automation.Runspaces') | Out-Null
      
          SetCacheConnectionString $provider $newConnectionString
      
          Write-Host "Connection string is altered on all the cache hosts. Now changing the connection string for cache admin"
          Remove-CacheAdmin
          Add-CacheAdmin -Provider $provider -ConnectionString $newConnectionString
      
          if ($clusterRunnig -eq $true)
          {
              Write-Host "Starting the cache cluster..." 
              Start-CacheCluster
          }
      }
      
      function SetCacheConnectionString {
      
          param ([string] $provider, [string] $newConnectionString)
      
          Write-Host "Parameters: " $provider " " $newConnectionString
          $powerShell = [System.Management.Automation.PowerShell]::Create()
          # Import the admin cmdlets module
          $powerShell.AddCommand("Import-Module", $true);
          $powerShell.AddParameter("Name", "DistributedCacheAdministration")
      
          # Call the Invoke method to run the commands
          $powerShell.Invoke();
      
          $powerShell.Commands.AddCommand("Use-CacheCluster")
          $powerShell.Commands.AddCommand("Get-CacheHost")
          $commandResults = $powerShell.Invoke()
          $powerShell.Dispose()
      
          Write-Host "Number of hosts in the cluster " $commandResults.Count
          foreach ($cacheHost in $commandResults)
          {
              Write-Host "Configuring the host " $cacheHost.HostName
      
              Invoke-Command -ComputerName $cacheHost.HostName -ScriptBlock {param ($provider, $newConnectionString) Import-Module DistributedCacheConfiguration;Remove-CacheHost;Add-CacheHost -Provider $provider -ConnectionString $newConnectionString -Account 'NT Authority\NETWORK SERVICE'} -ArgumentList $provider, $newConnectionString
          }
      }
      
      #
      # Entry
      #
      Main
      

      【讨论】:

      • 哇好答案!当主机可以停止时,我会试试这个:)
      猜你喜欢
      • 1970-01-01
      • 2014-08-05
      • 2016-01-11
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      • 2010-09-13
      • 2016-07-06
      • 1970-01-01
      相关资源
      最近更新 更多