Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MongoDB builds Replica Set replication set

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Create a data directory under the peer installation directory of MongoDB. The directory structure is as follows:

/ data/rs0 / data/rs1

/ data/rs2

2. Use the command line to start three instances of mongod, open three command line windows, and enter the following commands:

Mongod-- port 10000-- dbpath E:/field/replset/data/rs0-- replSet rscx-- smallfiles-- oplogSize 128mongod-- port 10001-- dbpath E:/field/replset/data/rs1-- replSet rscx-- smallfiles-- oplogSize 128mongod-- port 10002-- dbpath E:/field/replset/data/rs2-- replSet rscx-- smallfiles-- oplogSize

After executing the above command, the instance service of MongoDB has been started, and we can see some data configuration files automatically generated by MongoDB under the newly created data directory. But at the same time, we will also find that the command line will keep typing "replSet can't get local.system.replset config from self or any seed", this is because the collection loccal.system.replset does not have any configuration information, we also need to execute rs.initiate on the command line to initialize.

Open a command line window and we connect to the first instance.

Mongo-port 10000

Continue to enter configuration information for mongodb replicate sets on the command line, and then execute rs.initiate (rsconf) to initialize the configuration information.

Rsconf = {_ id: "rs0", members: [{_ id: 0, host: ": 27017"}]} rs.initiate (rsconf)

At this step, if the reader is not careful and forgets to add parameters when executing the rs.initialte method, you can reinitialize the configuration file through rs.reconfig (rsconf).

Next, run the rs.conf () command, and we can see that the replication set information is displayed as shown below.

Rscx:PRIMARY > rs.conf () {"_ id": "rscx", "version": 2, "members": [{"_ id": 0, "host": "favpc:10000"}]}

Next, continue to run the following command to add the other two configuration sets to the replication set.

Rs.add ("favpc": 10001) rs.add ("favpc": 10002)

At this point, the Replica Sets replication set is built successfully. We can also see that the command line window of the mongodb replication set no longer prints replSet can't get local.system.replset config from self or any seed, but instead prints the connection information of the replication set. When we update the data at the master node, the slave node will also update the data automatically.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report