database - MySQL Master-Slave Replication When Master is Down -
i'm running mysql database on ubuntu instances. i'm using mysql master-slave replication master's changes written slave , slave's changes not reflected on master. that's fine. i'm using haproxy load balancer front mysql instances requests sent master mysql instance. if master mysql instance down slave mysql instance act master , haproxy send requests salve. active-passive scenario.
haproxy - 192.168.a.abc mysql master - 192.168.a.abd mysql slave - 192.168.a.abe
let's assume mysql master(192.168.a.abd) down. requests sent mysql slave(192.168.a.abe) haproxy acts master mysql server time being.
my problems are
- what happens when original master mysql instance(192.168.a.abd) up?
- will changes written new mysql master (192.168.a.abe) replicated original master(192.168.a.abd) again?
how should address scenario?
first of should have never used ha proxy con't comment on directly.
however, in current setup master (abd) out of sync, , wont catch up. have rebuild using mysqldump or similar tool.
what need master < > master
setup (as opposed master > slave
), enables write either database , have reflected in other. isn't quite straight forward sounds though.
assuming have master > slave
setup, , in sync
on master (abd) want add:
auto_increment_increment=2 auto_increment_offset=1 log-slave-updates
on slave (abe) add:
auto_increment_increment=2 auto_increment_offset=2 log-slave-updates
to my.cnf files. restart database. prevent duplicate key errors
. (n.b. log-slave-updates
isn't strictly required makes easier add slave in future)
next want tell master (abd) replicate slave (abe).
depending on version of mysql , if using gtid etc. exact process differs slightly. going issue change master
statement on master replicates slave.
and away go. want avoid writing both @ same time opens whole other kettle of fish. if master goes down, can switch writes slave, , when master comes up, start replicating missing data.
Comments
Post a Comment