mongo的repSet转换为standalone

36 阅读1分钟

mongo的repSet转换为standalone


一、概述

wg mongo 在2022.08.15 晚10点secondary节点需要停机维护宿主机,导致需要停机。同时cpos mongo的服务不能停。

1、wg mongo架构

1主1从,没有仲裁节点

2、mongo版本

4.0.14

3、解决方法

将replica set 转换为单节点。停服关机secondary。

2、集群信息

IP:

172.21.213.210 (主)

172.21.213.219 (从)

配置文件

/data/mongodb/27017/conf

启停脚本

systemctl start mongod_27017

systemctl stop mongod_27017

systemctl status mongod_27017




二、操作

1、将集群中的secondary节点删除

use admin

db.auth('admin', 'admin')

rs.status()

rs.remove("172.21.213.219:27017")

2、切换到local库中删除local库

use local;

db.dropDatabase();

3、编辑mongodb.conf

3.1· 删除replset 参数

systemLog:
    destination: file
    path: "/data/mongodb/27017/log/mongod.log"
    logAppend: true
    logRotate: rename
    timeStampFormat: ctime
storage:
    dbPath: "/data/mongodb/27017/data"
    directoryPerDB: true
    journal:
        enabled: true
        commitIntervalMs: 100
    wiredTiger:
        engineConfig:
            cacheSizeGB: 1
operationProfiling:
    slowOpThresholdMs: 200
    mode: slowOp
    slowOpSampleRate: 100
processManagement:
    fork: true
    pidFilePath: "/data/mongodb/27017/mongod.pid"
net:
    port: 27017
    bindIpAll: true
    
    
# ###  删除以下内容
replication:
   oplogSizeMB: 25000
   replSetName: CPOS
   enableMajorityReadConcern: true
# ### 删除以上内容


security:
    authorization: enabled
    keyFile: "/data/mongodb/27017/conf/keyfile"

3.2· 重启mongo服务

systemctl stop mongod_27017

systemctl start mongod_27017

4、等待mongo服务启动




三、参考

medium.com/@cjandsilva…