首页 > 数据库 >mongodb副本集ip调整

mongodb副本集ip调整

时间:2023-07-17 11:00:16浏览次数:38  
标签:ip 副本 07 mongodb 43 NumberLong ISODate 2023 17T02

环境:
Os:Centos 7
mongodb:4.4.22

调整顺序:从节点-->仲裁节点-->主节点
源ip与新ip对应关系(这里只拿修改从库作为例子)
192.168.107-->192.168.104 从节点

 

1.关闭从节点
/usr/local/services/mongodb/bin/mongo localhost:29001
myrepl:SECONDARY> use admin
myrepl:SECONDARY> db.auth("test","test123");
myrepl:SECONDARY> db.shutdownServer()

 

2.修改ip

[root@localhost network-scripts]# more ifcfg-enp0s3 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=2323beca-b693-4a2a-9fcf-6caa2f095bef
DEVICE=enp0s3
ONBOOT=yes
IPADDR=192.168.1.104
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

重启网络
[root@localhost /]#service network restart

 

3.修改配置文件
[root@localhost conf]# vi /home/middle/mongodb/conf/mongo.cnf
bind_ip=192.168.1.104,127.0.0.1

 

4.启动从库
/usr/local/services/mongodb/bin/mongod -f /home/middle/mongodb/conf/mongo.cnf

 

5.登陆主库执行如下命令
/usr/local/services/mongodb/bin/mongo localhost:29001
myrepl:PRIMARY> use admin
myrepl:PRIMARY> db.auth("test","test123");

这个时候查看集群状态(rs.status())会提示连接不到原来的ip:
"lastHeartbeatMessage" : "Error connecting to 192.168.1.107:29001 :: caused by :: No route to host",

 

查看当前的配置

myrepl:PRIMARY> rs.conf()
{
        "_id" : "myrepl",
        "version" : 23821,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "192.168.1.102:29001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

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

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 4,
                        "host" : "192.168.1.107:29001",
                        "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("64b0a3f881b811c4931d4d4c")
        }
}

 

6.进行修改

注意这里的members[2] 中的数值2是member数组的序号
myrepl:PRIMARY>cfg = rs.conf()
myrepl:PRIMARY>cfg.members[2].host="192.168.1.104:29001"
myrepl:PRIMARY>rs.reconfig(cfg)

 

7.查看副本集状态

myrepl:PRIMARY> rs.status()
{
        "set" : "myrepl",
        "date" : ISODate("2023-07-17T02:43:37.181Z"),
        "myState" : 1,
        "term" : NumberLong(4),
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "majorityVoteCount" : 2,
        "writeMajorityCount" : 2,
        "votingMembersCount" : 3,
        "writableVotingMembersCount" : 2,
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1689561812, 1),
                        "t" : NumberLong(4)
                },
                "lastCommittedWallTime" : ISODate("2023-07-17T02:43:32.119Z"),
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1689561812, 1),
                        "t" : NumberLong(4)
                },
                "readConcernMajorityWallTime" : ISODate("2023-07-17T02:43:32.119Z"),
                "appliedOpTime" : {
                        "ts" : Timestamp(1689561812, 1),
                        "t" : NumberLong(4)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1689561812, 1),
                        "t" : NumberLong(4)
                },
                "lastAppliedWallTime" : ISODate("2023-07-17T02:43:32.119Z"),
                "lastDurableWallTime" : ISODate("2023-07-17T02:43:32.119Z")
        },
        "lastStableRecoveryTimestamp" : Timestamp(1689561802, 1),
        "electionCandidateMetrics" : {
                "lastElectionReason" : "electionTimeout",
                "lastElectionDate" : ISODate("2023-07-17T00:43:31.531Z"),
                "electionTerm" : NumberLong(4),
                "lastCommittedOpTimeAtElection" : {
                        "ts" : Timestamp(0, 0),
                        "t" : NumberLong(-1)
                },
                "lastSeenOpTimeAtElection" : {
                        "ts" : Timestamp(1689328811, 1),
                        "t" : NumberLong(3)
                },
                "numVotesNeeded" : 2,
                "priorityAtElection" : 1,
                "electionTimeoutMillis" : NumberLong(10000),
                "numCatchUpOps" : NumberLong(0),
                "newTermStartDate" : ISODate("2023-07-17T00:43:31.548Z"),
                "wMajorityWriteAvailabilityDate" : ISODate("2023-07-17T00:43:31.655Z")
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "192.168.1.102:29001",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 7219,
                        "optime" : {
                                "ts" : Timestamp(1689561812, 1),
                                "t" : NumberLong(4)
                        },
                        "optimeDate" : ISODate("2023-07-17T02:43:32Z"),
                        "lastAppliedWallTime" : ISODate("2023-07-17T02:43:32.119Z"),
                        "lastDurableWallTime" : ISODate("2023-07-17T02:43:32.119Z"),
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1689554611, 1),
                        "electionDate" : ISODate("2023-07-17T00:43:31Z"),
                        "configVersion" : 23822,
                        "configTerm" : -1,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                },
                {
                        "_id" : 3,
                        "name" : "192.168.1.105:29001",
                        "health" : 1,
                        "state" : 7,
                        "stateStr" : "ARBITER",
                        "uptime" : 7212,
                        "lastHeartbeat" : ISODate("2023-07-17T02:43:35.680Z"),
                        "lastHeartbeatRecv" : ISODate("2023-07-17T02:43:35.809Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "configVersion" : 23822,
                        "configTerm" : -1
                },
                {
                        "_id" : 4,
                        "name" : "192.168.1.104:29001",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 363,
                        "optime" : {
                                "ts" : Timestamp(1689561812, 1),
                                "t" : NumberLong(4)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1689561812, 1),
                                "t" : NumberLong(4)
                        },
                        "optimeDate" : ISODate("2023-07-17T02:43:32Z"),
                        "optimeDurableDate" : ISODate("2023-07-17T02:43:32Z"),
                        "lastAppliedWallTime" : ISODate("2023-07-17T02:43:32.119Z"),
                        "lastDurableWallTime" : ISODate("2023-07-17T02:43:32.119Z"),
                        "lastHeartbeat" : ISODate("2023-07-17T02:43:35.680Z"),
                        "lastHeartbeatRecv" : ISODate("2023-07-17T02:43:36.680Z"),
                        "pingMs" : NumberLong(0),
                        "lastHeartbeatMessage" : "",
                        "syncSourceHost" : "192.168.1.102:29001",
                        "syncSourceId" : 0,
                        "infoMessage" : "",
                        "configVersion" : 23822,
                        "configTerm" : -1
                }
        ],
        "ok" : 1
}

 

标签:ip,副本,07,mongodb,43,NumberLong,ISODate,2023,17T02
From: https://www.cnblogs.com/hxlasky/p/17559441.html

相关文章

  • 【技术积累】JavaScript中的基础语法【三】
    JavaScript的条件结构JavaScript中的条件结构主要包括if语句、if-else语句、if-elseif语句和switch语句。这些条件结构用于根据不同的条件执行不同的代码块。if语句if语句用于在满足条件时执行一段代码块。语法如下:if(condition){//codetobeexecutedifconditioni......
  • 自打有了GIPKs,DBA和开发再也不用battle了
    GIPKs特性简介GIPKs特性的作用玩转GIPKsGIPKs解决了历史难题1.GIPKs特性简介从MySQL8.0.30开始,新引入一个叫做GPIKs的特性,其全称是GeneratedInvisiblePrimaryKeys,简言之就是自动生成隐含的主键列,更完整的说法是:启用GIPKs后,当新建的InnoDB表没有显式主......
  • mongodb副本集(PSA模式)修改节点信息
    环境:OS:Centos7mongodb:4.4.22 我们在副本集扩容的情况下,新加入节点一般设置priority和votes都为0,待新节点数据同步完成后再进行修改:主库上执行新增新的节点:myrepl:PRIMARY>rs.add({host:"192.168.1.107:29001",priority:0,votes:0})待同步完成后查看副本集配置 ......
  • mongodb从库无法启动一例(replication_recovery.cpp)
    环境:OS:centos7mongodb:4.4.22背景:1主1从1仲裁的环境,修改从库的集群ip后,执行如下操作后发现无法启动myrepl:PRIMARY>rs.remove("192.168.1.104:29001")myrepl:PRIMARY>conf=rs.conf()myrepl:PRIMARY>conf.members[1].host="192.168.1.107:29001"myrepl:PRIMARY>rs.r......
  • xclip
    xclip管理X粘贴板补充说明在X系统里面,从一个窗口复制一段文字到另一个窗口,有两套机制,分别是Selections和cutbuffers。常用的copy&paste是利用的cutbuffers机制;另外用鼠标选中一段文字,然后在另一个窗口按鼠标中键实现复制,利用的是selections机制。selection......
  • javascript 快排
    functionquickSort(arr){//如果数组只有一个数,就直接返回;if(arr.length<1){returnarr;}//找到中间的那个数的索引值;如果是浮点......
  • 【技术积累】JavaScript中的基础语法【二】
    JavaScript编写方式JavaScript是一种脚本语言,用于为网页添加交互性和动态功能。它可以直接嵌入到HTML中,并通过浏览器解释执行。下面是一些常见的JavaScript编写方式和相应的代码示例:内联方式在HTML文件中直接嵌入JavaScript代码,使用`<script>`标签将代码包裹起来。这种方式适用......
  • Typescript学习笔记总结
    Typescript是一种由微软开发的开源编程语言,它是JavaScript的超集,意味着它包含了JavaScript的所有特性,同时还提供了一些额外的功能和类型检查。Typescript的目标是提高JavaScript代码的可读性、可维护性和可扩展性,同时还能够在编译时检测出一些常见的错误。在本文中,我们将详细介绍Ty......
  • [Linux][报错解决] 搭建有固定ip的节点
    Linux环境:CentOS8+VMware目标:令节点有固定可访问的ip地址,为以后搭建多节点环境铺垫过程:查看并确定宿主机和linux系统的ip地址,修改ens160/ens33文件中的参数,使系统ip固定使用dhclient给linux系统分配一个ip系统刚开始默认没有ip(ifconfig后ens160/33没有inet一项),这时候需要dhc......
  • 工具 | pip报错 ValueError: check_hostname requires server_hostname解决方法
    使用python的pip安装第三方包的时候会出现这个问题。报错信息:ValueError:check_hostnamerequiresserver_hostname解决方法:​ 你可能打开了代理,你可以关闭代理试一下。如果不行,重启电脑再试一下。......