目录
环境
操作系统:Amazon Linux 2
MongoDB版本:4.2.18
源端mongoDB:ip-10-10-1-12.ap-southeast-1.compute.internal或13.212.6.205
目标端MongoDB:ip-10-11-3-1.ap-southeast-1.compute.internal或13.212.248.207
MongoShake节点:ip-10-11-0-147.ap-southeast-1.compute.internal或13.212.91.106
一、副本集迁移
1.1 MongoDB安装(源端和目标端都需要安装)
MongoDB 源码下载地址:https://www.mongodb.com/download-center#community
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon2-4.2.18.tgz
tar -zxvf mongodb-linux-x86_64-amazon2-4.2.18.tgz
mv mongodb-linux-x86_64-amazon2-4.2.18.tgz /usr/local/mongodb4
export PATH=/usr/local/mongodb4/bin:$PATH
创建数据库目录
sudo mkdir -p /var/lib/mongo
sudo mkdir -p /var/log/mongodb
sudo chown `whoami` /var/lib/mongo
sudo chown `whoami` /var/log/mongodb
以副本集方式启动MongoDB,–bind_ip开启远程访问
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork --replSet rs0 --bind_ip 0.0.0.0
mongo localhost # 进入mongo命令行
>rs.initiate()
>rs.conf()
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --shutdown # 关闭mongodb
创建数据库和测试数据(在源端进入到mongo命令行中执行,目标端不需要执行)
use paas
db.createCollection("paas1")
for(i=1;i<=100000;i++) db.paas1.insert(
{
title: 'paas1_'+i,
descriptionage: '(Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster. You can use Amazon EC2 to launch as many or as few virtual servers as you need, configure security and networking, and manage storage. Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic.Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster. You can use Amazon EC2 to launch as many or as few virtual servers as you need, configure security and networking, and manage storage. Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic.Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster. You can use Amazon EC2 to launch as many or as few virtual servers as you need, configure security and net