MongoDB到MongoDB迁移-MongoShake

环境

操作系统: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
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值