게시 및 배포 구성

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

항목 내용

  • 시작하기 전 주의 사항

    보안

  • 게시 및 배포를 구성하려면:

    SQL Server Management Studio

    Transact-SQL

    RMO(복제 관리 개체)

시작하기 전 주의 사항

보안

자세한 내용은 안전한 배포(복제)를 참조하십시오.

맨 위로 이동 링크와 함께 사용되는 화살표 아이콘[맨 위]

SQL Server Management Studio 사용

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

배포를 구성하려면

  1. Microsoft SQL Server Management Studio에서 배포자가 될 서버에 연결한 다음 서버 노드를 확장합니다. 게시자와 배포자가 같은 서버인 경우가 많습니다.

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

  3. 배포 구성 마법사에 따라 다음을 수행하십시오.

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

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

    • 로컬 배포자에 대해 루트 스냅숏 폴더를 지정합니다. 스냅숏 폴더는 공유하도록 지정된 디렉터리일 뿐이며 이 폴더에 읽기/쓰기 작업을 수행하려면 에이전트에게 충분한 액세스 권한이 있어야 합니다. 이 배포자를 사용하는 각 게시자는 루트 폴더 아래에 폴더를 만들고, 각 게시는 스냅숏 파일을 저장할 게시자 폴더 아래에 폴더를 만듭니다. 폴더의 적절한 보안 유지 방법은 스냅숏 폴더 보안 설정을 참조하십시오.

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

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

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

맨 위로 이동 링크와 함께 사용되는 화살표 아이콘[맨 위]

Transact-SQL 사용

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

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

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

    • 결과 집합의 installed 값이 0인 경우 master 데이터베이스의 배포자에서 sp_adddistributor(Transact-SQL)를 실행합니다.

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

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

  3. 게시자에서 sp_replicationdboption(Transact-SQL)을 실행합니다. 이때 @dbname에 게시할 데이터베이스를 지정하고 @optname에 복제 유형을 지정하며 @value에 true 값을 지정합니다.

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

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

    • 결과 집합의 installed 값이 0인 경우 master 데이터베이스의 배포자에서 sp_adddistributor(Transact-SQL)를 실행합니다. 이때 @password에 강력한 암호를 지정합니다. 이는 distributor_admin 계정의 암호로 배포자에 연결할 때 게시자에서 사용됩니다.

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

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

  3. master 데이터베이스의 게시자에서 sp_adddistributor(Transact-SQL)를 실행합니다. 이때 @password에 1단계에서 사용한 강력한 암호를 지정합니다. 이 암호는 배포자에 연결할 때 게시자에서 사용됩니다.

  4. 게시자에서 sp_replicationdboption(Transact-SQL)을 실행합니다. 이때 @dbname에 게시할 데이터베이스를 지정하고 @optname에 복제 유형을 지정하며 @value에 true 값을 지정합니다.

예(Transact-SQL)

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

-- 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'AdventureWorks2012'; 

-- 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 AdventureWorks2012 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 속성을 데이터베이스 이름으로 설정하고 ConnectionContext 속성을 1단계에서 만든 ServerConnection으로 설정합니다.

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

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

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

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

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

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

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

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

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

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

    보안 정보보안 정보

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

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

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

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

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

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

  11. InstallDistributor 메서드를 호출합니다. 5단계에서 지정된 원격 배포자 이름 및 원격 배포자 암호를 전달합니다.

    보안 정보보안 정보

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

예(RMO)

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

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

            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 AdventureWorks2012 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 occured 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 = "AdventureWorks2012"

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 AdventureWorks2012 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 occured when installing distribution and publishing.", ex)

Finally
    conn.Disconnect()

End Try

맨 위로 이동 링크와 함께 사용되는 화살표 아이콘[맨 위]

참고 항목

개념

게시자 및 배포자 속성 보기 및 수정

게시 및 배포 구성

복제 시스템 저장 프로시저 개념

배포 구성

복제 관리 개체 개념

AlwaysOn 가용성 그룹에 대한 복제 구성(SQL Server)