replication

MySQL, MariaDB 2018. 6. 26. 10:06

1. A의 모든 DB를 B로 복제



A : 

mysqldump -u root -p --all-databases > all.sql


B : 


mysql -u root -p < all.sql




2. 마스터와 슬레이브 설정



A. 마스터 설정


설정파일  : /etc/my.cnf.d/server.cnf


서버아이디는 1로 설정


로그파일은 mysql-bin.000001 과 같은 형태로 생성됨




[mysqld]


server_id = 1


log-bin=mysql-bin

expire_logs_days=7





replication 사용자 등록


마스터 호스트 : 192.168.0.1

사용자 : repl

비밀번호 : 12345



MariaDB [mysql]> grant select, reload, lock tables, replication slave, replication client on *.* to 'repl@'192.168.0.1' identified by '12345';ant select, reload, lock tables, replication slave, replication client on *.* to 'id'@'slave ip address' identified by 'password';

MariaDB [mysql]> flush privileges;







B. 슬레이브 설정



설정파일 : /etc/my.cnf.d/server.cnf


서버아이디 : 2 로 설정


로그파일은  mysql-relay-bin.000001 과 같은 형식으로 생성됨


[mysqld]



server_id = 2

relay_log = mysql-relay-bin







3. replication


마스터 정보 확인


A : 


MariaDB [mysql]> show master status \G;

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

            File: mysql-bin.000001

        Position: 104060378

    Binlog_Do_DB: 

Binlog_Ignore_DB: 

1 row in set (0.00 sec)


ERROR: No query specified






마스터의 로그파일 : mysql-bin.000001

로그 포지션 : 104060378




B : 설정



MariaDB [mysql]> stop slave;


MariaDB [mysql]> change master to 

master_host = '192.168.0.1',

master_user = 'repl',

master_password = '12345',

master_log_file = 'mysql-bin.000001',

master_log_pos = 104060378

;


MariaDB [mysql]> start slave;





슬레이브 상태 확인


MariaDB [mysql]> show slave status \G;

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

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.0.1

                  Master_User: repl

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000001

          Read_Master_Log_Pos: 662570599

               Relay_Log_File: mysql-relay-bin.000001

                Relay_Log_Pos: 42800785

        Relay_Master_Log_File: mysql-bin.000001

             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: 43002550

              Relay_Log_Space: 662370967

              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: 416430

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error: 

               Last_SQL_Errno: 0

               Last_SQL_Error: 

  Replicate_Ignore_Server_Ids: 

             Master_Server_Id: 1

               Master_SSL_Crl: 

           Master_SSL_Crlpath: 

                   Using_Gtid: No

                  Gtid_IO_Pos: 

      Replicate_Do_Domain_Ids: 

  Replicate_Ignore_Domain_Ids: 

                Parallel_Mode: conservative

                    SQL_Delay: 0

          SQL_Remaining_Delay: NULL

      Slave_SQL_Running_State: updating

1 row in set (0.00 sec)


ERROR: No query specified


MariaDB [mysql]> 






mysql 디비 디렉토리에 가 보면,

아래와 같이 로그파일이 생성되어 있다.



-rw-rw----. 1 mysql mysql  47888824  6월 26 10:03 mysql-bin.000001

-rw-rw----. 1 mysql mysql        19  6월  7 11:22 mysql-bin.index

-rw-rw----. 1 mysql mysql       309  6월 21 09:02 mysql-relay-bin.000001

-rw-rw----. 1 mysql mysql       150  6월 26 10:03 mysql-relay-bin.index






끝.















블로그 이미지

엘로드넷

,