Background Image
Linux
2008.11.21 18:27

복제 따라하기

조회 수 29096 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

 

CUBRID 복제기능 따라하기

.소개: CUBRID2008 에서 제공하는 기능인 데이터베이스 복제 기능을 사용하기 위하여 설정과정을 간단히 보여준다.

2008-10-31 기술컨설팅팀, 허지웅CUBRID

적용 대상: CUBRID2008, Linux

복제기능 구성하기

준비 사항

동일한 OS 의 머신 2(CUBRID2008이 설치되어 있어야 한다.)

복제를 구성할 데이터베이스 : DDL 은 복제 대상이 아니므로 복제에 필요한 테이블들은 미리 생성되어 있어야 하며, 트리거는 지원되지 않으므로 트리거는 만들지 않아야 한다.

다음의 테이블을 미리 생성한다.

복제를 수행하기 위해서는 반드시 primary key 가 정의되어있어야 한다.

create class info (

    id int,

    name char(10),

    address varchar(100),

    primary key(id)

)

용어 정리

마스터 머신 : 마스터 데이터베이스가 있는 머신

슬레이브 머신 : 슬레이브 데이터베이스가 있는 머신

마스터 데이터베이스 : 복제 대상이 되는 주 데이터베이스

슬레이브 데이터베이스 : 복제가 이루어지는 데이터베이스. masterdb 의 내용이 slavedb 로 복제되어 진다.

배포 데이터베이스 : 복제를 행하기 위한 마스터 데이터베이스에 대한 정보를 가지고 있는 데이터베이스이며, 슬레이브 머신에 존재한다.

복제 서버 : 마스터 데이터베이스의 변경 내용을 복제 에이전트로 전달하는 프로세스

복제 에이전트 : 슬레이브 데이터베이스에 복제를 행하는 프로세스

복제 구성하기

마스터 데이터베이스 종료

복제를 위한 환경을 구성하기 위하여 우선 마스터 머신 상의 마스터 데이터베이스를 종료한다. 마스터 데이터베이스의 이름은 masterdb 로 가정한다.

% cubrid server start masterdb

마스터 데이터베이스 백업

데이터베이스 복제를 하기 위해서는 백업본을 이용하여 슬레이브 데이터베이스를 생성하게 되므로 마스터 데이터베이스를 전체 백업을 한다.

% cubrid backupdb –S masterdb

백업 파일 이전

슬레이브 머신으로 백업화일을 옮긴다. 이때 백업화일(masterdb_bv0v*)과 백업정보화일(masterdb_bkvinf) 을 모두 옮겨야 하며, 슬레이브 머신상에서 백업화일들을 놓아두는 위치는 마스터 머신상에서와 똑 같아야 한다. 예를 들어 마스터 머신상에서 마스터 데이터베이스의 백업정보화일이  /database/masterdb 아래에 존재 하였고 백업화일이 /backup/masterdb 아래에 존재하였다면 슬레이브 머신에도 /database/master, /backup/masterdb 의 디렉토리가 존재하야 하며 당연히 사용권한도 가지고 있어야 한다.

% ftp slave_machine

ftp> cd /database/masterdb

ftp> put masterdb_bkvinf

ftp> cd /backup/masterdb

ftp> mput masterdb_bk0v*

배포 데이터베이스 생성

슬레이브 머신상에서 마스터 데이터베이스의 정보를 보관하게 되는 배포 데이터베이스를 생성한다. 배포 데이터베이스의 위치는 사용자가 원하는 임의의 위치에 생성하면 된다. 배포 데이터베이스를 생성하는 방법은 다음과 같다.

배포 데이터베이스 생성 명령을 수행한다. 사용법은 다음과 같다

repl_make_distdb <배포 데이터베이스 이름> -p <배포 데이터베이스의 DBA 사용자 암호>

DBA 사용자 암호는 주지 않아도 된다. 하지만 보안상의 이유로 주는 것이 좋다.

배포 데이터베이스의 이름 : 생성할 배포 데이터베이스 이름의 지정하여야 하며 distdb 로 가정한다.

배포 데이터베이스 생성이 진행되면, 마스터 서버 정보를 물어오는데 마스터 데이터베이스 이름, 마스터 머신의 IP address, 복제 서버와 복제 에이전트가 통신하기 위한 통신 포트 번호 를 입력한다.

그다음 로그복사본 저장 디렉토리, trail 로그 디렉토리, 에러 로그 디렉토리를 물어오는데 이는 공간이 충분하고 사용권한을 가지고 있는 디렉토리를 지정하면 된다.

아래 예를 위하여 로그복사본 저장 디렉토리를 생성한다.

% mkdir /home/replication_logs

% repl_make_distdb distdb –p distdb_password

#########################################################################

#                                                                       #

#                Configuration of the Replication Agent                 #

#                                                                       #

#   To configure the replication environment,                           #

#        1. Configure the replication agent (using make_distdb script)  #

#        2. Back up the master database (using cubrid backup)           #

#        3. Copy the backup files to the slave site                     #

#        4. Construct the slave database (using make_slavedb script)    #

#        5. Start the repl_server at the master site                    #

#        6. Start the repl_agent at the slave site                      #

#                                                                       #

#   NOTE1: You have to back up the master database before constructing  #

#          the slave databases. If you back up the master database just #

#          before constructing the slave database, you can save the     #

#          time to synchronize the master database and slave database.  #

#          Following files should be copied to the slave site..         #

#                          -  master_db_name.bk_vinf                    #

#                          -  master_db_name.bk0v???                    #

#                                                                       #

#   NOTE2: To configure the distributor database, DBA account is        #

#          is necessary. Please provide the DBA account.                #

#                                                                       #

#   NOTE3: A distributor database should be created per slave database. #

#          Please create the distributor database and start up the      #

#          repl_agent at the slave site for the best performance.       #

#                                                                       #

#   When you stop this script using Ctrl-C, please retry again after    #

#   deleting the distributor database using 'cubrid server stop'after   #

#   then 'cubrid delete'.                                               #

#########################################################################

  STEP 1 : Creating the distributor database....

Creating database with 5000 pages.

CUBRID 2008 R1.0

  STEP 2 : Starting up the server for distributor..

  STEP 3 : Setting the DBA account of distributor database..

  STEP 4 : Creating the objects for replication...

  STEP 5 : Please provide information of the master databases ...

       1. Please enter the name of the master database >> masterdb

       2. Please enter the IP address of the master database.

          - Replication would not work without correct IP address.

                IP address of the master >> 10.31.14.206

       3. Please enter the TCP/IP port number of the repl_server >> 5621

       4. Please enter the directory path of copy log.

         If the target directory is /home/Rel_test, just strike enter.. >> /home/replicatoin_logs

  STEP 6 : Configuring the replication parameters..

       1. Please enter the directory path of trail log.

         If the target directory is /home/Rel_test, just strike enter.. >> /home/replicatoin_logs

       2. Please enter the directory path of error log.

         If the target directory is /home/Rel_test, just strike enter.. >> /home/replicatoin_logs

       3. Please enter the TCP/IP port number for information of repl_agent status. >> 5622

       4. Please enter the file size(line number) of replication delay time log. >>

배포 데이터베이스의 생성이 완료되면, 배포 데이터베이스가 구동되어 있다. cub_commdb –P 명령으로 확인할 수 있다.

% cub_commdb -P

 Server distdb (rel 8.1, pid 22086)

슬레이브 데이터베이스 생성

배포 데이터베이스 생성이 완료되면 슬레이브 데이터베이스를 생성한다. 슬레이브 데이터베이스는 마스터 데이터베이스의 백업본을 이용하여 생성되므로 마스터 데이터베이스의 구성과 동일한 환경을 슬레이브 머신상에 구성해놓아야 한다. 예를 들어 마스터 데이터베이스가 /database/masterdb 아래에 존재하고 있다면 슬레이브 머신상에도 같은 디렉토리가 존재하여야 하며 당연히 사용가능하여야 한다. 슬레이브 데이터베이스를 생성하는 방법은 다음과 같다.

마스터 데이터베이스 의 구성 환경과 동일하게 슬레이브 머신상에 디렉토리를 구성하고, 사용권한을 준다. root 에서 작업이 필요할 수 있다.

% mkdir /database/masterdb

% chown <user_id>:<user_group> /database/masterdb

슬레이브 데이터베이스 생성 명령을 수행한다. 이때 앞서 마스터 서버에서 가져다 놓은 마스터 데이터베이스의 백업 정보화일(masterdb_bkvinf) 가 존재하는 디렉토리에서 수행하여야 한다.

% cd /database/masterdb

슬레이브 데이터베이스 생성 명령의 사용방법은 다음과 같다.

repl_make_slavedb <마스터 데이터베이스 이름> <슬레이브 데이터베이스 이름> -u <슬레이브 데이터베이스 사용자 아이디> -p <슬레이브 데이터베이스 사용자 암호>

슬레이브 데이터베이스의 볼륨이 저장될 디렉토리는 마스터 데이터베이스의 볼륨이 저장된 디렉토리와 동일하게 입력하여야 한다.

마찬가지로 슬레이브 데이터베이스의 로그가 저장될 디렉토리 역시 마스터 데이터베이스의 로그가 저장된 디렉토리와 동일하게 입력한다.

배포 데이터베이스 이름은 조금전에 생성한 배포 데이터베이스의 이름을 입력한다.

배포 데이터베이스의 DBA 암호는 조금전 생성시 지정한 암호를 입력한다.

마스터 데이터베이스의 DBA 암호는 암호가 있는 경우에는 입력하고, 그렇지 않은 경우에는 그냥 엔터키만 입력한다.

% repl_make_slavedb masterdb slavedb -u repl2 -p repl2

#########################################################################

#                                                                       #

#                    Constructing the slave database                    #

#                                                                       #

#   To configure the replication environment,                           #

#        1. Configure the replication agent (using make_distdb script)  #

#        2. Back up the master database (using cubrid backup)           #

#        3. Copy the backup files to the slave site                     #

#        4. Construct the slave database (using make_slavedb script)    #

#        5. Start the repl_server at the master site                    #

#        6. Start the repl_agent at the slave site                      #

#                                                                       #

#   NOTE1: Please create and configure the distributor database         #

#          using make_distdb script before executing this script.       #

#   NOTE2: Please back up the master database before constructing       #

#          the slave databases. If you back up the master database just #

#          before constructing the slave database, you can save the     #

#          time to synchronize the master database and slave database.  #

#          Following files should be copied to the slave site..         #

#                          -  master_db_name.bk_vinf                    #

#                          -  master_db_name.bk0v???                    #

#   NOTE3: It's necessary to execute this script at the directory       #

#          in which the backup files locate.                            #

#                                                                       #

#   When you stop this script using Ctrl-C, please retry again after    #

#   deleting the distributor database using cubrid server stop and      #

#   then cubrid delete.                                                 #

#########################################################################

  STEP 1 : Preprocess to restore the master database...

       a. Please provide the directory path of data volume.

           Just enter if the target directory is /home/master >> /home/slavedb

       b. Please provide the directory path of log volume.

           Just enter if the target directory is /home/master >> /home/slavedb

  STEP 2 : Restore the master database backup to make the slave database...

          - Backup files and volume information file should be

            in the current directory.

          - Now, restoring the master database backup, please wait a moment...

          - Slave database is created.

  STEP 3 :  Insert the necessary information into the distributor database...

       a. Provide the name of the distributor database. >> distdb

       b. Provide the password of the DBA of distributor database. >> distdb_password

  STEP 4 : Start the slave database ...

  STEP 5 : Post process after starting up the slave database...

          - the DBA password of the master database is needed..

          - Provide the DBA password of the master database. >> dba_password

  STEP 6 : Set the replication parameters...

        1. perf_poll_interval         - preformance polling interval(sec)

        2. size_of_log_buffer         - log buffer size of repl_agent

        3. size_of_cache_buffer       - cache buffer size of the repl_agent

        4. size_of_copylog            - page count of the copy log

        5. index_replication          - 'y' for index replication

        6. for_recovery               - 'y' for recovery mode

        7. log_apply_interval         - interval between log page fetches(sec)

        8. restart_interval           - interval between connections to the slave(sec)

-- Parameter Number to be changed (q - quit ) >> q

STEP 7 : Set the replication group ...

MASTER_HOST : 10.31.14.206

-------------------------------------------------------------------------

  All the classes of masterdb are included in the replication group.

  Would you like to reset the replication group? (y or n) >> n

-------------------------------------------------------------------------

복제 서버 구동

마스터 데이터베이스를 구동한 후, 복제 서버를 구동한다. 이때 –d 다음에 마스터 데이터베이스의 이름을 넣고, -p 다음에 통신 포트를 주는데 이 포트는 배포 데이터베이스 생성시 입력한 포트 번호를 입력하여야 한다.

% cubrid server start masterdb

% repl_server –d masterdb –p 5621

복제 에이전트 구동

마지막으로 복제 에이전트를 구동한다. 이때 –d 다음에 배포 데이터베이스의 이름을 넣고, -p 다음에 배포 데이터베이스의 DBA 암호를 입력한다.

% repl_agent –d distdb –p dist_password

복제 하기

마스터 데이터베이스에 cubrid.conf 를 이용하여 접근하여 SQL 을 수행하면서 슬레이브 데이터베이스에 복제가 되었는지 확인한다. 앞에서 언급한 것 처럼 해당 테이블들은 이미 생성이 되어 있어야 한다.

입력

마스터 데이터베이스에서 esql를 이용하여 아래 SQL 을 수행하여 데이터를 입력한다.

csql> insert into info values(1, ‘홍길동’, ‘성남시 분당구 서현동’)

csql> insert into info values(2, ‘홍길순’, ‘성남시 분당구 서현동’)

슬레이브 데이터베이스에서 검색을 통하여 데이터가 입력된 것을 확인한다.

csql> select * from info

csql> ;x

=== <Result of SELECT Command in Line 1> ===

           id  name                  address

=========================================================

            1  '홍길동    '          ' 성남시 분당구 서현동'

            2  '홍길순    '          ' 성남시 분당구 서현동'

2 rows selected.

수정

마스터 데이터베이스에서 아래 SQL 을 수행하여 데이터를 수정한다.

csql> update info set address = ‘성남시 분당구 정자동’ where name = ‘홍길동

슬레이브 데이터베이스에서 검색을 통하여 데이터가 수정된 것을 확인한다.

csql> select * from info

csql> ;x

=== <Result of SELECT Command in Line 1> ===

           id  name                  address

=========================================================

            1  '홍길동    '          ' 성남시 분당구 정자동'

            2  '홍길순    '          ' 성남시 분당구 서현동 '

2 rows selected.

삭제

마스터 데이터베이스에서 아래 SQL 을 수행하여 데이터를 삭제한다.

csql> delete from info where name = ‘홍길순

슬레이브 데이터베이스에서 검색을 통하여 데이터가 수정된 것을 확인한다.

csql> select * from info

csql> ;x

=== <Result of SELECT Command in Line 1> ===

           id  name                  address

=========================================================

            1  '홍길동    '          ' 성남시 분당구 정자동'

1 rows selected.


List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
166 기타 [10.2 path] - 생성된 view구문을 'show create view' 수행 시 정상적으로 출력되지 않던 이슈 patch 큐브리드_김주현 2020.11.09 886
165 기타 큐브리드10.1 에서 윤초 지원 옵션 사용하기 최광일 2017.09.13 1419
164 Linux <주의> 생성한 DB볼륨을 절대! 삭제하지 말자 큐브리드_김주현 2019.09.30 1598
163 Install [linux] wget으로 제품 다운로드 시 "wget: unable to resolve host address ‘ftp.cubrid.org’" 해결방 큐브리드_김주현 2021.07.02 2264
162 기타 ERwin을 이용한 CUBRID 포워드 엔지니어링 file 민순 2020.07.14 2316
161 기타 따라하면 쉬운 compactdb 사용법 file 허서진 2017.07.01 2528
160 기타 ERwin을 이용한 CUBRID 리버스 엔지니어링 file 민순 2020.07.13 3462
159 Java JDBC를 사용한 다중화 구성 SELECT Query 부하 분산 가이드 file 윤준수 2017.03.30 3946
158 튜닝 다중컬럼 조건에 대한 인라인뷰 처리방안 2 박동윤 2016.12.27 6012
157 기타 PyCharm을 이용한 CUBRID, Django 연동 가이드 file 진우진 2016.04.11 8152
156 Java CUBRID에서 Java AddBatch 사용 엄기호 2016.06.28 8365
155 기타 CUBRID Migration Toolkit을 이용한 단계별 마이그레이션 진행 방법 file 진우진 2015.12.15 9542
154 PHP CUBRID HA 환경에서 Apache-PHP 설정 가이드 이용미 2015.06.16 10665
153 기타 CUBRID isolation level & Dirty Read 정만영 2015.05.29 11314
152 기타 알고 보면 쉬운 cubrid lockdb 유틸리티 file 김승훈 2015.12.08 12076
151 Windows Windows 에 설치 된 JRE 설치 위치 확인 하기. file 성진 2015.05.28 12571
150 기타 데이터 확인에 정규표현식을 사용 해 보자. 성진 2016.03.01 12759
149 기타 CUBRID 2008 R4.0 파라미터 변경 사항 (일부) file admin 2011.07.14 13154
148 Linux 가상머신 환경에서 리눅스 및 큐브리드 설치 가이드 file 이경오 2015.07.14 13399
147 기타 콘솔에서 마이그레이션 하기. file 권호일 2015.06.19 13432
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales