公司的实战ReplicaSets+Sharding方案
公司的实战 Replica Sets+Sharding 方案 公司 mongo 集群分片实战 准备九台服务器, 分片 1 : 172.16.0.124:11731 主 172.16.0.127.11731 备 172.16.0.115:11731 仲裁 分片 2 : 172.16.0.122:11732 主 172.16.0.125:11732 备 172.16.0.103:11732 仲裁 分片
公司的实战Replica Sets+Sharding方案
公司mongo集群分片实战
准备九台服务器,
分片1:
172.16.0.124:11731 主
172.16.0.127.11731 备
172.16.0.115:11731 仲裁
分片2:
172.16.0.122:11732 主
172.16.0.125:11732 备
172.16.0.103:11732 仲裁
分片3:
172.16.0.121:11733 主
172.16.0.123:11733 备
172.16.0.114:11733 仲裁
分片1步骤
--172.16.0.124分片1主
创建目录
mkdir -p /home/data/shard1_1
mkdir -p /home/Apps
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
启动服务
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard1 --port 11731 --dbpath /home/data/shard1_1 --logpath /home/data/shard1_1/shard1_1.log --logappend --oplogSize 5000 --fork
--172.16.0.127分片1备
mkdir -p /home/data/shard1_2
mkdir -p /home/Apps
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
启动服务
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard1 --port 11731 --dbpath /home/data/shard1_2 --logpath /home/data/shard1_2/shard1_2.log --logappend --oplogSize 5000 --fork
--172.16.0.115分片1仲载
mkdir -p /home/data/shard1_3
mkdir -p /home/Apps
mkdir -p /home/data/config
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard1 --port 11731 --dbpath /home/data/shard1_3 --logpath /home/data/shard1_3/shard1_3.log --logappend --oplogSize 5000 --fork
分片1启动好,初始化Replica Set1 arbiterOnly:true仲裁
在分片1主 172.16.0.124操作如下
/home/Apps/mongo/bin/mongo --port 11731
config={_id:'shard1',members:[{_id:0,host:'172.16.0.124:11731'},{_id:1,host:'172.16.0.127:11731'},{_id:2,host:'172.16.0.115:11731',arbiterOnly:true}]}
rs.initiate(config)
------------------------------------------------------------------------------------------------------------------------------
分片2步骤
--172.16.0.122分片2主
创建目录
mkdir -p /home/data/shard2_1
mkdir -p /home/Apps
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
启动服务
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard2 --port 11732 --dbpath /home/data/shard2_1 --logpath /home/data/shard2_1/shard2_1.log --oplogSize 50000 --logappend --fork
--172.16.0.125分片2备
mkdir -p /home/data/shard2_2
mkdir -p /home/Apps
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
启动服务
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard2 --port 11732 --dbpath /home/data/shard2_2 --logpath /home/data/shard2_2/shard2_2.log --oplogSize 50000 --logappend --fork
--172.16.0.103分片2仲载
mkdir -p /home/data/shard2_3
mkdir -p /home/Apps
mkdir -p /home/data/config
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard2 --port 11732 --dbpath /home/data/shard2_3 --logpath /home/data/shard2_3/shard2_3.log --oplogSize 50000 --logappend --fork
分片2启动好,初始化Replica Set 2 arbiterOnly:true仲裁
在分片2主 172.16.0.122操作如下
/home/Apps/mongo/bin/mongo --port 11732
config={_id:'shard2',members:[{_id:0,host:'172.16.0.122:11732'},{_id:1,host:'172.16.0.125:11732'},{_id:2,host:'172.16.0.103:11732',arbiterOnly:true}]}
rs.initiate(config)
-----------------------------------------------------------------------------------------------------------
分片3步骤
--172.16.0.121分片3主
创建目录
mkdir -p /home/data/shard3_1
mkdir -p /home/Apps
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
启动服务
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard3 --port 11733 --dbpath /home/data/shard3_1 --logpath /home/data/shard3_1/shard3_1.log --oplogSize 50000 --logappend --fork
--172.16.0.123分片3备
mkdir -p /home/data/shard2_2
mkdir -p /home/Apps
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
启动服务
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard3 --port 11733 --dbpath /home/data/shard3_2 --logpath /home/data/shard3_2/shard3_2.log --oplogSize 50000 --logappend --fork
--172.16.0.114分片3仲载
mkdir -p /home/data/shard3_3
mkdir -p /home/Apps
mkdir -p /home/data/config
tar zxvf mongodb-linux-x86_64-2.4.7.tgz
mv mongodb-linux-x86_64-2.4.7 /home/Apps/mongo
/home/Apps/mongo/bin/mongod --shardsvr --replSet shard3 --port 11733 --dbpath /home/data/shard3_3 --logpath /home/data/shard3_3/shard3_3.log --oplogSize 50000 --logappend --fork
分片3启动好,初始化Replica Set 3 arbiterOnly:true仲裁
在分片3主 172.16.0.121操作如下
/home/Apps/mongo/bin/mongo --port 11733
config={_id:'shard3',members:[{_id:0,host:'172.16.0.121:11733'},{_id:1,host:'172.16.0.123:11733'},{_id:2,host:'172.16.0.114:11733',arbiterOnly:true}]}
rs.initiate(config)
配置3个分片Config Server
在172.16.0.115,172.16.0.103,172.16.0.114 这三台执行操作,如下面代码
/home/Apps/mongo/bin/mongod --configsvr --dbpath /home/data/config --port 30000 --logpath /home/data/config/config.log --logappend --fork
配置3个分片Route Process
在172.16.0.115,172.16.0.103,172.16.0.114 这三台执行操作,如下面代码
/home/Apps/mongo/bin/mongos --configdb 172.16.0.115:30000,172.16.0.103:30000,172.16.0.114:30000 -port 60000 --chunkSize 1 --logpath /home/data/mongos.log --logappend --fork
配置Shard Cluster
在172.16.0.115,172.16.0.103,172.16.0.114 这三台其中一台执行操作,如下面代码
/home/Apps/mongo/bin/mongo --port 60000
use admin
db.runCommand({addshard:"shard1/172.16.0.124:11731, 172.16.0.127:11731, 172.16.0.115:11731"})
db.runCommand({addshard:"shard2/172.16.0.122:11732, 172.16.0.125:11732, 172.16.0.103:11732"})
db.runCommand({addshard:"shard3/172.16.0.121:11733, 172.16.0.123:11733, 172.16.0.114:11733"})
接下来激活分片,如下面的代码所示: 采用hash分片
db.runCommand({enablesharding:"test"})
db.runCommand({shardcollection:"test.users",key:{id:"hashed"}})
强调服务时间必须要同步,否则有问题

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Artificial intelligence is a computing system that attempts to imitate human intelligence, including some human functions that are intuitively related to intelligence, such as learning, problem solving, and rational thinking and action. Broadly interpreted, the term AI covers many closely related fields such as machine learning. Systems that make heavy use of AI are having significant social impacts in areas such as healthcare, transportation, finance, social networks, e-commerce, and education. This growing social impact has also brought with it a series of risks and concerns, including errors in artificial intelligence software, cyberattacks and artificial intelligence system security. Therefore, the issue of verification of AI systems, and the broader topic of trustworthy AI, has begun to attract attention from the research community. “Verifiable AI” has been confirmed

Blue Star Travel Ballad has been on the game hot list after the recent release of a promotional video. Many players are very curious about which company Blue Star Travel Ballad is made from. In fact, it is a new game from Shanghai 2D manufacturer Manjiu. The editor will explain it to you below. Here is the introduction of Blue Star Yuanluyao Game Company, come and take a look together. Which company does Blue Star Travel Yao come from? Answer: It was launched by Manjiu Network. 1. First of all, Blue Star Travel Yao is a game launched by Manju’s Big World RPG. A promotional video was released on March 20. 2. This product will get its version number in October 2023. The game's trademark and operating unit are both registered under the name of a company called. The latter was established in February 2023, and its official website shows that its headquarters is in Singapore. 3. The 11-minute promotional video released this time revealed this

PHP Practice: Code Example to Quickly Implement the Fibonacci Sequence The Fibonacci Sequence is a very interesting and common sequence in mathematics. It is defined as follows: the first and second numbers are 0 and 1, and from the third Starting with numbers, each number is the sum of the previous two numbers. The first few numbers in the Fibonacci sequence are 0,1,1.2,3,5,8,13,21,...and so on. In PHP, we can generate the Fibonacci sequence through recursion and iteration. Below we will show these two

Hands-on is a brand new chat and dating software, so which company is the Hand-on-hand app? This software was created by Tianjin Laifu Cultural Development Co., Ltd. You can download it from Xiaomi Mall and Apple Mall. This introduction to the Hands-on app creation company can tell you the specific methods. The following is a detailed introduction, so take a look. Which company is the Qianshou app? Answer: Tianjin Laifu Cultural Development Co., Ltd. Detailed description: On the official software website https://www.qianshouapp.cn/, you can see the company name at the bottom. Software introduction: 1. It can filter according to the conditions that users like, and can find the objects they need faster. 2. It can help users search for the objects they need faster.

Java Development Practice: Integrating Qiniu Cloud Storage Service to Implement File Upload Introduction With the development of cloud computing and cloud storage, more and more applications need to upload files to the cloud for storage and management. The advantages of cloud storage services are high reliability, scalability and flexibility. This article will introduce how to use Java language development, integrate Qiniu cloud storage service, and implement file upload function. About Qiniu Cloud Qiniu Cloud is a leading cloud storage service provider in China, providing comprehensive cloud storage and content distribution services. Users can use Qiniu Yunti

According to the company that owns Mingchao Game, many friends said they like this game very much after watching the latest character demonstration PV. Some of them are curious about which company produced Mingchao. Let me tell you. Everyone wonders which company produced Mingchao. Introduction to the company that owns Mingchao Game: Mingchao is an open-world action game developed by Guangzhou Culuo Technology Co., Ltd. 1. Mingchao is an open-world action mobile game produced and released by Guangzhou Culuo Technology Co., Ltd.; 2. The technical test of the game will start on July 4, 2022, and the resonance test will start on April 20, 2023; 3. The latest round of Sonata test is currently recruiting qualifications. You can go to draw test qualifications and experience the game in advance; 4. Sonata test recruitment

Large companies using PHP: 1. Facebook, one of the world's largest social media platforms; 2. Wikipedia, the world's largest online encyclopedia; 3. Slack, a popular team collaboration tool; 4. Etsy, a world-renowned Handicraft market; 5. WordPress, the world's most popular personal and business website building platform; 6. Magento, a popular e-commerce platform; 9. MailChimp, a popular email marketing platform.

MySQL table design practice: Create an e-commerce order table and product review table. In the database of the e-commerce platform, the order table and product review table are two very important tables. This article will introduce how to use MySQL to design and create these two tables, and give code examples. 1. Design and creation of order table The order table is used to store the user's purchase information, including order number, user ID, product ID, purchase quantity, order status and other fields. First, we need to create a table named "order" using CREATET
