Tag Archives: slave

After reboot of your master, slave and master switched their roles and you want to switch back them:
login to current master and make:

1
2
3
4
cfg = rs.conf()
cfg.members[0].priority = 1
cfg.members[1].priority = 0.5
rs.reconfig(cfg)

after «cfg = rs.conf ()» you'll see config, change priority for master (set bigger number) and for slave (set lower number).

mongodb: replica master-slave + creating of db and collection

Replica master-slave

master
add to mongod.conf:
master = true
client
add to mongod.conf:
slave = true
source = $masterHost:$masterPort #(for example 127.0.0.1:27017)

stop master
rsync folder with db from master to slave
start master
start slave

Creating of db and collection

# open mongo shell
mongo --host 127.0.0.1:27017
# use db name which you'd like to create
use newDbName
# data which you'd like to add to collection
j = { name : «mongo» }
# insert previous data to collection
db.testData.insert ( j )

# check that db/collection/data were created
show dbs
show collections
db.testData.find ()

check replica

# open mongo shell on slave
mongo --host 10.0.0.2:27017
# check that db/collection/data were created
show dbs
show collections
db.testData.find ()

mysql 5.1: replication

Master server

edit /etc/mysql/conf.d/replication.cnf

1
[mysqld]

1
server-id        =
1
1

1
# By
1
default
1
, the directory is written to the directory of database.

1
# IMPORTANT: If you lose the base, having a backup and binary logs, you can restore a database at the time of collapse. For
1
this

1
# reason, the logs and databases should be stored at physically different carriers.

1
log-bin          = /db/log/mysql-bin.log

1
# This variable applies when binary logging is enabled. It controls whether stored function creators can be trusted not to create #stored functions that will cause unsafe events to be written to the binary log.

1
log_bin_trust_function_creators =
1
1

1
# The number of days
1
for
1
automatic binary log file removal..

1
expire_logs_days =
1
90

1
# >=
1
5.1
1
.
1
28
1
- you is unable to start shard without
1
this
1
option.

1
# < 
1
5.1

   

1
- you is unable to start mysqld server without
1
this
1
option.

1
binlog_format    = MIXED

1
max_binlog_size  = 100M
# In addition, the transaction can determine what needs to change the data and may be useful to diagnose various problems.
# For MySQL <= 5.0: We don't recommend to use this option due to the replication became fragile.

mysql -uroot -p

1
GRANT REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO replicator@
1
'%'
1
IDENTIFIED BY
1
'****'
1
;

/etc/init.d/mysql restart
Continue reading mysql 5.1: replication