Mongodb2.4.3集群安装笔记

机器:
192.168.40.80 -> mongodb01
192.168.40.81 -> mongodb02
192.168.40.82 -> mongodb03
192.168.40.83 -> mongodb04
192.168.40.84 -> mongodb05

sharding架构设置

mongodb01 shard11     shard43 shard52
mongodb02 shard12 shard21     shard53
mongodb03 shard13 shard22 shard31    
mongodb04   shard23 shard32 shard41  
mongodb05     shard33 shard42 shard51
注明:
同色块为整个数据集的各个分部sharding(分散于各机器中)
同一分部sharding有三个replica副本

补充:这里说一下关于Replica Sets和Sharding,Sharding是将整个数据库分成若干个shard,每一个shard在replica sets中存在若干个副本。这样能够将数据库访问的压力通过shards分散到集群中的若干台机器,同时每个shard存在若干个分散的副本使得某个副本的丢失不会影响整个系统的运行。

1. 配置主机名:
# vi /etc/hosts
# vi /etc/sysconfig/network
# hostname newhostname

then relogin

2. 解压安装包
# tar zxvf mongodb-linux-x86_64-2.4.3.tgz


3. 创建shard数据目录
@ mongodb01
# mkdir -p /mongodb_data/data/shard11
# mkdir -p /mongodb_data/data/shard43
# mkdir -p /mongodb_data/data/shard52

@ mongodb02
# mkdir -p /mongodb_data/data/shard12
# mkdir -p /mongodb_data/data/shard21
# mkdir -p /mongodb_data/data/shard53

......

4. 配置replica sets

Shard1:
@mongodb01
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard1 -port 29019 -logpath /mongodb_data/data/shard11.log -dbpath /mongodb_data/data/shard11 -fork --logappend
@mongodb02
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard1 -port 29019 -logpath /mongodb_data/data/shard12.log -dbpath /mongodb_data/data/shard12 -fork --logappend
@mongodb03
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard1 -port 29019 -logpath /mongodb_data/data/shard13.log -dbpath /mongodb_data/data/shard13 -fork --logappend


Shard2:
@mongodb02
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard2 -port 29020 -logpath /mongodb_data/data/shard21.log -dbpath /mongodb_data/data/shard21 -fork --logappend
@mongodb03
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard2 -port 29020 -logpath /mongodb_data/data/shard22.log -dbpath /mongodb_data/data/shard22 -fork --logappend
@mongodb04
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard2 -port 29020 -logpath /mongodb_data/data/shard23.log -dbpath /mongodb_data/data/shard23 -fork --logappend




Shard3:
@mongodb03
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard3 -port 29021 -logpath /mongodb_data/data/shard31.log -dbpath /mongodb_data/data/shard31 -fork --logappend
@mongodb04
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard3 -port 29021 -logpath /mongodb_data/data/shard32.log -dbpath /mongodb_data/data/shard32 -fork --logappend
@mongodb05
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard3 -port 29021 -logpath /mongodb_data/data/shard33.log -dbpath /mongodb_data/data/shard33 -fork --logappend


Shard4:
@mongodb04
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard4 -port 29022 -logpath /mongodb_data/data/shard41.log -dbpath /mongodb_data/data/shard41 -fork --logappend
@mongodb05
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard4 -port 29022 -logpath /mongodb_data/data/shard42.log -dbpath /mongodb_data/data/shard42 -fork --logappend
@mongodb01
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard4 -port 29022 -logpath /mongodb_data/data/shard43.log -dbpath /mongodb_data/data/shard43 -fork --logappend


Shard5:
@mongodb05
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard5 -port 29023 -logpath /mongodb_data/data/shard51.log -dbpath /mongodb_data/data/shard51 -fork --logappend
@mongodb01
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard5 -port 29023 -logpath /mongodb_data/data/shard52.log -dbpath /mongodb_data/data/shard52 -fork --logappend
@mongodb02
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -shardsvr -replSet shard5 -port 29023 -logpath /mongodb_data/data/shard53.log -dbpath /mongodb_data/data/shard53 -fork --logappend

> config = {_id:'shard5',members:[ {_id: 0, host:'192.168.40.84:29023'}, {_id: 1, host:'192.168.40.80:29023'}, {_id: 2, host:'192.168.40.81:29023'}] }
> rs.initiate(config)

可能的错误
rs.initiate(config);
{"ok" : 0,
"errmsg" : "couldn't initiate : need all members up to initiate, not ok : 192.168.40.82:29019"} 
注意防火墙设置

5. 配置config server
@mongodb01~mongodb05
# mkdir /mongodb_data/data/config
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongod -configsvr -port 29018 -logpath /mongodb_data/data/config.log -dbpath /mongodb_data/data/config -logappend -fork

6. 配置mongos
# /opt/mongodb-linux-x86_64-2.4.3/bin/mongos -configdb 192.168.40.80:29018 -port 29025 -logpath /mongodb_data/data/mongos.log -logappend -fork

7. 配置shard cluster
使用其中一台服务器登录数据库
# mongo 192.168.40.80:29025
> use admin
> db.runCommand({addshard:"shard1/192.168.40.80:29019,192.168.40.81:29019,192.168.40.82:29019",name:"s1"})
> db.runCommand({addshard:"shard2/192.168.40.81:29020,192.168.40.82:29020,192.168.40.83:29020",name:"s2"})
> db.runCommand({addshard:"shard3/192.168.40.82:29021,192.168.40.83:29021,192.168.40.84:29021",name:"s3"})
> db.runCommand({addshard:"shard4/192.168.40.83:29022,192.168.40.84:29022,192.168.40.80:29022",name:"s4"})
> db.runCommand({addshard:"shard5/192.168.40.84:29023,192.168.40.80:29023,192.168.40.81:29023",name:"s5"})

db.printShardingStatus() - 打印sharding状态
mongodb web管理端,端口为连接端口号+1000
http://192.168.40.80:30025
注意在启动mongod时需要指定 --rest才能查看命令返回结果



参考资料:
http://www.taobaodba.com/html/525_525.html
http://blog.csdn.net/weiyuanke/article/details/7639905

你可能感兴趣的:(Mongodb2.4.3集群安装笔记)