Showing posts with label replication. Show all posts
Showing posts with label replication. Show all posts

Thursday, January 24, 2013

mongodb: replica set

setup 3 dbs


# mongod --rest --replSet myset
mongod --replSet myset --port 27017 --dbpath /data/db1
mongod --replSet myset --port 27018 --dbpath /data/db2
mongod --replSet myset --port 27019 --dbpath /data/db3


or set master config file:


dbpath = /data/db
#bind_ip = 127.0.0.1
port = 27017

#logpath = /var/log/mongodb.log
#logappend = true
master = true
replSet = myset
#nojournal = false
rest = true


and set slave config file:


dbpath = /data/db
#bind_ip = 127.0.0.1
port = 27017
#logpath = /var/log/mongodb.log
#logappend = true
replSet = myset
#nojournal = false
rest = true
slave = true
source = gambit:27017


* enter each's host name in your /etc/hosts file if you're using different hosts

-------------------------------------

initialize host replica set

# mongo --port 27017
> rs.initiate();


(http://www.mongodb.org/display/DOCS/Replica+Sets+-+Basics)
(http://www.kchodorow.com/blog/2010/07/30/replica-sets-part-1-master-slave-is-so-2009/)

got error couldn't initiate : can't find self in the replset config

supply config using localhost works!

> config = {_id: 'myset', members: [
    {_id: 0, host:'localhost:27017'},
    {_id: 1, host:'localhost:27018'},
    {_id: 2, host:'localhost:27019'}]
    }

> rs.initiate(config)


changing config

> config = {_id: 'myset', members: [
    {_id: 0, host:'192.168.1.10:27017'},
    {_id: 1, host:'192.168.1.9:27017'}]
    }

> rs.reconfig(config)


make query in slave available

> rs.slaveOk()


to create a cold standby set secondary as secondary-only

> config = rs.config()
> config.members[1].priority = 0
> rs.reconfig(config)


(http://docs.mongodb.org/manual/administration/replication-architectures/ )
(http://docs.mongodb.org/manual/core/replication/ )
(http://docs.mongodb.org/manual/reference/configuration-options/ )

(http://www.mongodb.org/display/DOCS/Replica+Set+Tutorial )
(http://www.mongodb.org/display/DOCS/Master+Slave )

-------------------------------------

restoring replication

clear local.* from new primary;
clear all /data/db files from new secondary;

restore from a primary fail

> config = {_id: 'myset', members: [
    {_id: 1, host:'localhost:27018'},
    {_id: 2, host:'localhost:27019'}]
    }

> rs.initiate(config)


got "errmsg" : "local.oplog.rs is not empty on the initiating member.  cannot initiate.",

> rs.reconfig(config, {force:1})


got "ok" : 1


point new secondary source to new primary

restore from a secondary fail

> config = {_id: 'myset', members: [
    {_id: 0, host:'localhost:27017'},
    {_id: 1, host:'localhost:27019'}]
    }

> rs.initiate(config)


got "errmsg" : "local.oplog.rs is not empty on the initiating member.  cannot initiate.",

> rs.reconfig(config, {force:1})


got "ok" : 1


* try copying files before restoration

Thursday, December 08, 2011

mysql: recover from replication error

to recover from replication error... do the ff:

* if you can stop master for a few mins

1. stop current replication db
(on slave db)

# show slave status;
# stop slave;
# reset slave;

> /etc/init.d/mysql stop


2. stop master mysql
(on master db)

# show master status;
# reset master;

> /etc/init.d/mysql stop


3. get a snapshot of master db
(on master db)

> copy -r /data/mysqldata /home/backup/mysqldataMaster

4. start master db

> /etc/init.d/mysql start

# show master status;


5. copy snapshot of master db to slave db

> scp ...
> cp ...


6. start slave and replication

> /etc/init.d/mysql start

# start slave;
# show slave status;


** if you cant stop master for a few mins

1. stop current replication db
(on slave db)

# show slave status;
# stop slave;
# reset slave;

> /etc/init.d/mysql stop


2. reset master mysql
(on master db)

# show master status;
# reset master;


3. get a snapshot of master db
(on master db)

> copy -r /data/mysqldata /home/backup/mysqldataMaster

4. copy snapshot of master db to slave db

> scp ...
> cp ...


5. start slave and replication

> /etc/init.d/mysql start

# start slave;
# show slave status;


*** if you just want recover replication without stopping mysql (and without copying missing entries)

1. stop current replication db
(on slave db)

# show slave status;
# stop slave;
# reset slave;


2. reset master mysql
(on master db)

# show master status;
# reset master;


3. start slave and replication

# start slave;
# show slave status;

Friday, August 12, 2011

mysql: replication

# in master db's my.cnf
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
datadir=/data1/mysqldata
 
set-variable = key_buffer_size=1500M
set-variable = max_allowed_packet=1M
set-variable = max_connections=1200
set-variable = max_connect_errors=999999
set-variable = max_user_connections=1200
set-variable = table_cache=512
set-variable = sort_buffer=128M
set-variable = ft_min_word_len=2
 
local-infile=1
server-id=1
log-bin
 
[mysqldump]
quick


# in slave db's my.cnf
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
 
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
datadir=/data1/mysqldata
set-variable = key_buffer_size=512M
set-variable = max_allowed_packet=1M
set-variable = max_connections=1200
set-variable = max_connect_errors=999999
set-variable = max_user_connections=1200
set-variable = table_cache=512
set-variable = sort_buffer=128M
set-variable = max_binlog_size=512M
 
slave-skip-errors=1062,1114,1050,1051,1146
 
local-infile=1
server-id=2
master-host=223.223.223.35
master-user=repl
master-password=replMaster
master-port=3306
 
[mysqldump]
quick


# grant access for slave db to master db
GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY '<slave_password>';


# dont forget to flush privileges
FLUSH PRIVILEGES;

SSH : No matching host key type found. Their offer: ssh-rsa,ssh-dss

Got this while connecting to my mikrotik router via ssh   Unable to negotiate with <ip address> port <ssh port>: no matching hos...