Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Restoring the configsvr Replica Set

Updated on 2024-04-01 GMT+08:00

Preparing Directories

rm -rf /compile/cluster-restore/cfg*

mkdir -p /compile/cluster-restore/cfg1/data/db

mkdir -p /compile/cluster-restore/cfg1/log

mkdir -p /compile/cluster-restore/cfg2/data/db

mkdir -p /compile/cluster-restore/cfg2/log

mkdir -p /compile/cluster-restore/cfg3/data/db

mkdir -p /compile/cluster-restore/cfg3/log

Procedure

  1. Prepare the configuration file and data directory of a single node and start the process in single-node mode.

    1. The configuration file is as follows (restoreconfig/single_40303.yaml):
      net:
        bindIp: 127.0.0.1
        port: 40303
        unixDomainSocket: {enabled: false}
      processManagement: {fork: true, pidFilePath: /compile/cluster-restore/cfg1/configsvr.pid}
      storage:
        dbPath: /compile/cluster-restore/cfg1/data/db/ 
        directoryPerDB: true
        engine: wiredTiger
        wiredTiger:
          collectionConfig: {blockCompressor: snappy}
          engineConfig: {directoryForIndexes: true, journalCompressor: snappy}
          indexConfig: {prefixCompression: true}
      systemLog: {destination: file, logAppend: true, logRotate: reopen, path: /compile/cluster-restore/cfg1/log/configsingle.log}
    2. Copy the decompressed configsvr file to the dbPath directory on the single node.

      cp -aR

      /compile/download/backups/cac1efc8e65e42ecad8953352321bfeein02_41c8a32fb10245899708dea453a8c5c9no02/* /compile/cluster-restore/cfg1/data/db/

    3. Start the process.

      ./mongod -f restoreconfig/single_40303.yaml

  2. Connect to the single node and run the following configuration command:

    ./mongo --host 127.0.0.1 --port 40303
    1. Run the following commands to modify the replica set configuration:

      var cf=db.getSiblingDB('local').system.replset.findOne();

      cf['members'][0]['host']='127.0.0.1:40303';

      cf['members'][1]['host']='127.0.0.1:40304';

      cf['members'][2]['host']='127.0.0.1:40305';

      cf['members'][0]['hidden']=false;

      cf['members'][1]['hidden']=false;

      cf['members'][2]['hidden']=false;

      cf['members'][0]['priority']=1;

      cf['members'][1]['priority']=1;

      cf['members'][2]['priority']=1;

      db.getSiblingDB('local').system.replset.remove({});

      db.getSiblingDB('local').system.replset.insert(cf)

    2. Run the following commands to clear the built-in accounts:

      db.getSiblingDB('admin').dropAllUsers();

      db.getSiblingDB('admin').dropAllRoles();

    3. Run the following command to update the dds mongos and shard information:

      db.getSiblingDB('config').mongos.remove({});

      Query the _id information about multiple shards in the config.shards table. The _id information is used as the query condition of _id in the following statements. Update records in sequence.

      db.getSiblingDB('config').shards.update({'_id' : 'shard_1'},{$set: {'host': 'shard_1/127.0.0.1:40306,127.0.0.1:40307,127.0.0.1:40308'}})

      db.getSiblingDB('config').shards.update({'_id' : 'shard_2'},{$set: {'host': 'shard_2/127.0.0.1:40309,127.0.0.1:40310,127.0.0.1:40311'}})

      db.getSiblingDB('config').mongos.find({});

      db.getSiblingDB('config').shards.find({});

    4. Run the following command to stop the single-node process:

      db.getSiblingDB('admin').shutdownServer();

  3. Create a configsvr replica set.

    1. Copy the dbPath file of the configsvr1 node to the directories of the other two configsvr nodes.

      cp -aR /compile/cluster-restore/cfg1/data/db/ /compile/cluster-restore/cfg2/data/db/

      cp -aR /compile/cluster-restore/cfg1/data/db/ /compile/cluster-restore/cfg3/data/db/

    2. Add the replica set configuration attribute to the configuration file (restoreconfig/configsvr_40303.yaml) of the configsvr-1 node.
      net:
        bindIp: 127.0.0.1
        port: 40303
        unixDomainSocket: {enabled: false}
      processManagement: {fork: true, pidFilePath: /compile/cluster-restore/cfg1/configsvr.pid}
      replication: {replSetName: config}
      sharding: {archiveMovedChunks: false, clusterRole: configsvr}
      storage:
        dbPath: /compile/cluster-restore/cfg1/data/db/ 
        directoryPerDB: true
        engine: wiredTiger
        wiredTiger:
          collectionConfig: {blockCompressor: snappy}
          engineConfig: {directoryForIndexes: true, journalCompressor: snappy}
          indexConfig: {prefixCompression: true}
      systemLog: {destination: file, logAppend: true, logRotate: reopen, path: /compile/cluster-restore/cfg1/log/configsvr.log}
    1. Start the process.

      ./mongod -f restoreconfig/configsvr_40303.yaml

    2. Add the replica set configuration attribute to the configuration file (restoreconfig/configsvr_40304.yaml) of the configsvr-2 node.
      net:
        bindIp: 127.0.0.1
        port: 40304
        unixDomainSocket: {enabled: false}
      processManagement: {fork: true, pidFilePath: /compile/cluster-restore/cfg2/configsvr.pid}
      replication: {replSetName: config}
      sharding: {archiveMovedChunks: false, clusterRole: configsvr}
      storage:
        dbPath: /compile/cluster-restore/cfg2/data/db/ 
        directoryPerDB: true
        engine: wiredTiger
        wiredTiger:
          collectionConfig: {blockCompressor: snappy}
          engineConfig: {directoryForIndexes: true, journalCompressor: snappy}
          indexConfig: {prefixCompression: true}
      systemLog: {destination: file, logAppend: true, logRotate: reopen, path: /compile/cluster-restore/cfg2/log/configsvr.log}
    3. Start the process.

      ./mongod -f restoreconfig/configsvr_40304.yaml

    4. Add the replica set configuration attribute to the configuration file (restoreconfig/configsvr_40305.yaml) of the configsvr-3 node.
      net:
        bindIp: 127.0.0.1
        port: 40305
        unixDomainSocket: {enabled: false}
      processManagement: {fork: true, pidFilePath: /compile/cluster-restore/cfg3/configsvr.pid}
      replication: {replSetName: config}
      sharding: {archiveMovedChunks: false, clusterRole: configsvr}
      storage:
        dbPath: /compile/cluster-restore/cfg3/data/db/ 
        directoryPerDB: true
        engine: wiredTiger
        wiredTiger:
          collectionConfig: {blockCompressor: snappy}
          engineConfig: {directoryForIndexes: true, journalCompressor: snappy}
          indexConfig: {prefixCompression: true}
      systemLog: {destination: file, logAppend: true, logRotate: reopen, path: /compile/cluster-restore/cfg3/log/configsvr.log}
    5. Start the process.

      ./mongod -f restoreconfig/configsvr_40305.yaml

  4. Wait until the primary node is selected.

    ./mongo --host 127.0.0.1 --port 40303

    Run the rs.status() command to check whether the primary node exists.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback