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了。
,美国服务器

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool