PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

Ny PowerShell Desired State Configuration (DSC) dia manamora be ny asa fametrahana sy fanamboarana ny rafitra fiasana, ny andraikitry ny mpizara ary ny fampiharana rehefa manana mpizara an-jatony ianao.

Fa rehefa mampiasa DSC an-toerana, i.e. tsy ao amin'ny MS Azure, misy ny nuance roa. Tena tsikaritra izy ireo raha lehibe ny fikambanana (avy amin'ny toeram-piasana sy mpizara 300) ary mbola tsy nahita ny tontolon'ny kaontenera:

  • Tsy misy tatitra feno momba ny satan'ny rafitra. Raha toa ka tsy nampiharina tamin'ny mpizara sasany ny fanamafisam-peo takiana, dia tsy ho fantatsika izany raha tsy misy ireo tatitra ireo. Sarotra ny mahazo vaovao avy amin'ny mpizara tatitra naorina, ary ho an'ny mpampiantrano marobe dia mety haharitra ela ihany koa izany.
  • Tsy ampy scalability sy fandeferana fahadisoana. Tsy azo atao ny manangana toeram-pambolena DSC misintona mpizara tranonkala izay manana angon-drakitra mandefitra amin'ny fahadisoana tokana ary fitehirizana iraisan'ny rakitra mof ho an'ny fanamafisana, maody ary fanalahidin'ny fisoratana anarana.

Androany aho dia hilaza aminao ny fomba ahafahanao mamaha ny olana voalohany sy mahazo angona ho an'ny tatitra. Ho mora kokoa ny zava-drehetra raha azo ampiasaina ho angon-drakitra ny SQL. MS FAMPANANTENAN'ANDRIAMANITRA fanohanana naorina ao amin'ny Windows Server 2019 na ao amin'ny build Windows server 1803. Makà data amin'ny alàlan'ny mpamatsy OleDB ihany koa tsy handehasatria ny DSC Server dia mampiasa mari-pamantarana nomena anarana izay tsy tohanan'ny OleDbCommand tanteraka.

Hitako ity fomba ity: ho an'ireo izay mampiasa Windows Server 2012 sy 2016, azonao atao napetraka mampiasa angona SQL ho backend ho an'ny mpizara fangatahana DSC. Mba hanaovana izany, dia hamorona "proxy" amin'ny endrika .mdb rakitra miaraka amin'ny latabatra mifandray, izay hamindra ny angona voaray avy amin'ny mpanjifa tatitra ho any amin'ny SQL server database.

Fanamarihana: Ho an'ny Windows Server 2016 dia tsy maintsy mampiasa ianao AccessDatabaseEngine2016x86satria tsy tohana intsony ny Microsoft.Jet.OLEDB.4.0.

Tsy hiditra amin'ny antsipiriany momba ny fizotran'ny fametrahana server DSC pull aho, voafaritra tsara izany eto. Hevitra roa ihany no homarihiko. Raha mametraka ny DSC puller amin'ny mpizara tranonkala mitovy amin'ny WSUS na Kaspersky Security Center isika, dia mila manova ireto marika manaraka ireto ao amin'ny script famoronana configuration:

  1. UseSecurityBestPractices     = $false

    Raha tsy izany, TLS 1.0 dia ho kilemaina ary tsy afaka mifandray amin'ny angona SQL ianao. Tsy mandeha ihany koa ny Kaspersky Security Center (tokony ho voavaha ny olana ao amin'ny Kaspersky Security Center v11).

  2. Enable32BitAppOnWin64   = $true

    Raha tsy manao izany fiovana izany ianao dia tsy ho afaka hampandeha ny mpizara AppPool DSC amin'ny IIS miaraka amin'ny WSUS.

  3. Rehefa mametraka DSC Server miaraka amin'ny WSUS, esory ny caching static sy dynamic ho an'ny tranokala DSC.

Andao hiroso amin'ny fametrahana ny mpizara DSC hampiasa ny angona SQL.

Mamorona angona SQL

  1. Andao hamorona angona SQL foana antsoina hoe DSC.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  2. Andao hamorona kaonty hifandraisana amin'ity tahiry ity. Voalohany, jereo fa ny mpizara SQL dia mamela ny fanamarinana ny kaonty Windows sy SQL.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  3. Mandehana any amin'ny fizarana User Mapping. Safidio ny angon-drakitra, amin'ity tranga ity DSC. Manome ny zon'ny tompon'ny tahiry izahay.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  4. Nataon'i.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

Mamorona Schema ho an'ny DSC Database

Misy fomba roa hamoronana schema ho an'ny angona DSC:

  • tsy miankina, amin'ny alàlan'ny script TSQL
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Devices](
    [TargetName] [nvarchar](255) NOT NULL,
    [ConfigurationID] [nvarchar](255) NOT NULL,
    [ServerCheckSum] [nvarchar](255) NOT NULL,
    [TargetCheckSum] [nvarchar](255) NOT NULL,
    [NodeCompliant] [bit] NOT NULL,
    [LastComplianceTime] [datetime] NULL,
    [LastHeartbeatTime] [datetime] NULL,
    [Dirty] [bit] NOT NULL,
    [StatusCode] [int] NULL
    ) ON [PRIMARY]
    GO
     
    CREATE TABLE [dbo].[RegistrationData](
    [AgentId] [nvarchar](255) NOT NULL,
    [LCMVersion] [nvarchar](255) NULL,
    [NodeName] [nvarchar](255) NULL,
    [IPAddress] [nvarchar](255) NULL,
    [ConfigurationNames] [nvarchar](max) NULL
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
     
    CREATE TABLE [dbo].[StatusReport](
    [JobId] [nvarchar](50) NOT NULL,
    [Id] [nvarchar](50) NOT NULL,
    [OperationType] [nvarchar](255) NULL,
    [RefreshMode] [nvarchar](255) NULL,
    [Status] [nvarchar](255) NULL,
    [LCMVersion] [nvarchar](50) NULL,
    [ReportFormatVersion] [nvarchar](255) NULL,
    [ConfigurationVersion] [nvarchar](255) NULL,
    [NodeName] [nvarchar](255) NULL,
    [IPAddress] [nvarchar](255) NULL,
    [StartTime] [datetime] NULL,
    [EndTime] [datetime] NULL,
    [Errors] [nvarchar](max) NULL,
    [StatusData] [nvarchar](max) NULL,
    [RebootRequested] [nvarchar](255) NULL
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
  • manafatra angona avy amin'ny fitaovana tsy misy na inona na inona.mdb ho ampahany amin'ny maody PS PSDesiredStateConfiguration amin'ny alàlan'ny SQL Data Import Wizard.

    Ny Devices.mdb hiarahanay dia hita ao amin'ny C:WindowsSysWOW64WindowsPowerShellv1.0ModulesPSDesiredStateConfigurationPullServer.

  1. Raha hanafatra angona dia mandehana ny SQL Server Import and Export Wizard.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  2. Mifidy avy amin'ny toerana ahazoantsika ny angon-drakitra izahay - raha ny anay dia angona Microsoft Access izany. Tsindrio Manaraka.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  3. Safidio ny rakitra izay hanafatra ny kisary.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  4. Asehonay hoe aiza no hanafatra - ho anay dia angona SQL izany.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  5. Safidio ny mpizara SQL (Anaran'ny mpizara) sy ny angon-drakitra izay hanafatra data (DataBase).

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  6. Safidio ny safidy Adikao ny angona avy amin'ny tabilao na fijery iray na maromaro (mandika data avy amin'ny tabilao na fijery).

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  7. Mifidy ny latabatra izay hanafatra ny schema database izahay.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  8. Tsindrio ny bokotra Run Immediately ary tsindrio Finish.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  9. Nataon'i.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  10. Vokatr'izany dia tokony hiseho ao amin'ny tahiry DSC ny tabilao.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

Mametraka rakitra .mdb "proxy".

Mamorona fifandraisana ODBC amin'ny mpizara SQL. Heverina fa ny MS Access dia tsy napetraka amin'ny mpizara mampiasa DSC, ka ny fametrahana databases.mdb dia atao amin'ny mpampiantrano mpanelanelana misy MS Access napetraka.

Andeha isika hamorona rafitra ODBC fifandraisana amin'ny SQL server (ny fifandraisana bitness dia tsy maintsy mifanaraka amin'ny MS Access bitness - 64 na 32). Afaka mamorona izany amin'ny fampiasana:
- Powershell cmdlet:

Add-OdbcDsn –Name DSC –DriverName 'SQL Server' –Platform '<64-bit or 32-bit>' –DsnType System –SetPropertyValue @('Description=DSC Pull Server',"Server=<Name of your SQL Server>",'Trusted_Connection=yes','Database=DSC') –PassThru

- na amin'ny tanana, amin'ny fampiasana ny wizard fifandraisana:

  1. Sokafy ny fitaovana fitantanana. Mifidy loharano angon-drakitra ODBC izahay miankina amin'ny kinova MS Access napetraka. Mandehana any amin'ny tabilao System DSN ary mamorona fifandraisana rafitra (Add).

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  2. Asehonay fa hifandray amin'ny mpizara SQL izahay. Tsindrio Finish.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  3. Lazao ny anarana sy ny mpizara hifandraisana. Avy eo dia mila mifandray amin'ny masontsivana mitovy amin'izany amin'ny mpizara DSC.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  4. Tondroinay fa raha te hifandray amin'ny mpizara SQL dia mampiasa fidirana efa noforonina miaraka amin'ny anarana DSC izahay.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  5. Izahay dia mamaritra ny angon-drakitra ao amin'ny firafitry ny fifandraisana DSC.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  6. Tsindrio Finish.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  7. Alohan'ny hamitana ny fanamboarana dia manamarina izahay fa mandeha ny fifandraisana (Loharano Data Test).

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  8. Nataon'i.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

Mamorona angon-drakitra devices.mdb amin'ny MS Access. Sokafy ny MS Access ary mamorona angon-drakitra foana antsoina hoe devices.mdb.

PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  1. Mandehana any amin'ny tabilao External Data ary tsindrio ny ODBC Database. Ao amin'ny varavarankely izay miseho, mifidiana Mamorona latabatra mifandray hifandraisana amin'ny loharano angona.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  2. Ao amin'ny varavarankely vaovao, safidio ny tabilao Machine Data Source ary tsindrio OK. Ao amin'ny varavarankely vaovao, ampidiro ny fahazoan-dàlana hifandray amin'ny mpizara SQL.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  3. Fidio ireo tabilao mila ampifandraisina. Jereo ny boaty Save tenimiafina ary tsindrio OK. Tehirizo ny tenimiafina isaky ny latabatra telo.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  4. Ao amin'ny index dia mila misafidy ireto manaraka ireto ianao:
    - TargetName ho an'ny latabatra dbo_Devices;

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

    - NodeName na IPAddress ho an'ny dbo_RegistrationData;

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

    - NodeName na IPAddress ho an'ny dbo_StatusReport.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  5. Andeha hosoloina anarana ny tabilao ao amin'ny MS Access, izany hoe: esory ny tovana dbo_ mba ahafahan'ny DSC mampiasa azy.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  6. Nataon'i.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  7. Tehirizo ny rakitra ary akatona ny MS Access. Ankehitriny dia mandika ny fitaovana.mdb vokarina amin'ny mpizara DSC izahay (amin'ny alàlan'ny default ao amin'ny C: Program FilesWindowsPowershellDSCService) ary manolo ny efa misy azy (raha misy).

Fanamboarana Server DSC hampiasa SQL

  1. Miverina amin'ny mpizara DSC izahay. Raha te hifandray amin'ny mpizara SQL miaraka amin'ny rakitra proxy, andao hamorona fifandraisana ODBC vaovao amin'ny mpizara DSC. Ny anarana, ny halalin'ny bitika, ary ny firafitry ny fifandraisana dia tsy maintsy mitovy amin'ny famoronana ny rakitra MDB. Azonao atao ny mandika ireo fitaovana tsy misy na inona na inona efa voarindra.mdb avy eto.
  2. Raha hampiasa devices.mdb dia mila manova ny web.config an'ny mpizara DSC pull ianao (C:inetpubPSDSCPullServerweb.config ny default):

- ho an'ny Windows Server 2012

<add key="dbprovider" value="System.Data.OleDb">
<add key="dbconnectionstr" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Program FilesWindowsPowerShellDscServiceDevices.mdb;">

- ho an'ny Windows Server 2016

<add key="dbprovider" value="System.Data.OleDb">
<add key="dbconnectionstr" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Program FilesWindowsPowerShellDscServiceDevices.mdb;">

Izany dia mamita ny fametrahana ny mpizara DSC.

Fanamarinana ny fiasan'ny mpizara DSC

  1. Andeha hojerentsika fa azo idirana amin'ny alalan'ny navigateur web ny mpizara DSC.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  2. Andeha hojerentsika raha mandeha tsara ny server DSC pull. Mba hanaovana izany, ny module xPSDesiredStateConfiguration dia ahitana ny script pullserversetuptests.ps1. Alohan'ny hampandehanana ity script ity dia tsy maintsy mametraka maody Powershell antsoina hoe Pester ianao. Apetraho izany Install-Module -Name Pester.
  3. Sokafy C:Program FilesWindowsPowerShellModulesxPSDesiredStateConfiguration<module version>DSCPullServerSetupPullServerDeploymentVerificationTest (amin'ny ohatra version 8.0.0.0.0).

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  4. Sokafy ny PullServerSetupTests.ps1 ary jereo ny lalana mankany amin'ny web.config an'ny mpizara DSC. Ny lalana mankany amin'ny web.config, izay hanamarina ny script, dia nasongadina mena. Raha ilaina dia ovainay ity lalana ity.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  5. Manaova pullserversetuptests.ps1
    Invoke-Pester.PullServerSetupTests.ps1
    Все работает.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

  6. Ao amin'ny SQL Management Studio dia hitantsika fa ny mpampiantrano voatanisa dia mandefa tatitra any amin'ny mpizara tatitra DSC ary ny angon-drakitra dia miafara amin'ny angon-drakitra DSC amin'ny mpizara SQL.

    PowerShell Desired State Configuration and file: part 1. Configuring DSC Pull Server to work with a SQL database

Izay ihany. Amin'ireto lahatsoratra manaraka ireto dia mikasa ny hilaza aminao ny fomba hananganana tatitra momba ny angon-drakitra azo aho, ary hiresaka momba ny olana momba ny fandeferana sy ny fampitomboana ny fahadisoana aho.

Source: www.habr.com

Add a comment