MongoDB叢集搭建(包括隱藏節點,仲裁節點)
準備引數檔案
dbpath = /u01/mongodb/db/27021/data
logpath = /u01/mongodb/db/27021/logs/mongodb.log
port = 27021
fork = true
bind_ip=0.0.0.0
#auth=true
replSet=firstset
#keyFile=/u01/mongodb/db/27021
拉起服務
mongod -f /u01/mongodb/db/27021/mongodb.conf
mongod -f /u01/mongodb/db/27022/mongodb.conf
mongod -f /u01/mongodb/db/27023/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 6267
child process started successfully, parent exiting
初始化
> rs.initiate()
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "mdb01:27021",
"ok" : 1
}
新增節點
firstset:PRIMARY> rs.add("192.168.61.16:27022")
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1618297787, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1618297787, 1)
}
firstset:PRIMARY> rs.add("192.168.61.16:27023")
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1618297916, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1618297916, 1)
}
firstset:PRIMARY> rs.conf()
{
"_id" : "firstset",
"version" : 3,
"term" : 1,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "mdb01:27021",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "192.168.61.16:27022",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "192.168.61.16:27023",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("607542f0619fcd69e2edeac0")
}
}
將27023節點設定為隱蔽,並且優先順序為0,那麼該節點就不會被選舉為主庫
firstset:PRIMARY> conf.members[2]
{
"_id" : 2,
"host" : "192.168.61.16:27023",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
firstset:PRIMARY> conf.members[2].hidden
false
firstset:PRIMARY> conf.members[2].hidden=true
true
firstset:PRIMARY> conf.members[2].priority
1
firstset:PRIMARY> conf.members[2].priority=0
0
檢視修改後的結果
firstset:PRIMARY> conf.members[2]
{
"_id" : 2,
"host" : "192.168.61.16:27023",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : true,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
更新複製集的引數
firstset:PRIMARY> rs.reconfig(conf)
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1618298298, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1618298298, 1)
}
新增仲裁伺服器
mongod -f /u01/mongodb/db/27024/mongodb.conf
firstset:PRIMARY> rs.addArb("192.168.61.16:27024")
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1618299479, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1618299479, 1)
}
rs.conf()將會增加如下內容:arbiterOnly的value是true
firstset:PRIMARY> rs.conf().members[3]
{
"_id" : 3,
"host" : "192.168.61.16:27024",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
現在複製集中有4個節點,偶數個節點是非常危險的事。所以將隱藏節點的投票權設定為0,
當然還可以再新增一個仲裁節點或投票節點。
conf=rs.conf()
firstset:PRIMARY> conf.members[2].votes=0
0
firstset:PRIMARY> rs.reconfig(conf)
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1618302254, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1618302254, 1)
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31480688/viewspace-2767847/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mongodb主從仲裁節點配置MongoDB
- consul 多節點/單節點叢集搭建
- 4.2 叢集節點初步搭建
- mongodb叢集節點故障的切換方法MongoDB
- 【Mongodb】sharding 叢集Add/Remove 節點MongoDBREM
- linux搭建kafka叢集,多master節點叢集說明LinuxKafkaAST
- Centos7.9 部署mongodb高可用叢集 3節點CentOSMongoDB
- kafka系列二:多節點分散式叢集搭建Kafka分散式
- CentOS7 上搭建多節點 Elasticsearch叢集CentOSElasticsearch
- hadoop叢集搭建——單節點(偽分散式)Hadoop分散式
- HAC叢集更改IP(單節點更改、全部節點更改)
- MongoDB分片叢集節點狀態stateStr:RECOVERING解決MongoDB
- MongoDB副本集新增和刪除仲裁節點一例MongoDB
- Redis服務之叢集節點管理Redis
- Redis Manager 叢集管理與節點管理Redis
- redhat安裝雙節點cassandra叢集Redhat
- Oracle叢集軟體管理-新增和刪除叢集節點Oracle
- 400+節點的 Elasticsearch 叢集運維Elasticsearch運維
- 400+ 節點的 Elasticsearch 叢集運維Elasticsearch運維
- Oracle RAC 10g叢集節點增加Oracle
- multicast導致節點無法加入叢集AST
- vscode中隱藏節點模組的外掛VSCode
- 搭建5個節點的hadoop叢集環境(CDH5)HadoopH5
- Jedis操作單節點redis,叢集及redisTemplate操作redis叢集(一)Redis
- 從庫轉換成PXC叢集的節點
- RAC修改叢集兩個節點public ip地址
- hadoop叢集多節點安裝詳解Hadoop
- 在多節點的叢集上執行Cassandra
- 升級kubeadm 叢集(只有master單節點)AST
- 使用kubeadm搭建一單節點k8s測試叢集K8S
- 單機Linux下搭建MongoDB副本集-三節點LinuxMongoDB
- 搭建Solana驗證者節點(全節點)的過程
- Elasticsearch 7.x 之節點、叢集、分片及副本Elasticsearch
- 檢視Redis叢集所有節點記憶體工具Redis記憶體
- 設定gbase叢集節點離線狀態
- Druid.io系列3:Druid叢集節點UI
- RAC第一個節點被剔除叢集故障分析
- 一個4節點Hadoop叢集的配置示例Hadoop