Server/DB

MySQL Replication

체리필터 2013. 5. 15. 10:39
728x90
반응형

Replication을 한개의 물리적 서버에서 테스트 하기 위해 설치할 필요가 있었다.

이를 위해 다음과 같은 셋팅으로 설정하였는데, 자료 아카이빙을 위해 정리해 본다.


기본적인 것은 아래와 같다.


1. 한개의 서버에 두개의 MySQL을 설치한다.

2. 각각 다른 Port를 사용한다.

3. Master, Slave 설정을 하고 Replication을 시작한다.


자세하게 기술하면 아래와 같다.


1. configure를 통해 master mysql 설치 디렉토리를 지정한다.


ex)

./configure --prefix=/설치디렉토리/mysql_master --with-charset=utf8 --enable-assembler


2. make, make install을 통해 설치한다.


3. master db가 설치가 완료 되었으면, slave db를 설치한다.


ex)

./configure --prefix=/설치 디렉토리/mysql_slave --with-charset=utf8 --enable-assembler


4. master db의 config 설정을 위해 mysql_master 디렉토리 아래 my.cnf 파일을 다음과 같이 만든다. (필요한 내용만 기재)


[mysqld]

datadir=/설치디렉토리/mysql_master/var

socket=/설치디렉토리/mysql_master/tmp/mysql.sock

server-id=1

log-bin=/설치디렉토리/mysql_master/var/replication.log

binlog-do-db = xe

port=3306


5. slave db의 config 설정을 위해 mysql_slave 디렉토리 아래 my.cnf 파일을 다음과 같이 만든다. (필요한 내용만 기재)


[mysqld]

datadir=/home1/irteam/db/mysql_slave/var

socket=/home1/irteam/db/mysql_slave/tmp/mysql.sock

server-id=2

port=3307


7. 각 서버를 기동한다.


8. Master와 Slave의 상태를 본다.


ex)

./mysql -uroot --socket=/설치디렉토리/mysql_master/tmp/mysql.sock


mysql> show master status;

+--------------------+----------+--------------+------------------+

| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+--------------------+----------+--------------+------------------+

| replication.000002 |   346615 | xe           |                  |

+--------------------+----------+--------------+------------------+

1 row in set (0.00 sec)


./mysql -uroot -p --socket=/설치디렉토리/mysql_slave/tmp/mysql.sock


mysql> show slave status \G

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 127.0.0.1

                  Master_User: replmon

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: replication.000002

          Read_Master_Log_Pos: 346615

               Relay_Log_File: dev-xemysql-relay-bin.001029

                Relay_Log_Pos: 253

        Relay_Master_Log_File: replication.000002

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB: 

          Replicate_Ignore_DB: 

           Replicate_Do_Table: 

       Replicate_Ignore_Table: 

      Replicate_Wild_Do_Table: 

  Replicate_Wild_Ignore_Table: 

                   Last_Errno: 0

                   Last_Error: 

                 Skip_Counter: 0

          Exec_Master_Log_Pos: 346615

              Relay_Log_Space: 561

              Until_Condition: None

               Until_Log_File: 

                Until_Log_Pos: 0

           Master_SSL_Allowed: No

           Master_SSL_CA_File: 

           Master_SSL_CA_Path: 

              Master_SSL_Cert: 

            Master_SSL_Cipher: 

               Master_SSL_Key: 

        Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error: 

               Last_SQL_Errno: 0

               Last_SQL_Error: 

1 row in set (0.00 sec)


9. Slave 서버에서 master의 위치정보를 변경하고자 할 경우에는 다음과 같은 명령어를 날린다.


change master to master_host='127.0.0.1' , master_port = 3306, master_user='replmon', master_password='12345';





728x90
반응형

'Server > DB' 카테고리의 다른 글

MySQL Erro Code 28이 리턴되는 경우  (2) 2009.04.08
MySQL의 백업 및 복구  (2) 2008.12.15
MySQL에서 대소문자 구별해서 쿼리하기  (0) 2007.05.15
Z와 S의 차이...  (2) 2007.02.14
MySQL에서 변수의 사용...  (2) 2006.12.18