乱读天书, 不求甚解
周祎骏的个人云笔记
Toggle navigation
乱读天书, 不求甚解
主页
Linux:系统配置
Linux:用户管理
Linux:优化排错
Linux:进程调度
Linux:文件系统
Linux:网络
Linux:系统服务
Linux:安全
Linux:内核
容器:Docker
容器:containerd
容器编排:Kubernetes
IAC:Terraform
大数据:Hadoop
大数据:Zookeeper
大数据:Hbase
消息队列:rsyslog
消息队列:kafka
数据库:MySQL
数据库:MongoDB
搜索引擎:Elasticsearch
时序数据库:OpenTSDB
网站服务:Nginx
编程:Bash
编程:Perl
编程:Python
编程:C
编程:JAVA
编程:Rust
版本控制:gitlab
知识管理:docusaurus
常用小工具
关于我
标签
Mongodb 3.0 部署 Shard
2017-08-30 13:07:42
67
0
0
admin
> 配置分片集群 **假设我们要配置如下集群** | test1 | test2 | test3 | test4 | |-----------------|-----------------|-----------------|-----------------| |mongod rs0 27018 |mongod rs0 27018 |arbit rs0 27019 | | | |arbit rs1 27019 |mongod rs1 27018 |mongod rs1 27018 | |configdb 27020 |configdb 27020 |configdb 27020 | | | | | |mongos 27017 | #集群部署 ##安装由mongod和arbit 组成的rs0 和 rs1 集群。 * 启动test1 的 mongod ``` [leo@test1 bin]$ cat mongod.cfg sharding: clusterRole: shardsvr replication: replSetName: rs0 systemLog: destination: file path: /leo/mongo/mongodb-linux-x86_64-rhel62-3.4.4/log/mongod.log processManagement: fork: true net: port: 27018 storage: dbPath: /leo/mongo/data/mongod [leo@test1 bin]$ ./mongod --config ./mongod.cfg about to fork child process, waiting until server is ready for connections. forked process: 2881 child process started successfully, parent exiting ``` * 把 test2 上的mongod 也起来 * 把 test3 上的arbit 起起来 ``` [leo@test3 bin]$ cat arbit.cfg sharding: clusterRole: shardsvr replication: replSetName: rs0 systemLog: destination: file path: /leo/mongo/mongodb-linux-x86_64-rhel62-3.4.4/log/arbit.log processManagement: fork: true net: port: 27020 storage: dbPath: /leo/mongo/data/arbit [leo@test3 bin]$ ./mongod --config ./arbit.cfg about to fork child process, waiting until server is ready for connections. forked process: 3719 child process started successfully, parent exiting ``` * 配置 ``` > rs.initiate() { "info2" : "no configuration specified. Using a default configuration for the set", "me" : "test1:27018", "ok" : 1 } rs0:OTHER> rs.add("test2:27018") { "ok" : 1 } rs0:PRIMARY> rs.addArb("test3:27020") { "ok" : 1 } ``` * 用同样的方法配置rs1 集群 ##部署configdb集群 * 在test1 test2 test3 上启动mongo arbit 进程 ``` [leo@test1 bin]$ cat ./configdb.cfg sharding: clusterRole: configsvr replication: replSetName: configdb systemLog: destination: file path: /leo/mongo/mongodb-linux-x86_64-rhel62-3.4.4/log/configdb.log processManagement: fork: true net: port: 27019 storage: dbPath: /leo/mongo/data/configdb [leo@test1 bin]$ ./mongod --config ./configdb.cfg about to fork child process, waiting until server is ready for connections. forked process: 3236 child process started successfully, parent exiting ``` * 配置 ``` > rs.initiate() { "info2" : "no configuration specified. Using a default configuration for the set", "me" : "test1:27019", "ok" : 1 } configdb:OTHER> rs.add("test2:27019") { "ok" : 1 } configdb:PRIMARY> rs.add("test3:27019") { "ok" : 1 } ``` ##部署mongos * 启动mongos ``` [leo@test4 bin]$ cat mongos.cfg sharding: configDB: configdb/test1:27019,test2:27019,test3:27019 systemLog: destination: file path: /leo/mongo/mongodb-linux-x86_64-rhel62-3.4.4/log/mongos.log processManagement: fork: true net: port: 27017 [leo@test4 bin]$ ./mongos --config ./mongos.cfg about to fork child process, waiting until server is ready for connections. forked process: 2923 child process started successfully, parent exiting ``` * 配置 ``` mongos> sh.addShard('rs0/test1:27018,test2:27018') { "shardAdded" : "rs0", "ok" : 1 } mongos> sh.addShard('rs1/test3:27018,test4:27018') { "shardAdded" : "rs1", "ok" : 1 } ``` *** #配置需要分片的库,表 ``` mongos> sh.enableSharding('database_name') { "ok" : 1 } mongos> sh.shardCollection('database_name.collection_name',{'_id':1}) // 根据某个键分片(该键必须有索引) { "collectionsharded" : "database_name.collection_name", "ok" : 1 } ```
上一篇:
Mongodb 2.2 Replic 管理
下一篇:
Mongodb 3.1 分片管理
文档导航