mongodb sharding 原理学习与试用(五)之添加与移除shard
1. 今天上午遇到一个有关host设置一部分是localhost另一部分是hostname,造成向sharding添加shard的时候失败。特纪录下来。 问题:一个已存在的sharding各个shard都是本机的其他的mongod进程,在当初添加shard的时候,db.runCommand({addshard:"localhost:po
1. 今天上午遇到一个有关host设置一部分是localhost另一部分是hostname,网站空间,造成向sharding添加shard的时候失败。特纪录下来。
问题:一个已存在的sharding各个shard都是本机的其他的mongod进程,在当初添加shard的时候,db.runCommand({addshard:"localhost:port"})。后来又在本机配置了一个replSet.问题就来了。replSet布署成功后,其中的各个节点的host使用的是hostname.这样一来,当我将replSet添加到sharding的时候报错。因为sharding的各个节点如果都是本机的其他进程的话,在设置host的时候要么全部使用localhost要么全部使用hostname,如果混用会报错。
解决过程:刚开始我打算将replSet的各个节点的host改成localhost.但是在reconfig的时候报错。报错截图如下:
之后考虑将已经添加到sharding中各个shard的host改成hostname.修改方法是use config;db.shards.update({_id:xx},{host:"xx"});这回修改成功了。之后就简单了。
2. 从sharding当中移除一个shard。需要将存储在将被移除的shard中数据移到其他的shard中。移除完成后,被移除的shard就没有数据了。
(一)移除一个shard. use admin; db.runCommand({removeshard:"name"});
(二)执行结果如上图,需要注意的是,note有提示说需要执行movePrimary操作。这是因为被移除的shard是某几个库的大本营。如果是这种情况,就需要在数据移除完之后执行movePrimary操作,为这几个库设置新的大本营。需要设置新的大本营的几个库这里也已经给出来了,例如dbsToMove的值 。如果被移除的shard不存在是任何一个库的大本营,那么就不需要执行movePrimary.如下图
(三)如上图,名为shard0001的shard并不是哪个库的大本营,因此在被移除的时候,结果输出中并没有类似于移除shard0000的时候有note与dbsToMove这两个值。需要注意的是,被移除的shard是某几个库的大本营,不管是否有库不参加分片,都需要为库设置新的大本营。如下图
(四)在数据迁移之前sar的partitioned的值是false,迁移完成执行movePrimary操作后,sar的partitioned的值仍是false.如下图。
(五)在移除数据过程中,由于网络与数据量的原因,可能需要花费不同的时间。执行db.runCommand({removeshard:"name"})命令可以查看数据迁移的进度。
(六)如上图,通过执行db.runCommand({removeshard:"name"})命令不但可以开始移除shard,还可以在移除的过程中查看数据迁移的进度。remaining的值就表示数据迁移的进度。其中chunks代表还剩多少块数据需要被迁移。当chunks的值等于0时代表数据迁移完成。dbs的值代表还剩多少个库需要设置新的大本营。movePrimary操作要等到数据迁移完成之后再进行。也就是当chunks的值等于0后才可以执行movePrimary操作。
(七)如上图,chunks的值等于0代表数据迁移已经完成。可以开始movePrimary操作。
(八)如上图,将库foo,too重新设置大本营为rs0这个shard.操作完成后,香港虚拟主机,可以查看整个移除进度了。
(九)如上图,代表整个移除过程已经全部完成。这个时候就可以放心的停掉shard0000这个shard了。
,美国服务器

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

It is recommended to use the latest version of MongoDB (currently 5.0) as it provides the latest features and improvements. When selecting a version, you need to consider functional requirements, compatibility, stability, and community support. For example, the latest version has features such as transactions and aggregation pipeline optimization. Make sure the version is compatible with the application. For production environments, choose the long-term support version. The latest version has more active community support.

Many users are increasingly favoring the electronic ecosystem of Xiaomi smart home interconnection in modern life. After connecting to the Mijia APP, you can easily control the connected devices with your mobile phone. However, many users still don’t know how to add Mijia to their homes. app, then this tutorial guide will bring you the specific connection methods and steps, hoping to help everyone in need. 1. After downloading Mijia APP, create or log in to Xiaomi account. 2. Adding method: After the new device is powered on, bring the phone close to the device and turn on the Xiaomi TV. Under normal circumstances, a connection prompt will pop up. Select "OK" to enter the device connection process. If no prompt pops up, you can also add the device manually. The method is: after entering the smart home APP, click the 1st button on the lower left

Node.js is a server-side JavaScript runtime, while Vue.js is a client-side JavaScript framework for creating interactive user interfaces. Node.js is used for server-side development, such as back-end service API development and data processing, while Vue.js is used for client-side development, such as single-page applications and responsive user interfaces.

The data of the MongoDB database is stored in the specified data directory, which can be located in the local file system, network file system or cloud storage. The specific location is as follows: Local file system: The default path is Linux/macOS:/data/db, Windows: C:\data\db. Network file system: The path depends on the file system. Cloud Storage: The path is determined by the cloud storage provider.

The MongoDB database is known for its flexibility, scalability, and high performance. Its advantages include: a document data model that allows data to be stored in a flexible and unstructured way. Horizontal scalability to multiple servers via sharding. Query flexibility, supporting complex queries and aggregation operations. Data replication and fault tolerance ensure data redundancy and high availability. JSON support for easy integration with front-end applications. High performance for fast response even when processing large amounts of data. Open source, customizable and free to use.
![Outlook stuck on adding account [Fixed]](https://img.php.cn/upload/article/000/887/227/171116770937641.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
When you encounter problems adding accounts in Outlook, you can try the following solutions to resolve it. Typically this can be caused by a faulty network connection, corrupted user profiles, or other temporary issues. Through the methods provided in this article, you can easily solve these problems and ensure that your Outlook can run normally. Outlook stuck on adding account If your Outlook is stuck on adding account, then use these fixes mentioned below: Disconnect and reconnect the internet Temporarily disable antivirus software Create a new Outlook profile Try adding account in safe mode Disable IPv6 Run Microsoft Support and Recovery Assistant Repair Office Application Outlook Add Account Required

Analysis of the role and principle of nohup In Unix and Unix-like operating systems, nohup is a commonly used command that is used to run commands in the background. Even if the user exits the current session or closes the terminal window, the command can still continue to be executed. In this article, we will analyze the function and principle of the nohup command in detail. 1. The role of nohup: Running commands in the background: Through the nohup command, we can let long-running commands continue to execute in the background without being affected by the user exiting the terminal session. This needs to be run

MongoDB is a document-oriented, distributed database system used to store and manage large amounts of structured and unstructured data. Its core concepts include document storage and distribution, and its main features include dynamic schema, indexing, aggregation, map-reduce and replication. It is widely used in content management systems, e-commerce platforms, social media websites, IoT applications, and mobile application development.
