mongodb 3.0.3 sharded cluster 配置
mongodb:mongodb 3.0.3
host:
ct6601 192.108.56.117
ct6602 192.108.56.119
ct6604 192.108.56.120
mongodb shard server:
shard1:192.108.56.117:27017,192.108.56.119:27017,192.108.56.120:27017
shard2:192.108.56.117:27018,192.108.56.119:27018,192.108.56.120:27018
shard3:192.108.56.117:27019,192.108.56.119:27019,192.108.56.120:27019
mongodb config server:192.108.56.117:27020,192.108.56.119:27020,192.108.56.120:27020
mongodb mongs:192.108.56.117:27000,192.108.56.119:27000,192.108.56.120:27000
一.安裝啟動mongodb
#在ct6601,ct6602,ct6604上執行以下
#mongodb.tgz檔案放在/root下
[root@ct6601 ~]# ll mongo*
-rwxr--r-- 1 root root 50328650 Jun 4 2015 mongodb-linux-x86_64-rhel62-3.0.3.tgz
#解壓mongodb.tgz
[root@ct6601 ~]# tar -xzvf mongodb-linux-x86_64-rhel62-3.0.3.tgz
#移動解壓後的檔案到/usr/local/mongodb
[root@ct6601 ~]# mv mongodb-linux-x86_64-rhel62-3.0.3 /usr/local/mongodb
#設定環境變數
[root@ct6601 ~]# echo "export PATH=\$PATH:/usr/local/mongodb/bin" >>.bash_profile
[root@ct6601 ~]# . /root/.bash_profile
#建立目錄
[root@ct6601 ~]# mkdir /usr/local/mongodb/data
[root@ct6601 data]# mkdir db_27017 db_27018 db_27019 conf_27020
#啟動sharded server db_27017
[root@ct6601 data]# mongod --shardsvr --replSet db_27017 --port 27017 --dbpath /usr/local/mongodb/data/db_27017 --logpath /usr/local/mongodb/data/db_27017/db_27017.log --nojournal --oplogSize 10 --fork
#啟動sharded server db_27018
[root@ct6601 data]# mongod --shardsvr --replSet db_27018 --port 27018 --dbpath /usr/local/mongodb/data/db_27018 --logpath /usr/local/mongodb/data/db_27018/db_27018.log --nojournal --oplogSize 10 --fork
#啟動sharded server db_27019
[root@ct6601 data]# mongod --shardsvr --replSet db_27019 --port 27019 --dbpath /usr/local/mongodb/data/db_27019 --logpath /usr/local/mongodb/data/db_27019/db_27019.log --nojournal --oplogSize 10 --fork
#啟動config server conf_27020
[root@ct6601 data]# mongod --configsvr --dbpath /usr/local/mongodb/data/conf_27020 --port 27020 --logpath /usr/local/mongodb/data/conf_27020/config.log --fork
#啟動mongos server
[root@ct6601 data]# mongos --configdb 192.108.56.117:27020,192.108.56.119:27020,192.108.56.120:27020 --port 27000 --logpath /usr/local/mongodb/data/mongos.log --fork
#在ct6601,ct6602,ct6604上看是否都有啟動5個mongodb程式
[root@ct6601 data]# ps -ef|grep mongo|grep -v grep
root 24348 1 0 14:16 ? 00:00:01 mongod --shardsvr --replSet db_27017 --port 27017 --dbpath /usr/local/mongodb/data/db_27017 --logpath /usr/local/mongodb/data/db_27017/db_27017.log --nojournal --oplogSize 10 --fork
root 24362 1 0 14:17 ? 00:00:01 mongod --shardsvr --replSet db_27018 --port 27018 --dbpath /usr/local/mongodb/data/db_27018 --logpath /usr/local/mongodb/data/db_27018/db_27018.log --nojournal --oplogSize 10 --fork
root 24376 1 0 14:17 ? 00:00:00 mongod --shardsvr --replSet db_27019 --port 27019 --dbpath /usr/local/mongodb/data/db_27019 --logpath /usr/local/mongodb/data/db_27019/db_27019.log --nojournal --oplogSize 10 --fork
root 24394 1 1 14:20 ? 00:00:01 mongod --configsvr --dbpath /usr/local/mongodb/data/conf_27020 --port 27020 --logpath /usr/local/mongodb/data/conf_27020/config.log --fork
root 24408 1 0 14:21 ? 00:00:00 mongos --configdb 192.108.56.117:27020,192.108.56.119:27020,192.108.56.120:27020 --port 27000 --logpath /usr/local/mongodb/data/mongos.log --fork
二.配置mongodb
#配置replica set
#配置replica set db_27017
[root@ct6601 data]# mongo 192.108.56.117:27017
> conf = { _id:"db_27017", members:[
{_id:0,host:"192.108.56.117:27017"},
{_id:1,host:"192.108.56.119:27017"},
{_id:2,host:"192.108.56.120:27017"}
]
}
> rs.initiate(conf)
db_27017:OTHER> rs.status()
db_27017:PRIMARY> exit
#配置replica set db_27018
[root@ct6601 data]# mongo 192.108.56.117:27018
> conf = { _id:"db_27018", members:[
{_id:0,host:"192.108.56.117:27018"},
{_id:1,host:"192.108.56.119:27018"},
{_id:2,host:"192.108.56.120:27018"}
]
}
> rs.initiate(conf)
db_27018:OTHER> rs.status()
db_27018:PRIMARY> exit
#配置replica set db_27019
[root@ct6601 data]# mongo 192.108.56.117:27019
> conf = { _id:"db_27019", members:[
{_id:0,host:"192.108.56.117:27019"},
{_id:1,host:"192.108.56.119:27019"},
{_id:2,host:"192.108.56.120:27019"}
]
}
> rs.initiate(conf)
db_27019:OTHER> rs.status()
db_27019:PRIMARY> exit
#配置mongos
[root@ct6601 data]# mongo 192.108.56.117:27000
mongos> use admin
switched to db admin
#配置shard
mongos> sh.addShard("db_27017/192.108.56.117:27017,192.108.56.119:27017,192.108.56.120:27017")
{ "shardAdded" : "db_27017", "ok" : 1 }
mongos> sh.addShard("db_27018/192.108.56.117:27018,192.108.56.119:27018,192.108.56.120:27018")
{ "shardAdded" : "db_27018", "ok" : 1 }
mongos> sh.addShard("db_27019/192.108.56.117:27019,192.108.56.119:27019,192.108.56.120:27019")
{ "shardAdded" : "db_27019", "ok" : 1 }
#檢視shard
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("567102d135eeed4237132975")
}
shards:
{ "_id" : "db_27017", "host" : "db_27017/192.108.56.117:27017,192.108.56.119:27017,192.108.56.120:27017" }
{ "_id" : "db_27018", "host" : "db_27018/192.108.56.117:27018,192.108.56.119:27018,192.108.56.120:27018" }
{ "_id" : "db_27019", "host" : "db_27019/192.108.56.117:27019,192.108.56.119:27019,192.108.56.120:27019" }
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
#開啟shard資料庫
mongos> sh.enableSharding("test")
{ "ok" : 1 }
#測試
#新增shardCollection
mongos> sh.shardCollection("test.tb01",{_id:1})
{ "collectionsharded" : "test.tb01", "ok" : 1 }
#插入測試資料
mongos> for(var i=0;i<100;i++){db.tb01.insert({name:"select"+i});}
WriteResult({ "nInserted" : 1 })
#檢視資料分佈情況
mongos> db.tb01.stats()
輸出:...
host:
ct6601 192.108.56.117
ct6602 192.108.56.119
ct6604 192.108.56.120
mongodb shard server:
shard1:192.108.56.117:27017,192.108.56.119:27017,192.108.56.120:27017
shard2:192.108.56.117:27018,192.108.56.119:27018,192.108.56.120:27018
shard3:192.108.56.117:27019,192.108.56.119:27019,192.108.56.120:27019
mongodb config server:192.108.56.117:27020,192.108.56.119:27020,192.108.56.120:27020
mongodb mongs:192.108.56.117:27000,192.108.56.119:27000,192.108.56.120:27000
一.安裝啟動mongodb
#在ct6601,ct6602,ct6604上執行以下
#mongodb.tgz檔案放在/root下
[root@ct6601 ~]# ll mongo*
-rwxr--r-- 1 root root 50328650 Jun 4 2015 mongodb-linux-x86_64-rhel62-3.0.3.tgz
#解壓mongodb.tgz
[root@ct6601 ~]# tar -xzvf mongodb-linux-x86_64-rhel62-3.0.3.tgz
#移動解壓後的檔案到/usr/local/mongodb
[root@ct6601 ~]# mv mongodb-linux-x86_64-rhel62-3.0.3 /usr/local/mongodb
#設定環境變數
[root@ct6601 ~]# echo "export PATH=\$PATH:/usr/local/mongodb/bin" >>.bash_profile
[root@ct6601 ~]# . /root/.bash_profile
#建立目錄
[root@ct6601 ~]# mkdir /usr/local/mongodb/data
[root@ct6601 data]# mkdir db_27017 db_27018 db_27019 conf_27020
#啟動sharded server db_27017
[root@ct6601 data]# mongod --shardsvr --replSet db_27017 --port 27017 --dbpath /usr/local/mongodb/data/db_27017 --logpath /usr/local/mongodb/data/db_27017/db_27017.log --nojournal --oplogSize 10 --fork
#啟動sharded server db_27018
[root@ct6601 data]# mongod --shardsvr --replSet db_27018 --port 27018 --dbpath /usr/local/mongodb/data/db_27018 --logpath /usr/local/mongodb/data/db_27018/db_27018.log --nojournal --oplogSize 10 --fork
#啟動sharded server db_27019
[root@ct6601 data]# mongod --shardsvr --replSet db_27019 --port 27019 --dbpath /usr/local/mongodb/data/db_27019 --logpath /usr/local/mongodb/data/db_27019/db_27019.log --nojournal --oplogSize 10 --fork
#啟動config server conf_27020
[root@ct6601 data]# mongod --configsvr --dbpath /usr/local/mongodb/data/conf_27020 --port 27020 --logpath /usr/local/mongodb/data/conf_27020/config.log --fork
#啟動mongos server
[root@ct6601 data]# mongos --configdb 192.108.56.117:27020,192.108.56.119:27020,192.108.56.120:27020 --port 27000 --logpath /usr/local/mongodb/data/mongos.log --fork
#在ct6601,ct6602,ct6604上看是否都有啟動5個mongodb程式
[root@ct6601 data]# ps -ef|grep mongo|grep -v grep
root 24348 1 0 14:16 ? 00:00:01 mongod --shardsvr --replSet db_27017 --port 27017 --dbpath /usr/local/mongodb/data/db_27017 --logpath /usr/local/mongodb/data/db_27017/db_27017.log --nojournal --oplogSize 10 --fork
root 24362 1 0 14:17 ? 00:00:01 mongod --shardsvr --replSet db_27018 --port 27018 --dbpath /usr/local/mongodb/data/db_27018 --logpath /usr/local/mongodb/data/db_27018/db_27018.log --nojournal --oplogSize 10 --fork
root 24376 1 0 14:17 ? 00:00:00 mongod --shardsvr --replSet db_27019 --port 27019 --dbpath /usr/local/mongodb/data/db_27019 --logpath /usr/local/mongodb/data/db_27019/db_27019.log --nojournal --oplogSize 10 --fork
root 24394 1 1 14:20 ? 00:00:01 mongod --configsvr --dbpath /usr/local/mongodb/data/conf_27020 --port 27020 --logpath /usr/local/mongodb/data/conf_27020/config.log --fork
root 24408 1 0 14:21 ? 00:00:00 mongos --configdb 192.108.56.117:27020,192.108.56.119:27020,192.108.56.120:27020 --port 27000 --logpath /usr/local/mongodb/data/mongos.log --fork
二.配置mongodb
#配置replica set
#配置replica set db_27017
[root@ct6601 data]# mongo 192.108.56.117:27017
> conf = { _id:"db_27017", members:[
{_id:0,host:"192.108.56.117:27017"},
{_id:1,host:"192.108.56.119:27017"},
{_id:2,host:"192.108.56.120:27017"}
]
}
> rs.initiate(conf)
db_27017:OTHER> rs.status()
db_27017:PRIMARY> exit
#配置replica set db_27018
[root@ct6601 data]# mongo 192.108.56.117:27018
> conf = { _id:"db_27018", members:[
{_id:0,host:"192.108.56.117:27018"},
{_id:1,host:"192.108.56.119:27018"},
{_id:2,host:"192.108.56.120:27018"}
]
}
> rs.initiate(conf)
db_27018:OTHER> rs.status()
db_27018:PRIMARY> exit
#配置replica set db_27019
[root@ct6601 data]# mongo 192.108.56.117:27019
> conf = { _id:"db_27019", members:[
{_id:0,host:"192.108.56.117:27019"},
{_id:1,host:"192.108.56.119:27019"},
{_id:2,host:"192.108.56.120:27019"}
]
}
> rs.initiate(conf)
db_27019:OTHER> rs.status()
db_27019:PRIMARY> exit
#配置mongos
[root@ct6601 data]# mongo 192.108.56.117:27000
mongos> use admin
switched to db admin
#配置shard
mongos> sh.addShard("db_27017/192.108.56.117:27017,192.108.56.119:27017,192.108.56.120:27017")
{ "shardAdded" : "db_27017", "ok" : 1 }
mongos> sh.addShard("db_27018/192.108.56.117:27018,192.108.56.119:27018,192.108.56.120:27018")
{ "shardAdded" : "db_27018", "ok" : 1 }
mongos> sh.addShard("db_27019/192.108.56.117:27019,192.108.56.119:27019,192.108.56.120:27019")
{ "shardAdded" : "db_27019", "ok" : 1 }
#檢視shard
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("567102d135eeed4237132975")
}
shards:
{ "_id" : "db_27017", "host" : "db_27017/192.108.56.117:27017,192.108.56.119:27017,192.108.56.120:27017" }
{ "_id" : "db_27018", "host" : "db_27018/192.108.56.117:27018,192.108.56.119:27018,192.108.56.120:27018" }
{ "_id" : "db_27019", "host" : "db_27019/192.108.56.117:27019,192.108.56.119:27019,192.108.56.120:27019" }
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
#開啟shard資料庫
mongos> sh.enableSharding("test")
{ "ok" : 1 }
#測試
#新增shardCollection
mongos> sh.shardCollection("test.tb01",{_id:1})
{ "collectionsharded" : "test.tb01", "ok" : 1 }
#插入測試資料
mongos> for(var i=0;i<100;i++){db.tb01.insert({name:"select"+i});}
WriteResult({ "nInserted" : 1 })
#檢視資料分佈情況
mongos> db.tb01.stats()
輸出:...
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-1873418/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 小丸子學MongoDB系列之——部署Replica Set+Sharded ClusterMongoDB
- mongodb 分片群集(sharding cluster)MongoDB
- redis cluster 配置Redis
- mysql cluster 簡單配置MySql
- REDHAT5.1 cluster配置Redhat
- MySQL Cluster 配置檔案MySql
- Comparing MongoDB with MySQL Cluster as a Key-Value StoreMongoDBMySql
- MongoDB安全配置MongoDB
- MySQL cluster 7.2叢集部署配置MySql
- oracle redhat 下cluster 配置管理OracleRedhat
- MongoDB 映象配置方法MongoDB
- Mongodb主從配置MongoDB
- 【mongodb安裝配置】MongoDB
- mongodb配置檔案常用配置項MongoDB
- MySQL Cluster 與 MongoDB 複製群集分片設計及原理MySqlMongoDB
- 搭建高可用MongoDB叢集(一):配置MongoDBMongoDB
- 一臺主機上配置MySQL ClusterMySql
- 【MongoDB】安裝與配置MongoDB
- MongoDB配置與啟動MongoDB
- MongoDB安裝配置教程MongoDB
- mongodb 3.0 replica set 配置MongoDB
- 如何配置 MongoDB 副本集MongoDB
- redis偽叢集配置Cluster叢集模式Redis模式
- LINUX下安裝cassandra 並配置clusterLinux
- 學習MongoDB 一:MongoDB 入門(安裝與配置)MongoDB
- MongoDB複製集什麼時候考慮使用Shared Cluster?MongoDB
- idea怎麼配置mongodbIdeaMongoDB
- Mac 安裝與配置mongodbMacMongoDB
- MongoDB之安裝並配置MongoDB
- MongoDB 3.4配置sharding分片MongoDB
- mongodb的安裝配置,使用MongoDB
- 【Mongodb】Sharding 叢集配置MongoDB
- kettle MongoDB Output 配置說明MongoDB
- jboss3.0.3釋出錯誤???S3
- Mysql ndb-cluster centos6.4 簡單配置MySqlCentOS
- 【轉】在同一臺主機配置MySQL ClusterMySql
- 01 . MongoDB簡介及部署配置MongoDB
- mongodb主從仲裁節點配置MongoDB