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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- consul 多節點/單節點叢集搭建
- mongodb主從仲裁節點配置MongoDB
- 4.2 叢集節點初步搭建
- mongodb叢集節點故障的切換方法MongoDB
- linux搭建kafka叢集,多master節點叢集說明LinuxKafkaAST
- hadoop叢集搭建——單節點(偽分散式)Hadoop分散式
- Centos7.9 部署mongodb高可用叢集 3節點CentOSMongoDB
- MongoDB分片叢集節點狀態stateStr:RECOVERING解決MongoDB
- CentOS7 上搭建多節點 Elasticsearch叢集CentOSElasticsearch
- kafka系列二:多節點分散式叢集搭建Kafka分散式
- HAC叢集更改IP(單節點更改、全部節點更改)
- Solaris叢集節點重啟
- HAC叢集新增新節點
- vscode中隱藏節點模組的外掛VSCode
- Redis Manager 叢集管理與節點管理Redis
- zookeeper叢集奇偶數節點問題
- Redis服務之叢集節點管理Redis
- Oracle叢集軟體管理-新增和刪除叢集節點Oracle
- 400+節點的 Elasticsearch 叢集運維Elasticsearch運維
- Druid.io系列3:Druid叢集節點UI
- 升級kubeadm 叢集(只有master單節點)AST
- 400+ 節點的 Elasticsearch 叢集運維Elasticsearch運維
- kubernets叢集節點NotReady故障 分析報告
- 使用kubeadm搭建一單節點k8s測試叢集K8S
- 單機Linux下搭建MongoDB副本集-三節點LinuxMongoDB
- Jedis操作單節點redis,叢集及redisTemplate操作redis叢集(一)Redis
- 使用容器快速在阿里雲 ECS 多節點上搭建 Citus 12.1 叢集阿里
- 從庫轉換成PXC叢集的節點
- 安裝 Hadoop:設定單節點 Hadoop 叢集Hadoop
- 設定gbase叢集節點離線狀態
- MongoDB修復config配置節點MongoDB
- 【故障公告】Kubernetes 叢集節點當機造成部落格站點故障
- DKHhadoop叢集新增節點管理功能的操作步驟Hadoop
- 檢視Redis叢集所有節點記憶體工具Redis記憶體
- 節點加入k8s 叢集的步驟K8S
- 讀懂這一篇,叢集節點不下線
- Elasticsearch 7.x 之節點、叢集、分片及副本Elasticsearch
- Hadoop 叢集角色和節點數規劃建議Hadoop