http://foxrain93.blog.me/100192636540
최소 2개의 db server 와 monistoring server가 필요하다.
서버 종류 | ip | hostname | server id |
monitoring host | 192.168.0.10 | mon | - |
master 1 | 192.168.0.11 | db1 | 1 |
master 2 | 192.168.0.12 | db2 | 2 |
master 1 환경 설정
# vi /etc/my.cnf
-------------------------------------------
server_id = 1
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-relay-bin
relay_log_index = /var/log/mysql/mysql-relay-bin.index
expire_logs_days = 10
max_binlog_size = 100M
log_slave_updates = 1
# bind-address = 127.0.0.1
삭제 하고
bind-address = 0.0.0.0
auto_increment_increment = 2 // master 서버의 수 설정
auto_increment_offset = 1 // 각 서버에서 auto_increment_increment 보다 적은(less than) 수로 unique 하게 설정
----------------------------------------------------------------
# /etc/init.d/mysqld restart
error : ~ file '/var/log/mysql/mysql-bin.log.index' not found 로 재구동이 안될경우
->
# mkdir /var/log/mysql
# chown -R mysql.mysql /var/log/mysql
# chmod -R 755 /var/log/mysql
mysql 사용자 생성
mysql> GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.0.%' IDENTIFIED BY 'monitor_password';
mysql> GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.0.%' IDENTIFIED BY 'agent_password';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication_password';
백업을 위해 데이터 변경을 금지한다.
mysql> FLUSH TABLES WITH READ LOCK;
상태값을 기억한다.
mysql> SHOW MASTER STATUS;
백업을 하는동안 mysql-shell 을 닫으면 안된다. 위에서한 lock이 해제된다.
# mysqldump -u root -p --all-databases > /tmp/database-backup.sql
mysql> UNLOCK TABLES;
다른 db 서버로 옮긴후 import 한다,
# mysql -u root -p < /tmp/database-backup.sql
권한을 새로이 적용한다
mysql> FLUSH PRIVILEGES;
mysql> CHANGE MASTER TO master_host='192.168.0.11', master_port=3306, master_user='replication', master_password='replication_password', master_log_file='<file>', master_log_pos=<position>;
(error)
// log를 보면 mysql slave failed to open the relay log 이렇게 나온다. 이럴 경우,
mysql> FLUSH LOGS;
mysql> RESET SLAVE;
mysql> CHANGE MASTER TO master_host='192.168.0.11', master_port=3306, master_user='replication', master_password='replication_password', master_log_file='<file>', master_log_pos=<position>;
// 오류가 없으면,
mysql> SLAVE START;
mysql> SHOW SLAVE STATUS\G
이제 반대로 replication 을 실행해야 한다.
mysql> SHOW MASTER STATUS;
// 새 파일과 위치를 기억한다.
db1으로 가서 명령을 실행한다. db2 에서 기억한 SHOW MASTER STATUS의 <file>, <position> 을 입력한다.
mysql> CHANGE MASTER TO master_host = '192.168.0.12', master_port=3306, master_user='replication', master_password='replication_password', master_log_file='<file>', master_log_pos=<position>;
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS\G
# vi /etc/sysconfig/iptables
--------------------------------------
// agent, monitor, tools
-A INPUT -s 192.168.10.0/24 -m state --state NEW -p tcp --dport 3306 -j ACCEPT
// agent, monitor
-A INPUT -s 192.168.10.0/24 -m state --state NEW -p tcp --dport 9989 -j ACCEPT
// tools
-A INPUT -s 192.168.10.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT
---------------------------------------
MMM 설치
모든 host 에서,
# useradd --comment "MMM Script owner" --shell /sbin/nologin mmmd
Monitoring host 에서,
# yum install mysql-mmm mysql-mmm-monitor
Database hosts 에서,
# yum install mysql-mmm mysql-mmm-agent
MMM 환경 설정
모든 host에서,
# vi /etc/mysql-mmm/mmm_common.conf
--------------------------------------------------
active_master_role writer
<host default>
# cluster에서 사용할 장비 설정
cluster_interface eth0
pid_path /var/run/mysql-mmm/mmm_agentd.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replication
replication_password replication_password
agent_user mmm_agent
agent_password agent_password
</host>
<host db1>
ip 192.168.0.11
mode master
peer db2
</host>
<host db2>
ip 192.168.0.12
mode master
peer db1
</host>
# slave 및 추가 장비들
#<host db3>
# ip 192.168.0.13
# mode slave
#</host>
#<host db4>
# ip 192.168.0.14
# mode slave
#</host>
<role writer>
hosts db1, db2
ips 192.168.0.250
mode exclusive
</role>
<role reader>
hosts db1, db2
ips 192.168.0.251, 192.168.0.252
mode balanced
</role>
--------------------------------------------------
Database hosts 에서, (db1 일 경우)
# vi /etc/mysql-mmm/mmm_agent.conf
---------------------------------------------------
include mmm_common.conf
this db1
---------------------------------------------------
Monitor host 에서
# vi /etc/mysql-mmm/mmm_mon.conf
-------------------------------------------------------
include mmm_common.conf
<monitor>
ip 127.0.0.1
pid_path /var/run/mysql-mmm/mmm_mond.pid
bin_path /usr/libexec/mysql-mmm/
status_path /var/lib/mysql-mmm/mmm_mond.status
# ping_ips 는 monitor 가 network connection이 ok 상태인지 ping해보는 ip 이다. ping 이 가능한 서버들을 리스트한다.
ping_ips 192.168.0.1, 192.168.0.11, 192.168.0.12
auto_set_online 60
</monitor>
<host default>
monitor_user mmm_monitor
monitor_password monitor_password
</host>
debug 0
-------------------------------------------------------
MMM 구동
Database hosts 에서,
(Debian/Ubuntu)
# vi /etc/default/mysql-mmm-agent
-----------------------------------
ENABLED=1
-----------------------------------
(Red Hat)
# chkconfig mysql-mmm-agent on
# /etc/init.d/mysql-mmm-agent start
Monitor host 에서,
# vi /etc/default/mysql-mmm-monitor
------------------------------------
ENABLED=1
-------------------------------------
# chkconfig mysql-mmm-monitor on
# /etc/init.d/mysql-mmm-monitor start
[출처] Mysql MMM 의 설치|작성자 진저티
'연구개발 > MYSQL' 카테고리의 다른 글
rand 함수를 이용한 정해진 자릿수 숫자 만들기 (0) | 2014.08.28 |
---|---|
Mysql MMM error 처리 (0) | 2014.08.28 |
character-set utf8mb4 사용시 replication slave 구성 주의사항 (0) | 2014.08.28 |
MySQL 날짜 함수 정리 (0) | 2014.08.12 |
xtrabackup (0) | 2014.08.08 |