移动和重命名AppFabric配置数据库

时间:2015-04-23 11:54:32

标签: powershell appfabric appfabric-cache

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

重命名来自默认名称" AppFabricConfigurationDatabase"到" AppFabricPreOrdersConfiguration"

已使用新数据库和服务器名称

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

并且服务成功启动。

但从这一点来看,&#34;缓存管理powershell&#34;因为当调用use-cachecluster时它仍然会尝试连接到旧的服务器/数据库。

ConnectionString Data Source = OLDSERVER;初始目录的测试连接失败 = AppFabricCacheConfigurationDatabase;

Use-CacheCluster:ErrorCode:SubStatus:无效的提供者和c onnection string read。

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

3 个答案:

答案 0 :(得分:2)

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

    string exception = "";
    try
    {
        System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
        // I wonder what to do here...
    }
    catch (Exception ex)
    {
        //store the exception until the logging is initialized
        exception = ex.ToString();
        i_UserLevel = 0;
    }

答案 1 :(得分:2)

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

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

该值命名为&#34; ConnectionString&#34;

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

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

答案 2 :(得分:1)

您需要调用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