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

How to realize slicing and clustering in MongoDB

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

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to achieve slicing and clustering in MongoDB. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1. Mongodb fragmentation and cluster topology diagram

II. Deployment of fragmentation and cluster

Installation of 1.Mongodb

Install mongodb on the above three servers

For installation methods, see the installation script.

2.Mongod creates a replica set of individual fragments

10.68.4.209

① establishes data folder and log folder

Mdkir / data/ {master,slave,arbiter}

Mkdir / data/log/mongodb/ {master,slave,arbiter}-p

② establishes a configuration file

# master.conf dbpath=/data/master logpath=/data/log/mongodb/master/mongodb.log pidfilepath=/var/run/mongo_master.pid # directoryperdb=true logappend=true replSet=policydb port=10002 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200 # slave.conf dbpath=/data/slave logpath=/data/log/mongodb/slave/mongodb.log pidfilepath=/var/run/mongo_slave.pid # directoryperdb=true logappend=true replSet=policydb port=10001 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200 # arbiter.conf dbpath=/data/arbiter logpath=/data/log/mongodb/arbiter/mongodb.log pidfilepath=/var/run/mongo_ Arbiter.pid # directoryperdb=true logappend=true replSet=policydb port=10000 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200

③ starts mongodb

/ etc/init.d/mongodb_master start

/ etc/init.d/mongodb_slave start

/ etc/init.d/mongodb_arbiter start

④ configures primary, standby and arbitration nodes

Primary node:

# / usr/local/mongodb/bin/mongo 10.68.4.209 connecting to 10002 MongoDB shell version: 2.4.9 connecting to: 10.68.4.209:10002/test > use admin switched to db admin > config= {_ id: "policydb", members: [{_ id:0,host:'10.68.4.209:10002',priority:2}, {_ id:1,host:'10.68.4.209:10001',priority:1},. {_ id:2 Host:'10.68.4.209:10000',arbiterOnly:true}]} {"_ id": "policydb", "members": [{"_ id": 0, "host": "10.68.4.209 id 10002", "priority": 2}, {"_ id": 1, "host": "10.68.4.209 id 10001", "priority": 1}, {"_ id": 2, "host": "10.68.4.209 members" "arbiterOnly": true}]} rs.initiate (config) # initialize rs.status () # View cluster status

10.68.4.29

① establishes data folder and log folder

Mdkir / data/ {master,slave,arbiter}

Mkdir / data/log/mongodb/ {master,slave,arbiter}-p

② establishes a configuration file

# master.conf dbpath=/data/master logpath=/data/log/mongodb/master/mongodb.log pidfilepath=/var/run/mongo_master.pid # directoryperdb=true logappend=true replSet=policydb2 port=10002 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200 # slave.conf dbpath=/data/slave logpath=/data/log/mongodb/slave/mongodb.log pidfilepath=/var/run/mongo_slave.pid # directoryperdb=true logappend=true replSet=policydb2 port=10001 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200 # arbiter.conf dbpath=/data/arbiter logpath=/data/log/mongodb/arbiter/mongodb.log pidfilepath=/var/run/mongo_ Arbiter.pid # directoryperdb=true logappend=true replSet=policydb2 port=10000 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200 ③ starts mongodb / etc/init.d/mongodb_master start / etc/init.d/mongodb_slave start / etc/init.d/mongodb_arbiter start

④ configures primary, standby and arbitration nodes

Primary node:

# / usr/local/mongodb/bin/mongo 10.68.4.209 connecting to 10002 MongoDB shell version: 2.4.9 connecting to: 10.68.4.209:10002/test > use admin switched to db admin > config= {_ id: "policydb2", members: [{_ id:0,host:'10.68.4.29:10002',priority:2}, {_ id:1,host:'10.68.4.29:10001',priority:1},. {_ id:2 Host:'10.68.4.209:10000',arbiterOnly:true}]} {"_ id": "policydb", "members": [{"_ id": 0, "host": "10.68.4.29 host 10002", "priority": 2}, {"_ id": 1, "host": "10.68.4.29 id 10001", "priority": 1}, {"_ id": 2, "host": "10.68.4.2910 000" "arbiterOnly": true}]} rs.initiate (config) # initialize rs.status () # View cluster status

10.68.4.30

① establishes data folder and log folder

Mdkir / data/ {master,slave,arbiter}

Mkdir / data/log/mongodb/ {master,slave,arbiter}-p

② establishes a configuration file

# master.conf dbpath=/data/master logpath=/data/log/mongodb/master/mongodb.log pidfilepath=/var/run/mongo_master.pid # directoryperdb=true logappend=true replSet=policydb3 port=10002 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200 # slave.conf dbpath=/data/slave logpath=/data/log/mongodb/slave/mongodb.log pidfilepath=/var/run/mongo_slave.pid # directoryperdb=true logappend=true replSet=policydb3 port=10001 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200 # arbiter.conf dbpath=/data/arbiter logpath=/data/log/mongodb/arbiter/mongodb.log pidfilepath=/var/run/mongo_ Arbiter.pid # directoryperdb=true logappend=true replSet=policydb3 port=10000 oplogSize=10000 fork=true noprealloc=true profile=1 slowms=200

③ starts mongodb

/ etc/init.d/mongodb_master start

/ etc/init.d/mongodb_slave start

/ etc/init.d/mongodb_arbiter start

④ configures primary, standby and arbitration nodes

Primary node:

# / usr/local/mongodb/bin/mongo 10.68.4.209 connecting to 10002 MongoDB shell version: 2.4.9 connecting to: 10.68.4.209:10002/test > use admin switched to db admin > config= {_ id: "policydb3", members: [{_ id:0,host:'10.68.4.30:10002',priority:2}, {_ id:1,host:'10.68.4.30:10001',priority:1},. {_ id:2 Host:'10.68.4.30:10000',arbiterOnly:true}]} {"_ id": "policydb", "members": [{"_ id": 0, "host": "10.68.4.30 host 10002", "priority": 2}, {"_ id": 1, "host": "10.68.4.30 id 10001", "priority": 1}, {"_ id": 2, "host": "10.68.4.30 host" "arbiterOnly": true}]} rs.initiate (config) # initialize rs.status () # View cluster status

2.Mongod creates a single shard configuration server

① creates a configuration directory

10.68.4.209 mkdir / data/config

10.68.4.29 mkdir / data/config

10.68.4.30 mkdir / data/config

② prepares to configure the configuration file for the server

The configuration files of the three servers are the same.

# config.conf dbpath=/data/config logpath=/data/log/mongodb/config/mongodb.log pidfilepath=/var/run/mongo_config.pid directoryperdb=true logappend=true port=10003 fork=true configsvr=true

③ Startup configuration Server

/ etc/init.d/mongodb_config start

3.Mongod creates and configures mongos and enables sharding mode

① creates a log directory

Mkdir-p / data/log/mongodb/mongos/

② prepares the configuration file for mongos

# mongos.conf logpath=/data/log/mongodb/mongos/mongodb.log pidfilepath=/var/run/mongo_mongos.pid logappend=true port=10004 fork=true configdb=10.68.4.209:10003,10.68.4.29:10003,10.68.4.30:1000

③ starts mongos

/ etc/init.d/mongodb_mongos start

④ configuration fragmentation

Sh.addShard ("policydb/10.68.4.209:10002") sh.addShard ("policydb2/10.68.4.29:10002") sh.addShard ("policydb3/10.68.4.30:10002") sh.enableSharding ("policydb") db.runCommand ({"shardcollection": "policydb.fullPolicyTextInfo_history", "key": {"key": 1}}) db.printShardingStatus () # View the shard status sh.status ({verbose:true}) sh.status ()

3. Quickly create replica sets and configure service scripts

The picture above

1. Figure 1

two。 Figure 2 config.conf configuration file

3. Figure 3

The above is how to achieve sharding and clustering in the MongoDB shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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