mongodb - arbiter- cluster installation

mongodb cluster is divided into three main methods Replica Set / Sharding / Master-Slaver, only the simplest explanation here way to build clusters (production), so if you have multiple nodes may or check out the official documentation.

Replica Set

Chinese translation is called the replica set. In fact, is simply among the cluster contains multiple copies of data to ensure that the master node and hung up, the standby node can continue to provide data services, consistent with the premise of the need to provide is the data and the master node. FIG follows

Primary a front node, Secondary represents the standby node, Mongodb (A) represented by the arbitration node. Standby node stores data (M, S), the arbitration node does not store data. Simultaneous client connections master node and the standby node, the node is not connected to the arbitration.

In the default setting, the master node changes all deletions search service, the standby node does not provide any services. However, provided that the standby node can provide access to services, which can reduce the pressure of the master node, when a client query data, the request automatically to the standby node. This setting is called Read Preference Modes, while the Java client provides a simple configuration, you can not operate directly on the database.

Arbitration node is a special node, which itself is not stored data, the main role is to decide which one standby node to a primary node after the primary node hang up, so the client need not be connected to this node. Although only a standby node here, but still needs to improve prepare an arbitration node node level.
Master node failure, a handover procedure is as follows

Mongo download the installation package

Download the official website address of
https://www.mongodb.com/download-center/community
the selected system version

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.0.tgz
tar -zxf  https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.0.tgz
mkdir -p /mongodb/data/{master,slaver,arbiter}
mkdir /mongodb/log   
#三个目录分别对应主,备,仲裁节点 

Configuration file of each node


#master.conf  
dbpath=/mongodb/data/master  
logpath=/mongodb/log/master.log  
pidfilepath=/mongodb/master.pid  
directoryperdb=true  
logappend=true  
replSet=testrs  
bind_ip=192.168.11.11
port=27017  
oplogSize=10000  
fork=true


#slaver.conf  
dbpath=/mongodb/data/slaver  
logpath=/mongodb/log/slaver.log  
pidfilepath=/mongodb/slaver.pid  
directoryperdb=true  
logappend=true  
replSet=testrs  
bind_ip=192.168.11.12
port=27017
oplogSize=10000  
fork=true 


#arbiter.conf  
dbpath=/mongodb/data/arbiter  
logpath=/mongodb/log/arbiter.log  
pidfilepath=/mongodb/arbiter.pid  
directoryperdb=true  
logappend=true  
replSet=testrs  
bind_ip=192.168.11.13
port=27017
oplogSize=10000  
fork=true  

Parameter Description

*配置文件中参数解释:

  dbpath:数据存放目录

  logpath:日志存放路径

  pidfilepath:进程文件,方便停止mongodb

  directoryperdb:为每一个数据库按照数据库名建立文件夹存放

  logappend:以追加的方式记录日志

  replSet:replica set的名字

  bind_ip:mongodb所绑定的ip地址

  port:mongodb进程所使用的端口号,默认为27017

  oplogSize:mongodb操作日志文件的最大大小。单位为Mb,默认为硬盘剩余空间的5%

  fork:以后台方式运行进程

Cluster Configuration

#启动各节点的mongo
./mongod -f master.conf 
./mongod -f slaver.conf 
./mongod -f arbiter.conf 
#配置主,备,仲裁节点
./mongo 192.168.11.11:27017   #ip和port是某个节点的地址 
>use admin  
>cfg={ _id:"testrs", members:[ {_id:0,host:'192.168.11.11:27017',priority:2}, {_id:1,host:'192.168.11.12:27017',priority:1},   {_id:2,host:'192.168.11.13:27017',arbiterOnly:true}] };  
#cfg是可以任意的名字,当然最好不要是mongodb的关键字,conf,config都可以。最外层的_id表示replica set的名字,
members里包含的是所有节点的地址以及优先级。优先级最高的即成为主节点,即这里的192.168.11.11:27017。
特别注意的是,对于仲裁节点,需要有个特别的配置——arbiterOnly:true。这个千万不能少了,不然主备模式就不能生效。 
arbiterOnly   O为大写
>rs.initiate(cfg)  
#查看状态
> rs.status()
#正在进行配置会提示:"stateStr" : "RECOVERING" 
#末行输出如下即为成功

    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1567144580, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    },
    "operationTime" : Timestamp(1567144580, 1)
}

Reference: https://www.cnblogs.com/callmecool/p/4662876.html

#example
mkdir -p /data/app-data/mongodb

dbpath=/data/app-data/mongodb
logpath=/data/app-data/mongodb/mongodb.log    
pidfilepath=/data/app-data/mongodb/mongodb.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=10.80.25.130
port=27017
oplogSize=10000
fork=true
#以上为用来复制的配置

Guess you like

Origin www.cnblogs.com/66li/p/12058750.html