一.mongodb分片之win7环境下模拟多节点添加与移除分片
本文主要介绍在一台win7电脑上模拟mongo分片。如果有多台服务器,可以将每个mongo部署在单台电脑上。我们将配置3个mongo分片,3个配置服务器,1个路由服务器。如下图所示进行配置,介绍如何增加分片、移除分片。 vcD4KPHA+PHN0cm9uZz7Su6Ouz8LU2G1vbmdvZGI8L
本文主要介绍在一台win7电脑上模拟mongo分片。如果有多台服务器,可以将每个mongo部署在单台电脑上。我们将配置3个mongo分片,3个配置服务器,1个路由服务器。如下图所示进行配置,介绍如何增加分片、移除分片。
喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PHN0cm9uZz7Su6Ouz8LU2G1vbmdvZGI8L3N0cm9uZz48L3A+CjxwPs/C1Ni12Na3o7podHRwOi8vd3d3Lm1vbmdvZGIub3JnLzwvcD4KPHA+PGltZyBzcmM9"http://www.2cto.com/uploadfile/Collfiles/20141202/2014120209234283.png" alt="\">
二.下载windows zip版本,解压到一个目录中,并且复制7份,命名如下图:

三.分别在bin目录下建立 config.bat文件 文件内容如下列表格中所述。
注意在mongodb_xxxx目录下建data文件夹
注:路由配置中:mongos --port 2222 --configdb 127.0.0.1:2001,127.0.0.1:2002,127.0.0.1:2003
表示将路由器与配置服务器连接起来,使得他们自己可以认识对方。
四.启动:分别按照下列顺序启动mongo
1.点击配置服务器1的config.bat,启动配置
2.点击配置服务器2的config.bat,启动配置
3.点击配置服务器3的config.bat,启动配置
4.点击路由器1的config.bat,启动路由服务
5.点击分片1的config.bat,启动分片
6.点击分片2的config.bat,启动分片
7.点击分片3的config.bat,启动分片
注:启动完分片后,分片与路由之间还没有建立连接,他们是独立的,通过下面一步增加分片。
五.进入cmd命令终端,执行下列语句,client连接mongos,注意用admin连接

六.通过执行addShard命令增加分片,命令如下,增加2004,2005,2006端口的分片

七.为分片增加数据集合,测试分片
1.我们设定集合数据库名为:blog,用下列语句启用分片:
2.要进行分片必须指定集合和片键,假设我们在博客系统时间与作者上进行分片,执行语句如下:
注意,blog是数据库名,posts类似于关系型中的表名。如果要对一个已经包含数据的集合进行分片,数据片键上必须有索引。
所有文档也都必须有片键值(且不能为null)。
八.分片优化注意
1.根据分片磁盘容量设置分片最大数据量执行下面的语句,增加一个分片且只使用20GB
db.runCommand(‘addShard’:’127.0.0.1:2007’,’maxSize’:20000);
2.在添加新分片时,应该在mongo不是高度负载情况下添加,否者mongo在迁移数据时,会把应用正在使用的数据迁移到硬盘中,这样查询就会非常满。
九.移除分片
1.有时也需要移除分片,执行如下命令:
此时draining started successfunlly 表示正在进行分片移除,会将2006上数据迁移到其他分片上,这个过程非常耗时间。通过下面命令检测是否已经完成移除。
2.检测是否完成移除分片,再次执行下来语句,返回completed,表示移除完成,移除后就可以对2006进行任何操作了,关机也无所谓了。
3.如果使用了副本集,对某个副本集进行修改,应该连接副本集主服务器进行修改相应配置。

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

AI Hentai Generator
Generate AI Hentai for free.

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

Recently, many users using Win7 system have found that the icons in the taskbar suddenly disappeared, which makes the operation very inconvenient and they do not know how to solve the problem. This article will introduce to you how to solve the problem of disappearing taskbar icons in Win7 system. Bar! Cause Analysis When encountering such a situation, there are generally two situations: one is that the taskbar on the computer does not really disappear, but is just hidden, and the other is that the taskbar does disappear. Method 1: 1. There is a situation that you need to confirm first, that is, when the mouse is placed at the bottom of the screen, the taskbar will be displayed. You can directly click the mouse on the taskbar and select "Properties". 2. In the dialog box that opens, click & on the "Hide taskbar" option.

1. First, select the Control Panel option in the Start button of the Win7 system. 2. Then in the control panel that pops up, click the [User Accounts and Family Safety] item. 3. Then click [Credential Manager] in the pop-up interface. 4. Finally, click [Add Windows Credentials] to create your credentials. The operation method of adding and managing windows credentials in win7 is shared here in detail with friends. More exciting tutorials are available on the PHP Chinese website!

In Win7 system, many users want to delete personalized desktop background images, but do not know how to delete them. This article will show you how to delete personalized background images in Win7 system. 1. First, open the control panel interface of the Win7 system and click to enter the "Appearance and Personalization" settings; 2. Then, in the opened interface, click the "Change Desktop Background" setting; 3. Then, click below "Desktop background" option; 4. Then, select Select all, and then click Clear all. Of course, you can also use it under "Customize", right-click the theme you want to delete, and then click &q on the shortcut menu

Many computer users know that network discovery is a network setting. This setting will affect whether the computer can find other computers and devices on the network and whether it can find the computer when other computers on the network are found. So how to enable network discovery in win7? The following computer System Home U Disk Installation will introduce you to the tutorial on how to enable network discovery in win7 system. 1. First, click the "Start Menu" icon on the desktop taskbar and choose to open the "Control Panel" interface. 2. Then, in the interface that opens, set "View by" to "Category", and then choose to enter "Network and Internet"

1. Click [Start → Run] and enter gpedit.msc. On the left side of the [Group Policy] window, click the [Computer Configuration → Windows Settings → Security Settings → Software Restriction Policy] item, and then click the [Action → Create New Policy] menu item. As shown in the picture: 2. Select [Other Rules] from the left. Right-click the blank space in the right pane and select the [New Path Rule] item in the menu. In the pop-up window, click the [Browse] button after [Path], select the wscript.exe file in the C: WindowsSystem32 folder, and set the [Security Level] to [Not Allowed]. Change C: System32, Dllcache and I386 under Windows

1. Press win+r to enter the run window, enter [controluserpasswords2] and press Enter. 2. In the user account window, uncheck [To use this machine, the user must enter a username and password (E)], and then click [Apply → OK].

1. First copy the file you want to use as boot music to the corresponding directory of C: WindowsMedia. As shown in the figure: 2. Right-click the desktop on a single machine and select Personalize menu; as shown in the figure: 3. Select the sound option; as shown in the figure: 4. In the [Program Events] box in the [Sound] tab of the sound interface Select [Windows Login], then click [Browse]; as shown in the figure: 5. Select the music file that needs to be replaced, click Open, then click Apply and confirm to save the settings. as the picture shows:

1. Press and hold the [Win+R] keys to open the run dialog box, enter [regedit] in the search box, and then confirm; as shown in the figure: 2. Open HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionAuthenticationLogonUIBackgroud in the opened registry editor; as shown in the figure Display: 3. Double-click [OEMBackground] and open it, change the default value [0] to [1], and then confirm to exit; as shown in the figure: 4. Rename the image backgroundDefault.jpg, (the image size cannot exceed 256k
