AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / dba / Perguntas / 229245
Accepted
user1716729
user1716729
Asked: 2019-02-09 06:53:21 +0800 CST2019-02-09 06:53:21 +0800 CST 2019-02-09 06:53:21 +0800 CST

Definir a inicialização do serviço usando DSC

  • 772

Novato na configuração de estado desejado do Windows PowerShell (DSC) aqui. A geração do arquivo MOF falha com:

PSDesiredStateConfiguration\Node : The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:13 char:5
+     Node localhost
+     ~~~~
    + CategoryInfo          : MetadataError: (:) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ArgumentIsNull,PSDesiredStateConfiguration\node   Compilation errors occurred while processing configuration 'SQLConfig'. Please review the errors reported in error stream and modify your configuration code appropriately. At C:\windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3917 char:5
+     throw $ErrorRecord
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (SQLConfig:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

Roteiro

Configuration SQLConfig
{
    param(
        [Parameter(Mandatory =$true)][string[]]$serviceConfig,
        [Parameter(Mandatory =$true)][string]$DataDrive,
        [Parameter(Mandatory =$true)][string]$LogDrive

    )
    Import-DscResource -ModuleName SqlServerDsc
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node localhost
    {
        WindowsFeature Net35
        {
            Name = 'NET-Framework-Core'
            Ensure = 'Present'
        }
        WindowsFeature Net45
        {
            Name = 'NET-Framework-45-Core'
            Ensure = 'Present'
        }
        WindowsFeature Cluster
        {
            Name = 'RSAT-Clustering'
            Ensure = 'Present'
        }

        File datadrive
        {
           Type = 'Directory'
           DestinationPath = $DataDrive
           Ensure ='Present' 

        }
        File logdrive
        {
           Type = 'Directory'
           DestinationPath = $LogDrive
           Ensure ='Present' 
        }
        SqlDatabaseDefaultLocation dataPath
        {
            InstanceName = 'MSSQLSERVER'
            Path = $DataDrive
            ServerName = 'localhost'
            Type = 'Data'
            DependsOn = '[File]datadrive'
        }
        SqlDatabaseDefaultLocation logPath
        {
            InstanceName = 'MSSQLSERVER'
            Path = $LogDrive
            ServerName = 'localhost'
            Type = 'Log'
            DependsOn = '[File]logdrive'
        }
        foreach ($service in $serviceConfig) {
            ServiceSet $service
            {
                Name = $service.ServiceName
                State = $service.State
                StartupType = $service.StartupType
                Ensure = $service.Ensure
            }


        }

    }
}

#region create configuration data

$serviceConfig=(
    @{ServiceName='MSSQLSERVER';State='Running';StartupType='Automatic';Ensure='Present'},
    @{ServiceName='SQLSERVERAGENT';State='Running';StartupType='Automatic';Ensure='Present'},
    @{ServiceName='SQLBrowser';State='Ignore';StartupType='Disabled';Ensure='Present'}
)
SQLConfig -serviceConfig $serviceConfig -DataDrive "F:\Data" -LogDrive "H:\Log" -OutputPath "C:\dump"
sql-server installation
  • 1 1 respostas
  • 331 Views

1 respostas

  • Voted
  1. Best Answer
    user507
    2019-02-21T11:14:08+08:002019-02-21T11:14:08+08:00

    Algumas coisas que precisam ser corrigidas em sua função de configuração:

    1. O parâmetro serviceConfigdeve ser o tipo [object[]]para aceitar uma tabela de hash. O uso [string[]]do PowerShell não trata adequadamente a iteração sobre esse objeto, pois é um objeto literal e não apenas uma matriz de strings.
    2. Quando você estiver usando um recurso no DSC, ele deve ser um nome exclusivo. Sua declaração do ServiceSetrecurso está simplesmente passando $service; que, em termos do PowerShell, está simplesmente passando a [System.Collections.Hashtable]cada vez e, portanto, não é exclusivo.

    Versão corrigida da configuração que testa e roda com sucesso no meu sistema:

    Configuration SQLConfig
    {
        param(
            [Parameter(Mandatory =$true)][object[]]$serviceConfig,
            [Parameter(Mandatory =$true)][string]$DataDrive,
            [Parameter(Mandatory =$true)][string]$LogDrive
    
        )
        Import-DscResource -ModuleName SqlServerDsc
        Import-DscResource -ModuleName PSDesiredStateConfiguration
    
        Node localhost 
        {
            WindowsFeature Net35 {
                Name   = 'NET-Framework-Core'
                Ensure = 'Present'
            }
            WindowsFeature Net45 {
                Name   = 'NET-Framework-45-Core'
                Ensure = 'Present'
            }
            WindowsFeature Cluster {
                Name   = 'RSAT-Clustering'
                Ensure = 'Present'
            }
    
            File datadrive {
                Type            = 'Directory'
                DestinationPath = $DataDrive
                Ensure          ='Present' 
    
            }
            File logdrive {
                Type            = 'Directory'
                DestinationPath = $LogDrive
                Ensure          ='Present' 
            }
            SqlDatabaseDefaultLocation dataPath {
                InstanceName = 'MSSQLSERVER'
                Path         = $DataDrive
                ServerName   = 'localhost'
                Type         = 'Data'
                DependsOn    = '[File]datadrive'
            }
            SqlDatabaseDefaultLocation logPath {
                InstanceName = 'MSSQLSERVER'
                Path         = $LogDrive
                ServerName   = 'localhost'
                Type         = 'Log'
                DependsOn    = '[File]logdrive'
            }
            foreach ($service in $serviceConfig) {
                ServiceSet $service.ServiceName {
                    Name        = $service.ServiceName
                    State       = $service.State
                    StartupType = $service.StartupType
                    Ensure      = $service.Ensure
                }
            }
    
        }
    }
    
    $serviceConfig= @(
        @{ServiceName='MSSQLSERVER';State='Running';StartupType='Automatic';Ensure='Present'},
        @{ServiceName='SQLSERVERAGENT';State='Running';StartupType='Automatic';Ensure='Present'},
        @{ServiceName='SQLBrowser';State='Stopped';StartupType='Disabled';Ensure='Present'}
    )
    SQLConfig -serviceConfig $serviceConfig -DataDrive "C:\temp" -LogDrive "C:\temp" -OutputPath "C:\temp" -Verbose
    
    • 1

relate perguntas

  • SQL Server - Como as páginas de dados são armazenadas ao usar um índice clusterizado

  • Preciso de índices separados para cada tipo de consulta ou um índice de várias colunas funcionará?

  • Quando devo usar uma restrição exclusiva em vez de um índice exclusivo?

  • Quais são as principais causas de deadlocks e podem ser evitadas?

  • Como determinar se um Índice é necessário ou necessário

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    conectar ao servidor PostgreSQL: FATAL: nenhuma entrada pg_hba.conf para o host

    • 12 respostas
  • Marko Smith

    Como fazer a saída do sqlplus aparecer em uma linha?

    • 3 respostas
  • Marko Smith

    Selecione qual tem data máxima ou data mais recente

    • 3 respostas
  • Marko Smith

    Como faço para listar todos os esquemas no PostgreSQL?

    • 4 respostas
  • Marko Smith

    Listar todas as colunas de uma tabela especificada

    • 5 respostas
  • Marko Smith

    Como usar o sqlplus para se conectar a um banco de dados Oracle localizado em outro host sem modificar meu próprio tnsnames.ora

    • 4 respostas
  • Marko Smith

    Como você mysqldump tabela (s) específica (s)?

    • 4 respostas
  • Marko Smith

    Listar os privilégios do banco de dados usando o psql

    • 10 respostas
  • Marko Smith

    Como inserir valores em uma tabela de uma consulta de seleção no PostgreSQL?

    • 4 respostas
  • Marko Smith

    Como faço para listar todos os bancos de dados e tabelas usando o psql?

    • 7 respostas
  • Martin Hope
    Jin conectar ao servidor PostgreSQL: FATAL: nenhuma entrada pg_hba.conf para o host 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane Como faço para listar todos os esquemas no PostgreSQL? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh Por que o log de transações continua crescendo ou fica sem espaço? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland Listar todas as colunas de uma tabela especificada 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney O MySQL pode realizar consultas razoavelmente em bilhões de linhas? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx Como posso monitorar o andamento de uma importação de um arquivo .sql grande? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison Como você mysqldump tabela (s) específica (s)? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas Como posso cronometrar consultas SQL usando psql? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas Como inserir valores em uma tabela de uma consulta de seleção no PostgreSQL? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas Como faço para listar todos os bancos de dados e tabelas usando o psql? 2011-02-18 00:45:49 +0800 CST

Hot tag

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve