mongodb 3.2.7版本 的分片集群安装demo
来源:互联网 发布:微控制器是单片机 编辑:程序博客网 时间:2024/06/06 17:33
操作步骤
cd /home/deploy/test/mongodb
这个目录为mongodb的安装目录(关于mongodb的安装,就不详述了),在该目录下建如下目录
mkdir data
cd data
#shard1目录
mkdir db1-1
mkdir db1-2
mkdir db1-3
#shard2目录
mkdir db2-1
mkdir db2-2
mkdir db2-3
#shard3目录
mkdir db3-1
mkdir db3-2
mkdir db3-3
#log目录
mkdir log
#配置文件目录
mkdir configdb1
mkdir configdb2
mkdir configdb3
#副本集db1 启动命令
/home/deploy/test/mongodb/bin/mongod --dbpath /home/deploy/test/mongodb/data/db1-1 --port 11001 --replSet db1 --logpath=/home/deploy/test/mongodb/data/log/db1-1.log --pidfilepath=/home/deploy/test/mongodb/data/db1-1.pid &
/home/deploy/test/mongodb/bin/mongod --dbpath /home/deploy/test/mongodb/data/db1-2 --port 11002 --replSet db1 --logpath=/home/deploy/test/mongodb/data/log/db1-2.log --pidfilepath=/home/deploy/test/mongodb/data/db1-2.pid &
#副本集db2 启动命令
/home/deploy/test/mongodb/bin/mongod --dbpath /home/deploy/test/mongodb/data/db2-1 --port 21001 --replSet db2 --logpath=/home/deploy/test/mongodb/data/log/db2-1.log --pidfilepath=/home/deploy/test/mongodb/data/db2-1.pid &
/home/deploy/test/mongodb/bin/mongod --dbpath /home/deploy/test/mongodb/data/db2-2 --port 21002 --replSet db2 --logpath=/home/deploy/test/mongodb/data/log/db2-2.log --pidfilepath=/home/deploy/test/mongodb/data/db2-2.pid &
#副本集db3 启动命令
/home/deploy/test/mongodb/bin/mongod --dbpath /home/deploy/test/mongodb/data/db3-1 --port 31001 --replSet db3 --logpath=/home/deploy/test/mongodb/data/log/db3-1.log --pidfilepath=/home/deploy/test/mongodb/data/db3-1.pid &
/home/deploy/test/mongodb/bin/mongod --dbpath /home/deploy/test/mongodb/data/db3-2 --port 31002 --replSet db3 --logpath=/home/deploy/test/mongodb/data/log/db3-2.log --pidfilepath=/home/deploy/test/mongodb/data/db3-2.pid &
#所有副本集的停止命令
kill -2 `cat /home/deploy/test/mongodb/data/db1-1.pid`
kill -2 `cat /home/deploy/test/mongodb/data/db1-2.pid`
kill -2 `cat /home/deploy/test/mongodb/data/db1-3.pid`
kill -2 `cat /home/deploy/test/mongodb/data/db2-1.pid`
kill -2 `cat /home/deploy/test/mongodb/data/db2-2.pid`
kill -2 `cat /home/deploy/test/mongodb/data/db2-3.pid`
kill -2 `cat /home/deploy/test/mongodb/data/db3-1.pid`
kill -2 `cat /home/deploy/test/mongodb/data/db3-2.pid`
kill -2 `cat /home/deploy/test/mongodb/data/db3-3.pid`
#副本集的配置及初始化
./mongo --port 11001
>config={
"_id":"db1",
"members":[
{"_id":0,"host":"192.168.1.31:11001"},
{"_id":1,"host":"192.168.1.31:11002"},
{"_id":2,"host":"192.168.1.31:11003"}
]
}
rs.initiate(config)
exit
./mongo --port 21001
config={
"_id":"db2",
"members":[
{"_id":3,"host":"192.168.1.31:21001"},
{"_id":4,"host":"192.168.1.31:21002"},
{"_id":5,"host":"192.168.1.31:21003"}
]
}
rs.initiate(config)
exit
./mongo --port 31001
config={
"_id":"db3",
"members":[
{"_id":0,"host":"192.168.1.31:31001"},
{"_id":1,"host":"192.168.1.31:31002"},
{"_id":2,"host":"192.168.1.31:31003"}
]
}
rs.initiate(config)
exit
#配置库的启动命令
/home/deploy/test/mongodb/bin/mongod --configsvr --dbpath /home/deploy/test/mongodb/data/configdb1 --port 20000 --logpath=/home/deploy/test/mongodb/data/log/configdb1.log --pidfilepath=/home/deploy/test/mongodb/data/cdb-1.pid &
/home/deploy/test/mongodb/bin/mongod --configsvr --dbpath /home/deploy/test/mongodb/data/configdb2 --port 20001 --logpath=/home/deploy/test/mongodb/data/log/configdb2.log --pidfilepath=/home/deploy/test/mongodb/data/cdb-2.pid &
/home/deploy/test/mongodb/bin/mongod --configsvr --dbpath /home/deploy/test/mongodb/data/configdb3 --port 20002 --logpath=/home/deploy/test/mongodb/data/log/configdb3.log --pidfilepath=/home/deploy/test/mongodb/data/cdb-3.pid &
#配置库的停止命令
kill -2 `cat /home/deploy/test/mongodb/data/cdb-1.pid`
kill -2 `cat /home/deploy/test/mongodb/data/cdb-2.pid`
kill -2 `cat /home/deploy/test/mongodb/data/cdb-3.pid`
#启动mongos
/home/deploy/test/mongodb/bin/mongos --port 30000 --configdb 192.168.1.31:20000,192.168.1.31:20001,192.168.1.31:20002 --logpath=/home/deploy/test/mongodb/data/log/mongos.log &
#测试
./mongo --port 30000
use admin
sh.addShard("db1/192.168.1.31:11001")
sh.addShard("db2/192.168.1.31:21001")
sh.addShard("db3/192.168.1.31:31001")
db.runCommand({listshards:1})
db.runCommand({"enablesharding":"test"})
sh.shardCollection("test.person",{_id:'hashed'})
use test
插入测试数据:
for(var i=0;i<10;i++){db.person.insert({name:"bluejoe"+i});}
db.person.find()
exit
./mongo --port 11001
db.person.find() -- 查看分片情况
- mongodb 3.2.7版本 的分片集群安装demo
- MongoDB的分片集群
- 安装mongodb副本分片集群
- mongodb分片集群的搭建
- MongoDB的分片集群配置
- Mongodb分布式分片集群安装和理解
- MongoDB分片>集群组件>分片
- MongoDB 3.2.7 基于keyFile的认证在副本集+集群分片中的使用
- mongodb集群与分片的配置说明
- mongodb集群与分片的配置说明
- MongoDB分片存储的集群架构实现
- MongoDB分片存储的集群架构实现
- mongodb分片集群的管理命令集合
- MongoDB分片存储的集群架构实现
- MongoDB实战-分片集群的管理
- MongoDB分片存储的集群架构实现
- Mongodb 集群分片部署
- MongoDB 分片集群
- Java 7之基础 - 强引用、弱引用、软引用、虚引用
- C# WinForm程序退出的方法
- Python 验证码识别
- Java-Vextor(1)
- iOS开发之检查APP版本更新
- mongodb 3.2.7版本 的分片集群安装demo
- oracle发送HTTP请求参考例子
- HBase概览
- setuid()
- 计算 变异系数 标准差 标准偏差 相关系数 平滑指数 回归系数等C++ 模板类
- 最新eclipse整合Struts2.3.29+Hibernate5.2.1+Spring4.3.1(二)Struts+Hibernate篇
- 深层次理解MVC
- shell截取字符串的方法
- 网络流入门题hdu3549(Flow Problem)