728x90
MySQL Replication 구성(MySQL 복제)
MySQL 환경 설정(my.cnf)
Hostname | node1 | node2 |
Role | master | slave |
my.cnf | ### my.cnf(/usr/local/mysql/my.cnf) [mysqld] bind-address = 0.0.0.0 port = 3306 user = mysql basedir = /usr/local/mysql datadir = /usr/local/mysql/data socket = /tmp/mysql.sock pid-file = /var/run/mysqld/mysqld.pid log-error = /usr/local/mysql/data/error.log log-error-verbosity = 3 symbolic-links = 0 explicit_defaults_for_timestamp = 1 server-id = 1 log-bin = mysql-bin binlog-format = ROW expire_logs_days = 2 #skip-grant-tables [client] port = 3306 socket = /tmp/mysql.sock |
### my.cnf(/usr/local/mysql/my.cnf) [mysqld] bind-address = 0.0.0.0 port = 3306 user = mysql basedir = /usr/local/mysql datadir = /usr/local/mysql/data socket = /tmp/mysql.sock pid-file = /var/run/mysqld/mysqld.pid log-error = /usr/local/mysql/data/error.log log-error-verbosity = 3 symbolic-links = 0 explicit_defaults_for_timestamp = 1 server-id = 2 log-bin = mysql-bin binlog-format = ROW expire_logs_days = 2 relay_log = relay-bin log_slave_updates = 1 read_only = 1 #skip-grant-tables [client] port = 3306 socket = /tmp/mysql.sock |
Start | mysqld_safe --defaults-file=/usr/local/mysql/my.cnf & | |
Shutdown | mysqladmin -u root shutdown --socket /tmp/mysql.sock |
마스터 서버
- bin-log(File) 파일 및 Position 확인
mysql -h localhost -uroot -p'mysqlpassword' -e "show master status\G" | egrep 'File|Position'
$ mysql -h localhost -uroot -p'mysqlpassword' -e "show master status\G" | egrep 'File|Position'
mysql: [Warning] Using a password on the command line interface can be insecure.
File: mysql-bin.000007
Position: 154
슬레이브 서버
- 복제 중지
mysql -h localhost -uroot -p'mysqlpassword' -e "stop slave"
- 복제 설정을 재설정
mysql -h localhost -uroot -p'mysqlpassword' -e "reset slave"
- 슬레이브 복제 설정
mysql -h localhost -uroot -p'mysqlpassword' -e "
CHANGE MASTER TO
MASTER_HOST='192.168.56.101',
MASTER_USER='replication_user',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000007',
MASTER_LOG_POS=154;
"
$ mysql -h localhost -uroot -p'mysqlpassword' -e "
CHANGE MASTER TO
MASTER_HOST='192.168.56.101',
MASTER_USER='replication_user',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000007',
MASTER_LOG_POS=154;
"
mysql: [Warning] Using a password on the command line interface can be insecure.
- 슬레이브 서버 다시 시작
mysql -h localhost -uroot -p'mysqlpassword' -e "start slave"
$ mysql -h localhost -uroot -p'mysqlpassword' -e "start slave"
mysql: [Warning] Using a password on the command line interface can be insecure.
728x90
- 슬레이브 상태 확인
mysql -hlocalhost -uroot -p'mysqlpassword' -e "show slave status\G" | egrep 'Slave_IO_Running|Slave_SQL_Running|Seconds_Behind_Master'
$ mysql -hlocalhost -uroot -p'mysqlpassword' -e "show slave status\G" | egrep 'Slave_IO_Running|Slave_SQL_Running|Seconds_Behind_Master'
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
mysql -hlocalhost -uroot -p'mysqlpassword' -e "show slave status\G"
$ mysql -hlocalhost -uroot -p'mysqlpassword' -e "show slave status\G"
mysql: [Warning] Using a password on the command line interface can be insecure.
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.101
Master_User: replication_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 154
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000007
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: 154
Relay_Log_Space: 521
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 1e320772-f6c4-11ed-a93d-0800278c2c47
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
마스터 서버
- 슬레이브 호스트 확인
mysql -h localhost -uroot -p'mysqlpassword' -e "SHOW SLAVE HOSTS"
$ mysql -h localhost -uroot -p'mysqlpassword' -e "SHOW SLAVE HOSTS"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID |
+-----------+------+------+-----------+--------------------------------------+
| 3 | | 3306 | 1 | 8802cba8-f8ab-11ed-aa0c-080027dcd0c8 |
| 2 | | 3306 | 1 | 81a1c980-f8ab-11ed-9f7e-0800273d1990 |
+-----------+------+------+-----------+--------------------------------------+
728x90
'리눅스' 카테고리의 다른 글
[draft] 우분투에서 고정 IP 주소를 설정하는 방법 (0) | 2023.05.26 |
---|---|
MHA NodeUtil.pm 에러 (0) | 2023.05.24 |
[리눅스] MySQL MHA 원복(mha failback) (0) | 2023.05.23 |
MySQL에서 리플리케이션을 다시 연결하는 방법 (0) | 2023.05.23 |
[리눅스] MySQL에서 신규 데이터베이스를 생성하고 데이터를 추가하고 조회하는 방법 (0) | 2023.05.23 |