게시 및 배포 구성

적용 대상:SQL ServerAzure SQL Managed Instance

이 항목에서는 SQL Server Management Studio, Transact-SQL 또는 RMO(복제 관리 개체)를 사용하여 SQL Server에서 게시 및 배포를 구성하는 방법에 대해 설명합니다.

시작하기 전에

보안

자세한 내용은 복제 보안 설정 보기 및 수정을 참조하세요.

SQL Server Management Studio 사용

새 게시 마법사 또는 배포 구성 마법사를 사용하여 배포를 구성합니다. 배포자를 구성한 후 배포자 속성 - <배포>자 대화 상자에서 속성을 보고 수정합니다. 고정 데이터베이스 역할의 db_owner 멤버가 게시를 만들 수 있도록 배포자를 구성하거나 게시자가 아닌 원격 배포자를 구성하려는 경우 배포 구성 마법사를 사용합니다.

배포를 구성하려면

  1. Microsoft SQL Server Management Studio에서 배포자가 될 서버에 연결한 다음(대부분의 경우 게시자와 배포자는 동일한 서버) 서버 노드를 확장합니다.

  2. 복제 폴더를 마우스 오른쪽 단추로 클릭한 다음 배포 구성을 클릭합니다.

  3. 배포 구성 마법사에 따라 다음을 수행하세요.

  • 배포자를 선택합니다. 로컬 배포자를 사용하려면 ServerName을 선택하면 자체 배포자로 작동합니다. SQL Server는 배포 데이터베이스 및 로그를 만듭니다. 원격 배포자를 사용하려면 다음 서버를 배포자로 사용을 선택한 다음 서버를 선택합니다. 서버는 미리 배포자로 구성되어 있어야 하며 해당 배포자를 사용하도록 게시자를 설정해야 합니다. 자세한 내용은 배포자에서 원격 게시자 사용(SQL Server Management Studio)을 참조하세요.

    원격 배포자를 선택하는 경우 게시자에서 배포자로 연결하기 위해 관리시제 암호 페이지에 암호를 입력해야 합니다. 이 암호는 원격 배포자에서 게시자를 사용할 때 지정한 암호와 일치해야 합니다.

  • 루트 스냅샷 폴더를 지정합니다(로컬 배포자에 대한). 스냅샷 폴더는 단순히 공유로 지정한 디렉터리입니다. 이 폴더에서 읽고 쓰는 에이전트에는 액세스할 수 있는 충분한 권한이 있어야 합니다. 이 배포자를 사용하는 각 게시자는 루트 폴더 아래에 폴더를 만들고 각 게시는 스냅샷 파일을 저장할 Publisher 폴더 아래에 폴더를 만듭니다. 폴더를 적절하게 보호하는 방법에 대한 자세한 내용은 스냅샷 폴더 보안을 참조 하세요.

  • 배포 데이터베이스를 지정합니다(로컬 배포자의 경우). 배포 데이터베이스는 트랜잭션 복제에 대한 모든 유형의 복제 및 트랜잭션에 대한 메타데이터와 기록 데이터를 저장합니다.

  • 필요에 따라 배포자를 사용할 수 있도록 다른 게시자를 설정합니다. 배포자를 사용할 수 있도록 다른 게시자를 설정한 경우 배포자 암호 페이지에서 이러한 게시자에서 배포자로 연결할 때 사용될 암호를 입력해야 합니다.

  • 필요에 따라 구성 설정을 스크립팅합니다. 자세한 내용은 복제 스크립팅을 참조 하세요.

Transact-SQL 사용

복제 게시 및 배포는 복제본(replica)tion 저장 프로시저를 사용하여 프로그래밍 방식으로 구성할 수 있습니다.

로컬 배포자를 사용하여 게시를 구성하려면

  1. sp_get_distributor(Transact-SQL)를 실행하여 서버가 배포자로 이미 구성되어 있는지 확인합니다.
  • 결과 집합의 값이0면 master 데이터베이스의 installed 배포자에서 sp_adddistributor(Transact-SQL)를 실행합니다.

  • 결과 집합의 값이0면 master 데이터베이스의 distribution db installed 배포자에서 sp_adddistributiondb(Transact-SQL)를 실행합니다. 에 대한 배포 데이터베이스의 이름을 지정합니다 @database. 필요에 따라 최대 트랜잭션 보존 기간 @max_distretention 및 기록 보존 기간을 @history_retention지정할 수 있습니다. 새 데이터베이스를 만드는 경우 원하는 데이터베이스 속성 매개 변수를 지정합니다.

  1. 게시자이기도 한 배포자에서 sp_adddistpublisher(Transact-SQL)를 실행하여 기본 스냅샷 폴더로 사용할 UNC 공유를 @working_directory지정합니다.

    SQL Managed Instance의 배포자의 경우 Azure Storage 계정 @working_directory 및 스토리지 액세스 키를 @storage_connection_string사용합니다.

  2. 게시자에서 sp_복제본(replica)tiondboption(Transact-SQL)을 실행합니다. 게시@dbname할 데이터베이스, 복제본(replica)tion의 형식 및 에 대한 @optname@value값을 true 지정합니다.

원격 배포자를 사용하여 게시를 구성하려면

  1. sp_get_distributor(Transact-SQL)를 실행하여 서버가 배포자로 이미 구성되어 있는지 확인합니다.

    • 결과 집합의 값이0면 master 데이터베이스의 installed 배포자에서 sp_adddistributor(Transact-SQL)를 실행합니다. 이때 @password을 참조하세요. 이 암호는 distributor_admin 계정의 암호로 배포자에 연결할 때 게시자에서 사용됩니다.

    • 결과 집합의 값이0면 master 데이터베이스의 distribution db installed 배포자에서 sp_adddistributiondb(Transact-SQL)를 실행합니다. 에 대한 배포 데이터베이스의 이름을 지정합니다 @database. 필요에 따라 최대 트랜잭션 보존 기간 @max_distretention 및 기록 보존 기간을 @history_retention지정할 수 있습니다. 새 데이터베이스를 만드는 경우 원하는 데이터베이스 속성 매개 변수를 지정합니다.

  2. 배포자에서 sp_adddistpublisher(Transact-SQL)를 실행하고 기본 스냅샷 폴더로 사용할 UNC 공유를 @working_directory지정합니다. 배포자가 게시자에 연결할 때 SQL Server 인증을 사용하는 경우 해당 값 0@security_mode 과 Microsoft SQL Server 로그인 정보 @login@password도 지정해야 합니다.

    SQL Managed Instance의 배포자의 경우 Azure Storage 계정 @working_directory 및 스토리지 액세스 키를 @storage_connection_string사용합니다.

  3. master 데이터베이스의 게시자에서 sp_adddistributor(Transact-SQL)를 실행합니다. 이때 @password을 참조하세요. 이 암호는 배포자에 연결할 때 게시자가 사용합니다.

  4. 게시자에서 sp_복제본(replica)tiondboption(Transact-SQL)을 실행합니다. 게시@dbname할 데이터베이스, 복제본(replica)tion @optname유형 및 true 값을 지정합니다@value.

예제(Transact-SQL)

다음 예제에서는 게시 및 배포를 프로그래밍 방식으로 구성하는 방법을 보여 줍니다. 이 예제에서는 게시자 및 로컬 배포자로 구성되는 서버의 이름이 스크립팅 변수를 사용하여 제공됩니다. 복제 게시 및 배포는 복제본(replica)tion 저장 프로시저를 사용하여 프로그래밍 방식으로 구성할 수 있습니다.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- Install the Distributor and the distribution database.
DECLARE @distributor AS sysname;
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @directory AS nvarchar(500);
DECLARE @publicationDB AS sysname;
-- Specify the Distributor name.
SET @distributor = $(DistPubServer);
-- Specify the distribution database.
SET @distributionDB = N'distribution';
-- Specify the Publisher name.
SET @publisher = $(DistPubServer);
-- Specify the replication working directory.
SET @directory = N'\\' + $(DistPubServer) + '\repldata';
-- Specify the publication database.
SET @publicationDB = N'AdventureWorks2022'; 

-- Install the server MYDISTPUB as a Distributor using the defaults,
-- including autogenerating the distributor password.
USE master
EXEC sp_adddistributor @distributor = @distributor;

-- Create a new distribution database using the defaults, including
-- using Windows Authentication.
USE master
EXEC sp_adddistributiondb @database = @distributionDB, 
    @security_mode = 1;
GO

-- Create a Publisher and enable AdventureWorks2022 for replication.
-- Add MYDISTPUB as a publisher with MYDISTPUB as a local distributor
-- and use Windows Authentication.
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
-- Specify the distribution database.
SET @distributionDB = N'distribution';
-- Specify the Publisher name.
SET @publisher = $(DistPubServer);

USE [distribution]
EXEC sp_adddistpublisher @publisher=@publisher, 
    @distribution_db=@distributionDB, 
    @security_mode = 1;
GO

RMO(복제 관리 개체) 사용

단일 서버에서 게시 및 배포를 구성하려면

  1. 클래스를 사용하여 서버에 대한 연결을 만듭니다 ServerConnection .

  2. ReplicationServer 클래스의 인스턴스를 만듭니다. 1단계에서 만든 ServerConnection 을 전달합니다.

  3. DistributionDatabase 클래스의 인스턴스를 만듭니다.

  4. Name 속성을 데이터베이스 이름으로 설정하고 1단계에서 속성으로 ServerConnection 설정합니다ConnectionContext.

  5. 메서드를 호출하여 배포자를 설치합니다 InstallDistributor . 3단계에서 만든 DistributionDatabase 개체를 전달합니다.

  6. DistributionPublisher 클래스의 인스턴스를 만듭니다.

  7. 다음 속성을 DistributionPublisher설정합니다.

  1. Create 메서드를 호출합니다.

원격 배포자를 사용하여 게시 및 배포를 구성하려면

  1. 클래스를 사용하여 원격 배포자 서버에 대한 연결을 만듭니다 ServerConnection .

  2. ReplicationServer 클래스의 인스턴스를 만듭니다. 1단계에서 만든 ServerConnection 을 전달합니다.

  3. DistributionDatabase 클래스의 인스턴스를 만듭니다.

  4. Name 속성을 데이터베이스 이름으로 설정하고 1단계에서 속성으로 ServerConnection 설정합니다ConnectionContext.

  5. 메서드를 호출하여 배포자를 설치합니다 InstallDistributor . 보안 암호(원격 배포자에 연결할 때 게시자가 사용) 및 3단계의 DistributionDatabase 개체를 지정합니다. 자세한 내용은 배포자 보안을 참조하세요.

    Important

    가능한 경우 런타임 시 사용자에게 보안 자격 증명을 입력하라는 메시지가 표시됩니다. 자격 증명을 저장해야 하는 경우 Microsoft Windows .NET Framework에서 제공하는 암호화 서비스를 사용합니다.

  6. DistributionPublisher 클래스의 인스턴스를 만듭니다.

  7. 다음 속성을 DistributionPublisher설정합니다.

  1. Create 메서드를 호출합니다.

  2. 클래스를 사용하여 로컬 게시자 서버에 대한 연결을 만듭니다 ServerConnection .

  3. ReplicationServer 클래스의 인스턴스를 만듭니다. ServerConnection 9단계에서 전달합니다.

  4. InstallDistributor 메서드를 호출합니다. 5단계에서 지정한 원격 배포자의 이름과 원격 배포자의 암호를 전달합니다.

Important

가능한 경우 런타임 시 사용자에게 보안 자격 증명을 입력하라는 메시지가 표시됩니다. 자격 증명을 저장해야 하는 경우 Windows .NET Framework에서 제공하는 암호화 서비스를 사용합니다.

예제(RMO)

RMO(복제 관리 개체)를 사용하여 프로그래밍 방식으로 복제본(replica)tion 게시 및 배포를 구성할 수 있습니다.

// Set the server and database names
string distributionDbName = "distribution";
string publisherName = publisherInstance;
string publicationDbName = "AdventureWorks2022";

DistributionDatabase distributionDb;
ReplicationServer distributor;
DistributionPublisher publisher;
ReplicationDatabase publicationDb;

// Create a connection to the server using Windows Authentication.
ServerConnection conn = new ServerConnection(publisherName);

try
{
    // Connect to the server acting as the Distributor 
    // and local Publisher.
    conn.Connect();

    // Define the distribution database at the Distributor,
    // but do not create it now.
    distributionDb = new DistributionDatabase(distributionDbName, conn);
    distributionDb.MaxDistributionRetention = 96;
    distributionDb.HistoryRetention = 120;

    // Set the Distributor properties and install the Distributor.
    // This also creates the specified distribution database.
    distributor = new ReplicationServer(conn);
    distributor.InstallDistributor((string)null, distributionDb);

    // Set the Publisher properties and install the Publisher.
    publisher = new DistributionPublisher(publisherName, conn);
    publisher.DistributionDatabase = distributionDb.Name;
    publisher.WorkingDirectory = @"\\" + publisherName + @"\repldata";
    publisher.PublisherSecurity.WindowsAuthentication = true;
    publisher.Create();

    // Enable AdventureWorks2022 as a publication database.
    publicationDb = new ReplicationDatabase(publicationDbName, conn);

    publicationDb.EnabledTransPublishing = true;
    publicationDb.EnabledMergePublishing = true;
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("An error occurred when installing distribution and publishing.", ex);
}
finally
{
    conn.Disconnect();
}
' Set the server and database names
Dim distributionDbName As String = "distribution"
Dim publisherName As String = publisherInstance
Dim publicationDbName As String = "AdventureWorks2022"

Dim distributionDb As DistributionDatabase
Dim distributor As ReplicationServer
Dim publisher As DistributionPublisher
Dim publicationDb As ReplicationDatabase

' Create a connection to the server using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Try
    ' Connect to the server acting as the Distributor 
    ' and local Publisher.
    conn.Connect()

    ' Define the distribution database at the Distributor,
    ' but do not create it now.
    distributionDb = New DistributionDatabase(distributionDbName, conn)
    distributionDb.MaxDistributionRetention = 96
    distributionDb.HistoryRetention = 120

    ' Set the Distributor properties and install the Distributor.
    ' This also creates the specified distribution database.
    distributor = New ReplicationServer(conn)
    distributor.InstallDistributor((CType(Nothing, String)), distributionDb)

    ' Set the Publisher properties and install the Publisher.
    publisher = New DistributionPublisher(publisherName, conn)
    publisher.DistributionDatabase = distributionDb.Name
    publisher.WorkingDirectory = "\\" + publisherName + "\repldata"
    publisher.PublisherSecurity.WindowsAuthentication = True
    publisher.Create()

    ' Enable AdventureWorks2022 as a publication database.
    publicationDb = New ReplicationDatabase(publicationDbName, conn)

    publicationDb.EnabledTransPublishing = True
    publicationDb.EnabledMergePublishing = True

Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("An error occurred when installing distribution and publishing.", ex)

Finally
    conn.Disconnect()

End Try

참고 항목

배포자 및 게시자 속성 보기 및 수정
Replication System Stored Procedures Concepts
배포 구성
Replication Management Objects Concepts
Always On 가용성 그룹에 대한 복제 구성(SQL Server)