资源描述:
《centos下搭建mongodb集群》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、centos下搭建mongodb集群mongodbcentos 安装前先同步服务器时间: a.yuminstallntp b.ntpdate210.72.145.44 配置总览: 3个分片sharding 每一个分片由3个节点构成1主2备的ReplicaSets 3个配置节点Configsever 1个路由节点Mongos 步骤: 首先安装mongodb:将其解压到/usr,再重命名为mongodb,路径为/usr/mongodb1.创建分片: serverA: mkdir-p/data/a/r0 mkdir-p/data/b/r0 mkdir-p/
2、data/c/r0 mkdir-p/data/logs/a mkdir-p/data/logs/b mkdir-p/data/logs/c mkdir-p/data/configServer/r0 mkdir-p/data/logs/configServer mkdir-p/data/logs/serverlogs ./mongod--logpath/data/logs/a/r0.log--logappend--dbpath/data/a/r0--port10000--shardsvr--replSetsetA--rest --oplogSize64
3、--fork serverBserverC 执行同上命令。 2.初始化复制集setA: ./mongo192.168.1.115:10000/admin config={_id:'setA',members:[{_id:0,host:'192.168.1.115:10000'},{_id:1,host:'192.168.1.116:10000'},{_id:2,host:'192.168.1.117:10000'}]} rs.initiate(config); 3.初始化复制集setB: ./mongod--logpath/data/logs/b/r
4、0.log--logappend--dbpath/data/b/r0--port20000--shardsvr--replSetsetB--rest --oplogSize64--fork ./mongo192.168.1.116:20000/admin config={_id:'setB',members:[{_id:0,host:'192.168.1.115:20000'},{_id:1,host:'192.168.1.116:20000'},{_id:2,host:'192.168.1.117:20000'}]} rs.initiate(con
5、fig); 4.初始化复制集setC: ./mongod--logpath/data/logs/c/r0.log--logappend--dbpath/data/c/r0--port30000--shardsvr--replSetsetC--rest --oplogSize64--fork ./mongo192.168.1.117:30000/admin config={_id:'setC',members:[{_id:0,host:'192.168.1.115:30000'},{_id:1,host:'192.168.1.116:30000'},{
6、_id:2,host:'192.168.1.117:30000'}]} rs.initiate(config); 5.配置configServer: 115116117上执行 ./mongod--configsvr--logpath/data/logs/configServer/r0.log--logappend--dbpath/data/configServer/r0--port40000--shardsvr--fork 6.启动路由节点: 115上执行: ./mongos--configdb192.168.1.115:40000,192.168.
7、1.116:40000,192.168.1.116:40000--logpath /data/logs/serverlogs/mongos.log--logappend--port50000--fork 7.配置分片 115上执行: ./mongo127.0.0.1:50000 useadmin db.runCommand({addshard:"setA/192.168.1.115:10000,192.168.1.116:10000,192.168.1.117:10000",name:"ShardSetA"})db.runCommand({adds
8、hard:"setB/192.168.1.115:20000,192.168.1.116:20000,192