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

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





Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,

.NET 4.0 is used to create a variety of applications and it provides application developers with rich features including: object-oriented programming, flexibility, powerful architecture, cloud computing integration, performance optimization, extensive libraries, security, Scalability, data access, and mobile development support.

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

Encrypting MongoDB database on a Debian system requires following the following steps: Step 1: Install MongoDB First, make sure your Debian system has MongoDB installed. If not, please refer to the official MongoDB document for installation: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/Step 2: Generate the encryption key file Create a file containing the encryption key and set the correct permissions: ddif=/dev/urandomof=/etc/mongodb-keyfilebs=512

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.
