首页 > 数据库 >mongodb副本集(非仲裁模式)修改各节点ip(update方式)

mongodb副本集(非仲裁模式)修改各节点ip(update方式)

时间:2023-09-02 15:22:29浏览次数:57  
标签:02T07 mongodb 08 09 update NumberLong ip ISODate 2023

环境:
OS:Centos 7
mongodb:5.0
当前的ip        变更后的ip
192.168.1.108    192.168.1.105    PRIMARY
192.168.1.109    192.168.1.106    SECONDARY
192.168.1.110    192.168.1.107     SECONDARY

 

1.查看当前的集群
登录一个节点上查看

/usr/local/services/mongodb/bin/mongo 192.168.1.108:29001
myrepl:PRIMARY> use admin
myrepl:PRIMARY> db.auth("test","test123");
myrepl:PRIMARY> rs.conf()
{
        "_id" : "myrepl",
        "version" : 1,
        "term" : 6,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "192.168.1.108:29001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "192.168.1.109:29001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "192.168.1.110:29001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "catchUpTimeoutMillis" : -1,
                "catchUpTakeoverDelayMillis" : 30000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("64d58c8b10dc4e229f96f8a7")
        }
}

 

2.停掉mongodb
每个节点上操作,先停掉从再停主
/usr/local/services/mongodb/bin/mongo localhost:29001
use admin
db.auth("test","test123");
db.shutdownServer()

 

3.修改每个节点的ip
cd /etc/sysconfig/network-scripts
vi ifcfg-enp0s3

重启网络
systemctl restart network

 

4.单机模式启动每一个节点
我这里以其中一个节点为例子
vi /home/middle/mongodb/conf/mongo.cnf

bind_ip=192.168.1.108,127.0.0.1 ##注意修改ip
##shardsvr=true
##replSet=myrepl
##auth=true
##keyFile=/home/middle/mongodb/key/keyfile

单机模式启动
/usr/local/services/mongodb/bin/mongod -f /home/middle/mongodb/conf/mongo.cnf

 

5.更新配置表
每个节点都要执行该操作

/usr/local/services/mongodb/bin/mongo localhost:29001
use local
db.system.replset.findOne()
cfg = db.system.replset.findOne({_id: 'myrepl'})
cfg.members[0].host = "192.168.1.105:29001"
cfg.members[1].host = "192.168.1.106:29001"
cfg.members[2].host = "192.168.1.107:29001"
db.system.replset.update({_id: 'myrepl'}, cfg)
db.system.replset.findOne()

注意这里我的副本集名称为:myrepl,要根据自己的实际情况替换.

 

6.停掉每个节点
/usr/local/services/mongodb/bin/mongo localhost:29001
use admin
db.shutdownServer()

另外的节点也做步骤4 和步骤5、步骤6的操作

 

7.去掉每个节的注释参数
vi /home/middle/mongodb/conf/mongo.cnf
shardsvr=true
replSet=myrepl
auth=true
keyFile=/home/middle/mongodb/key/keyfile

 

8.重新启动

每个节点都执行
/usr/local/services/mongodb/bin/mongod -f /home/middle/mongodb/conf/mongo.cnf

 

9.登录检查

/usr/local/services/mongodb/bin/mongo localhost:29001
use admin
db.auth("test","test123");
myrepl:PRIMARY> rs.status()
{
        "set" : "myrepl",
        "date" : ISODate("2023-09-02T07:08:30.560Z"),
        "myState" : 1,
        "term" : NumberLong(7),
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "majorityVoteCount" : 2,
        "writeMajorityCount" : 2,
        "votingMembersCount" : 3,
        "writableVotingMembersCount" : 3,
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1693638501, 1),
                        "t" : NumberLong(7)
                },
                "lastCommittedWallTime" : ISODate("2023-09-02T07:08:21.308Z"),
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1693638501, 1),
                        "t" : NumberLong(7)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1693638501, 1),
                        "t" : NumberLong(7)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1693638501, 1),
                        "t" : NumberLong(7)
                },
                "lastAppliedWallTime" : ISODate("2023-09-02T07:08:21.308Z"),
                "lastDurableWallTime" : ISODate("2023-09-02T07:08:21.308Z")
        },
        "lastStableRecoveryTimestamp" : Timestamp(1693637577, 1),
        "electionCandidateMetrics" : {
                "lastElectionReason" : "electionTimeout",
                "lastElectionDate" : ISODate("2023-09-02T07:07:51.248Z"),
                "electionTerm" : NumberLong(7),
                "lastCommittedOpTimeAtElection" : {
                        "ts" : Timestamp(0, 0),
                        "t" : NumberLong(-1)
                },
                "lastSeenOpTimeAtElection" : {
                        "ts" : Timestamp(1693637587, 1),
                        "t" : NumberLong(6)
                },
                "numVotesNeeded" : 2,
                "priorityAtElection" : 1,
                "electionTimeoutMillis" : NumberLong(10000),
                "numCatchUpOps" : NumberLong(0),
                "newTermStartDate" : ISODate("2023-09-02T07:07:51.301Z"),
                "wMajorityWriteAvailabilityDate" : ISODate("2023-09-02T07:07:51.867Z")
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "192.168.1.105:29001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 51,
                        "optime" : {
                                "ts" : Timestamp(1693638501, 1),
                                "t" : NumberLong(7)
                        },
                        "optimeDate" : ISODate("2023-09-02T07:08:21Z"),
                        "lastAppliedWallTime" : ISODate("2023-09-02T07:08:21.308Z"),
                        "lastDurableWallTime" : ISODate("2023-09-02T07:08:21.308Z"),
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "Could not find member to sync from",
                        "electionTime" : Timestamp(1693638471, 1),
                        "electionDate" : ISODate("2023-09-02T07:07:51Z"),
                        "configVersion" : 1,
                        "configTerm" : 7,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 1,
                        "name" : "192.168.1.106:29001",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 47,
                        "optime" : {
                                "ts" : Timestamp(1693638501, 1),
                                "t" : NumberLong(7)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1693638501, 1),
                                "t" : NumberLong(7)
                        },
                        "optimeDate" : ISODate("2023-09-02T07:08:21Z"),
                        "optimeDurableDate" : ISODate("2023-09-02T07:08:21Z"),
                        "lastAppliedWallTime" : ISODate("2023-09-02T07:08:21.308Z"),
                        "lastDurableWallTime" : ISODate("2023-09-02T07:08:21.308Z"),
                        "lastHeartbeat" : ISODate("2023-09-02T07:08:29.328Z"),
                        "lastHeartbeatRecv" : ISODate("2023-09-02T07:08:30.344Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncSourceHost" : "192.168.1.105:29001",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 1,
                        "configTerm" : 7
                },
                {
                        "_id" : 2,
                        "name" : "192.168.1.107:29001",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 44,
                        "optime" : {
                                "ts" : Timestamp(1693638501, 1),
                                "t" : NumberLong(7)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1693638501, 1),
                                "t" : NumberLong(7)
                        },
                        "optimeDate" : ISODate("2023-09-02T07:08:21Z"),
                        "optimeDurableDate" : ISODate("2023-09-02T07:08:21Z"),
                        "lastAppliedWallTime" : ISODate("2023-09-02T07:08:21.308Z"),
                        "lastDurableWallTime" : ISODate("2023-09-02T07:08:21.308Z"),
                        "lastHeartbeat" : ISODate("2023-09-02T07:08:29.328Z"),
                        "lastHeartbeatRecv" : ISODate("2023-09-02T07:08:30.345Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncSourceHost" : "192.168.1.105:29001",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 1,
                        "configTerm" : 7
                }
        ],
        "ok" : 1
}

 

标签:02T07,mongodb,08,09,update,NumberLong,ip,ISODate,2023
From: https://www.cnblogs.com/hxlasky/p/17673711.html

相关文章

  • macOS Sonoma 14 beta 7 (23A5337a) ISO、IPSW、PKG 下载
    macOSSonoma14beta7(23A5337a)ISO、IPSW、PKG下载本站下载的macOS软件包,既可以拖拽到Applications(应用程序)下直接安装,也可以制作启动U盘安装,或者在虚拟机中启动安装。另外也支持在Windows和Linux中创建可引导介质。请访问原文链接:https://sysin.org/blog/macOS-......
  • iptables防火墙(二)
    实现NAT功能所需要的环境:三台主机,一台做内网主机桥节点V8192.168.1.2/24 网关192.168.1.1一台做防火墙(路由器)装两块网卡V8ens33192.168.1.1/24V1ens37200.0.0.1/24一台做外网主机V1200.0.0.2/24 无网关做路由器的主机需要开启路由转发vim/etc/sysctl.conf最后加一......
  • javascript: confirm alert box costomer style
     //JavaScriptDocument/*參考資源:https://developer.mozilla.org/en-US/docs/Web/API/Window/alerthttps://developer.mozilla.org/en-US/docs/Web/API/Window/confirmhttps://reactkungfu.com/2015/08/beautiful-confirm-window-with-react/https://www.jquery-az.co......
  • Seurat Tutorial 5:使用 reciprocal PCA (RPCA) 快速整合
    写在前面学习一个软件最好的方法就是啃它的官方文档。本着自己学习、分享他人的态度,分享官方文档的中文教程。软件可能随时更新,建议配合官方文档一起阅读。推荐先按顺序阅读往期内容:文献篇:1.文献阅读:(SeuratV1)单细胞基因表达数据的空间重建2.文献阅读:(SeuratV2)整合跨......
  • 24 路由器,交换机,IP,DNS,子网掩码,网关
    昨天有同志遇到了电脑连接问题,他是在一个大型局域网中,他们的网络交换机没打开自动分配IP的功能,所以IP地址都是手动配置,期间遇到了子网掩码,IP地址,网关,DNS服务器等概念,逐一记录,希望能让所有人看懂。一、交换机主要功能为端口拓展,让你有更多网络端口,扩大局域网接入点。。工作在TCPI......
  • MongoDB系列之分片管理
    1.查看当前状态1.1查看配置信息mongos>useconfig//查看分片mongos>db.shards.find(){"_id":"study","host":"study/localhost:27018,localhost:27019,localhost:27020","state":1}//查看分片集合信息mongos>db.collecti......
  • pip安装pyinstall
    ......
  • NOIP2012提高组初赛易错题解析
    一.3. 错误原因:忘记了解析:Intel是全球最大的CPU厂商,AMD是世界上首个研发出7纳米CPU的厂商 6.错误原因:忘记了解析:ENIAC是世界上首台计算机,属于第一代计算机,即电子管计算机 10.错误原因:选项理解错误解析:A由蝙蝠,发明雷达是正确的,B因特网的发明与蜘蛛网无关,只是形......
  • NOIP2011提高组初赛易错题解析
    一.7.错误原因:不知道解析:快速排序在理论上最低的时间复杂度为O(n),但实际最低的时间复杂度为O(nlogn) 二.1.错误原因:漏项了解析:这棵树最少有12层,但题目是问可能是几层,所以还可能是2011层 5.错误原因:漏了一种情况解析:这道题的树有两种,所以答案也有两种 ......
  • VChart中如何配置Tooltip (文字提示) 自动换行?
    在VChart中,您可以通过配置tooltip的formatter函数来实现Tooltip的自动换行。tooltip的formatter函数允许您自定义Tooltip的文本内容,因此您可以在该函数中处理并格式化Tooltip的文本。以下是一个示例,演示如何在VChart中配置Tooltip的自动换行:<template><div>......