복제 Replication

mysql 2018.12.19 17:24


Slave IO Thread

- 마스터 DBMS에 로그인해서 바이너리로그를 읽어 릴레이로그에 쓰는 쓰레드


Slave SQL Thread

- 릴레이로그에서 실제 슬레이브 DBMS에 반영하는 쓰레드


docker run -d -e MYSQL_ROOT_PASSWORD=sample --name=master mariadb:10.1

docker run -d -e MYSQL_ROOT_PASSWORD=sample --name slave mariadb:10.1


docker inspect master | grep "IPAddress"

docker inspect slave | grep "IPAddress"


docker exec -it master bash


cd /etc/mysql


my.cnf/my.ini


master

[mysqld]

pid-file = /var/run/mysqlid/mysqlid.pid

socket = /var/run/mysql/mysqlid.sock

datadir = /var/lib/mysql

log-error = /var/log/mysql/error.log 

symbolic-links = 0

bind-address = 0.0.0.0

server-id = 1

log_bin = /var/log/mysql/mysql-bin.log

expire_logs_days = 10

max_binlog_size = 100M 



docker exec -it slave bash


cd /etc/mysql


my.cnf/my.ini


slave

[mysqld]

pid-file = /var/log/mysqld/mysqld.pid

socket = /var/run/mysqld/mysqld.dock

datadir = /var/lib/mysql

log-error = /var/log/mysql/error.log 

symbloic-links = 0

bind-address = 0.0.0.0

server-id = 2

relay-log = /var/log/mysql/relay.log

relay_log_purge = TRUE

read_only



sudo service mysql restart


$ docker commit -m "xxx" -a "aaa" master master_new

$ docker commit -m "xxx" -a "aaa" slave slave_new


$ docker images


$ docker run -d -e MYSQL_ROOT_PASSWORD=sample --name=master_new master_new

$ docker run -d -e MYSQL_ROOT_PASSWORD=sample --name=slave_new slave_new


$ docker rm -f master

$ docker rm -f slave


$ docker ps -a


$ docker inspect master_new | grep "IPAddress"

$ docker inspect slave_new | grep "IPAddress"


$ docker exec -it master_new bash


create user 'replicationuser1'@'%' identified by 'sample';


grant replication slave, replication client on *.* to 'replicationuser1'@'%' identified by 'slavepass';


flush privileges;


master 상태 확인

show master status;


master db 덤프 후 slave로 복사


# docker exec -it master_new bash

mysqldump -lock-all-tables -all-databases -master-data=1 -uroot -p > dump.sql


# docker cp master_new:/dump.sql . 

# docker cp dump.sql slave_new:/


slave


# docker exec -it slave_new bash


mysql-uroot -p < dump.sql


change master to master_log='mariadb-bin.001482' master_log_pos=4415249, master_host='172.17.0.x', master_port=3306, master_user='replicationuser1', master_password='slavepass';


show slave status;

-> Slave_IO_Running

-> Slave_SQL_Running


start slave;


show slave status;

-> Slave_IO_Running

-> Slave_SQL_Running



'mysql' 카테고리의 다른 글

복제 Replication  (0) 2018.12.19
show processlist 에 where 조건 사용하기  (0) 2018.12.19
샤딩 sharding  (0) 2018.12.19
트랜잭션 Transcation, 락 Lock, 격리수준 IsolationLevel  (0) 2018.12.18
파티셔닝 Partitioning  (0) 2018.12.17
Azure Linux VM에서 MySQL 성능 최적화  (0) 2016.06.16
Trackbacks 0 : Comments 0