mongodb学习(三、主从)

主从备份Master->Slave->arbiter

数据目录

软件版本:mongodb-linux-x86_64-rhel70-4.4.3.tgz

目录配置
目前是单机配置的三个节点
192.168.31.131 主 port=27017
192.168.31.131 从 port=28000
192.168.31.131 仲裁 port=28010

mkdir -p /data/mongodb/data
mkdir -p /data/mongodb/conf
mkdir -p /data/mongodb/log
mkdir -p /data/mongodb/arbiter

chown -R mongod.mongod /data/mongodb
chown -R mongod.mongod /data/mongodb/data
chown -R mongod.mongod /data/mongodb/conf
chown -R mongod.mongod /data/mongodb/log
chown -R mongod.mongod /data/mongodb/arbiter

配置文件

Master

vi /data/mongodb/master/conf/mongod.conf
启动脚本
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /data/mongodb/master/conf/mongod.conf

主节点配置文件

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
   destination: file
   path: "/data/mongodb/master/conf/shard1.log"
   logAppend: true

# Where and how to store data.
storage:
  journal:
    enabled: true
  dbPath: "/data/mongodb/master/data"
  directoryPerDB: true
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
      directoryForIndex: true
    collectionConfig:
      blockCompressor: zlib
    indexConfig:
      prefixCompression: true

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

replication:
  oplogSizeMB: 512
  replSetName: rep1

# how the process runs
processManagement:
  fork: true  # fork and run in background

Slave

vi /data/mongodb/slave1/conf/mongod.conf
启动脚本
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /data/mongodb/slave1/conf/mongod.conf

从节点配置文件

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
   destination: file
   path: "/data/mongodb/slave1/conf/shard1.log"
   logAppend: true

# Where and how to store data.
storage:
  journal:
    enabled: true
  dbPath: "/data/mongodb/slave1/data"
  directoryPerDB: true
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
      directoryForIndex: true
    collectionConfig:
      blockCompressor: zlib
    indexConfig:
      prefixCompression: true

# network interfaces
net:
  port: 28000
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

replication:
  oplogSizeMB: 512
  replSetName: rep1

# how the process runs
processManagement:
  fork: true  # fork and run in background

xarbiter

vi /data/mongodb/arbiter/conf/mongod.conf
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /data/mongodb/arbiter/conf/mongod.conf

#仲裁节点【配置文件】

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
   destination: file
   path: "/data/mongodb/arbiter/conf/arbiter.log"
   logAppend: true

# Where and how to store data.
storage: 
  journal:
    enabled: true
  dbPath: "/data/mongodb/arbiter/arbiter"
  directoryPerDB: true
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
      directoryForIndex: true
    collectionConfig:
      blockCompressor: zlib
    indexConfig:
      prefixCompression: true

# network interfaces
net:
  port: 28010
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

replication:
  oplogSizeMB: 512
  replSetName: rep1

# how the process runs
processManagement:
  fork: true  # fork and run in background

启动节点



仲裁
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /usr/local/mongodb/master/conf/mongod.conf
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /usr/local/mongodb/slave1/conf/mongod.conf
/usr/local/mongodb/mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod -f /usr/local/mongodb/arbiter/conf/mongod.conf

mongodb3.4可以使用此节点检查是否主节点
rs.slaveOk()
mongodb4.3使用
rs.isMaster()
备注:更多操作使用
rs.help()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值