Home Database Mysql Tutorial 搭建ReplicaSet复制集

搭建ReplicaSet复制集

Jun 07, 2016 pm 03:54 PM
mongodb copy Install build

1、在MongoDB的同级安装目录下创建数据目录,目录结构如下: /data/rs0 /data/rs1 /data/rs2 2、使用命令行启动mongod的三个实例,打开三个命令行窗口,分别输入命令如下: mongod --port 10000 --dbpath E:/field/replset/data/rs0 --replSet rscx --smallfi

1、在MongoDB的同级安装目录下创建数据目录,目录结构如下: /data/rs0 /data/rs1 /data/rs2   2、使用命令行启动mongod的三个实例,打开三个命令行窗口,分别输入命令如下:
mongod --port 10000 --dbpath E:/field/replset/data/rs0 --replSet rscx --smallfiles --oplogSize 128
mongod --port 10001 --dbpath E:/field/replset/data/rs1 --replSet rscx --smallfiles --oplogSize 128
mongod --port 10002 --dbpath E:/field/replset/data/rs2 --replSet rscx --smallfiles --oplogSize 128
  执行完上面的命令后,MongoDB的实例服务已经启动了,我们可以在刚刚创建数据目录下,看到MongoDB自动生成的一些数据配置文件。但同时我们也会发现命令行上会不停的打出“replSet can't get local.system.replset config from self or any seed”,这是因为集合loccal.system.replset还没有任何配置信息,我们还需要在命令行执行rs.initiate来进行初始化。      打开一个命令行窗口,我们连接到第一个实例。
mongo --port 10000
  在命令行继续输入mongodb replicate sets的配置信息,然后执行rs.initiate( rsconf )初始化配置信息。
rsconf = { _id: "rs0", members: [ { _id: 0, host: ":27017" } ] } rs.initiate( rsconf )
     在这一步,如果读者不小心,在执行rs.initialte方法时,忘记了加参数,可以通过rs.reconfig(rsconf)来重新初始化配置文件。        接下来,运行rs.conf()命令,我们能够看到会显示如下所示的复制集信息。
rscx:PRIMARY> rs.conf() { "_id" : "rscx", "version" : 2, "members" : [ { "_id" : 0, "host" : "favpc:10000" } ] }
  接下来,继续运行下面的命令,将另外两个配置集加到复制集中。
rs.add("favpc":10001) rs.add("favpc":10002)
  至此,Replica Sets复制集就搭建成功了。我们也可以看到mongodb复制集的命令行窗口不再打印replSet can't get local.system.replset config from self or any seed“,取而代       之的是打印的复制集的连接信息。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the use of net4.0 What is the use of net4.0 May 10, 2024 am 01:09 AM

.NET 4.0 is used to create a variety of applications and it provides application developers with rich features including: object-oriented programming, flexibility, powerful architecture, cloud computing integration, performance optimization, extensive libraries, security, Scalability, data access, and mobile development support.

How to configure MongoDB automatic expansion on Debian How to configure MongoDB automatic expansion on Debian Apr 02, 2025 am 07:36 AM

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

How to ensure high availability of MongoDB on Debian How to ensure high availability of MongoDB on Debian Apr 02, 2025 am 07:21 AM

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

Navicat's method to view MongoDB database password Navicat's method to view MongoDB database password Apr 08, 2025 pm 09:39 PM

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

Major update of Pi Coin: Pi Bank is coming! Major update of Pi Coin: Pi Bank is coming! Mar 03, 2025 pm 06:18 PM

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

The best software choice for building a mobile virtual live broadcast room (key skills in using key software to create a virtual live broadcast room) The best software choice for building a mobile virtual live broadcast room (key skills in using key software to create a virtual live broadcast room) Sep 02, 2024 pm 03:17 PM

With the rapid development of mobile Internet, mobile live broadcast has become a popular way of social entertainment. In order to improve the quality and experience of live broadcasts, many anchors have begun to look for solutions to build virtual live broadcast rooms. This article will focus on several software suitable for building a mobile virtual live broadcast room, and share some key skills to help anchors create a professional-level live broadcast space. 1. Choose suitable virtual live broadcast software. To build a mobile virtual live broadcast room, you first need to choose a suitable software. There are many excellent options on the market, such as OBS Studio, XSplit Gamecaster, etc., which provide rich functions and user-friendly interfaces to facilitate live broadcasts and interactions. Design a personalized live broadcast interface A personalized live broadcast

How to encrypt data in Debian MongoDB How to encrypt data in Debian MongoDB Apr 12, 2025 pm 08:03 PM

Encrypting MongoDB database on a Debian system requires following the following steps: Step 1: Install MongoDB First, make sure your Debian system has MongoDB installed. If not, please refer to the official MongoDB document for installation: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/Step 2: Generate the encryption key file Create a file containing the encryption key and set the correct permissions: ddif=/dev/urandomof=/etc/mongodb-keyfilebs=512

How to sort mongodb index How to sort mongodb index Apr 12, 2025 am 08:45 AM

Sorting index is a type of MongoDB index that allows sorting documents in a collection by specific fields. Creating a sort index allows you to quickly sort query results without additional sorting operations. Advantages include quick sorting, override queries, and on-demand sorting. The syntax is db.collection.createIndex({ field: <sort order> }), where <sort order> is 1 (ascending order) or -1 (descending order). You can also create multi-field sorting indexes that sort multiple fields.

See all articles