lee@ubuntu:~$ sudo mkdir -p /var/mongodb/0
[sudo] password for lee:
lee@ubuntu:~$ sudo mkdir -p/var/mongodb/1
mkdir: invalid option -- '/'
Try `mkdir --help' for more information.
lee@ubuntu:~$ sudo mkdir -p /var/mongodb/1
lee@ubuntu:~$ cd mongodb-linux-i686-1.6.4/
lee@ubuntu:~/mongodb-linux-i686-1.6.4$ ls
bin GNU-AGPL-3.0 README THIRD-PARTY-NOTICES
lee@ubuntu:~/mongodb-linux-i686-1.6.4$ cd bin
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo ./mongod --shardsvr --port 10000 --dbpath /var/mongod/0 --fork --logpath /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ forked process: 3411
all output going to: /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo ./mongod --shardsvr --port 10001 --dbpath /var/mongod/0 --fork --logpath /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ forked process: 3517
all output going to: /dev/null
________________________________________________________________________________ (1)安装shard 10000 10001
[sudo] password for lee:
lee@ubuntu:~$ sudo mkdir -p/var/mongodb/1
mkdir: invalid option -- '/'
Try `mkdir --help' for more information.
lee@ubuntu:~$ sudo mkdir -p /var/mongodb/1
lee@ubuntu:~$ cd mongodb-linux-i686-1.6.4/
lee@ubuntu:~/mongodb-linux-i686-1.6.4$ ls
bin GNU-AGPL-3.0 README THIRD-PARTY-NOTICES
lee@ubuntu:~/mongodb-linux-i686-1.6.4$ cd bin
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo ./mongod --shardsvr --port 10000 --dbpath /var/mongod/0 --fork --logpath /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ forked process: 3411
all output going to: /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo ./mongod --shardsvr --port 10001 --dbpath /var/mongod/0 --fork --logpath /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ forked process: 3517
all output going to: /dev/null
________________________________________________________________________________ (1)安装shard 10000 10001
lee@ubuntu:~$ cd mongodb-linux-i686-1.6.4/
lee@ubuntu:~/mongodb-linux-i686-1.6.4$ cd bin
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ ls
bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongostat
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo ./mongod --configsvr --port 20000 --dbpath /var/mongod/config --fork --logpath /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ forked process: 3843
all output going to: /dev/null
__________________________________________________________________________________(2) 启动 Config Server。
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo mongos --configdb localhost:20000 --fork --logpath /dev/null
forked process: 3892
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ all output going to: /dev/null
terminate called after throwing an instance of 'mongo::UserException'
what(): dbconnectionpool: connect failed localhost:20000
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo ./mongos --configdb localhost:20000 --fork --logpath /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ forked process: 3915
all output going to: /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4$ cd bin
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ ls
bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongostat
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo ./mongod --configsvr --port 20000 --dbpath /var/mongod/config --fork --logpath /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ forked process: 3843
all output going to: /dev/null
__________________________________________________________________________________(2) 启动 Config Server。
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo mongos --configdb localhost:20000 --fork --logpath /dev/null
forked process: 3892
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ all output going to: /dev/null
terminate called after throwing an instance of 'mongo::UserException'
what(): dbconnectionpool: connect failed localhost:20000
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ sudo ./mongos --configdb localhost:20000 --fork --logpath /dev/null
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ forked process: 3915
all output going to: /dev/null
_________________________________________________________________________________(3) 启动 Route Process。
_________________________________________________________________________________(4) 连接到 Route,开始配置。
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ ./mongo
MongoDB shell version: 1.6.4
connecting to: test
> use admin
switched to db admin
> db.runCommand({addshard : "localhost:10000"})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"addshard" : "localhost:10000"
},
"ok" : 0
}
> db.runCommand({addshard : "localhost:10001"})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"addshard" : "localhost:10001"
},
"ok" : 0
}
> db.runCommand({enablesharding : "test"})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"enablesharding" : "test"
},
"ok" : 0
}
> db.runCommand({shardCollection : "test.users",key: {-id:1}})
Tue Apr 19 20:36:03 SyntaxError: invalid property id (shell):0
> db.runCommand({shardCollection : "test.users",key: {_id:1}})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"shardCollection" : "test.users",
"key" : {
"_id" : 1
}
},
"ok" : 0
}
addshard: 添加 Shard Server,相关的命令还有 listshards 和 removeshard。
enablesharding: 用于设置可以被分布存储的数据库。
shardcollection: 用于设置具体被切块的集合名称,且必须指定 Shard Key,系统会自动创建索引。
注: Sharded Collection 只能有一个 unique index,且必须是 shard key。
_________________________________________________________________________________(4) 连接到 Route,开始配置。
lee@ubuntu:~/mongodb-linux-i686-1.6.4/bin$ ./mongo
MongoDB shell version: 1.6.4
connecting to: test
> use admin
switched to db admin
> db.runCommand({addshard : "localhost:10000"})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"addshard" : "localhost:10000"
},
"ok" : 0
}
> db.runCommand({addshard : "localhost:10001"})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"addshard" : "localhost:10001"
},
"ok" : 0
}
> db.runCommand({enablesharding : "test"})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"enablesharding" : "test"
},
"ok" : 0
}
> db.runCommand({shardCollection : "test.users",key: {-id:1}})
Tue Apr 19 20:36:03 SyntaxError: invalid property id (shell):0
> db.runCommand({shardCollection : "test.users",key: {_id:1}})
{
"errmsg" : "no such cmd",
"bad cmd" : {
"shardCollection" : "test.users",
"key" : {
"_id" : 1
}
},
"ok" : 0
}
addshard: 添加 Shard Server,相关的命令还有 listshards 和 removeshard。
enablesharding: 用于设置可以被分布存储的数据库。
shardcollection: 用于设置具体被切块的集合名称,且必须指定 Shard Key,系统会自动创建索引。
注: Sharded Collection 只能有一个 unique index,且必须是 shard key。