【mongoDB】集群搭建

集群架构

我选择了3台机器搭建一个集群,每台机器上会启动3个进程,分别是Shard、Config和Router

步骤

下载mongdb的安装包,拷贝3个副本,3个角色

1.启动shard进程 

conf/mongo.conf 配置如下, 其中keyFile需要每个分片节点都一致,3台机器分别启动 ./bin/mongod -f ./conf/mongod.conf

#log
logpath = ./var/mongo/log/mongod.log
logappend = true
port = 7111
dbpath = ./mongo/data

directoryperdb = true
nssize = 500
maxConns = 10240

replSet = rs0
oplogSize = 102400

syncdelay = 1
fastsync = true
fork = true

keyFile = ./conf/pcskey
#monitor
rest = true

2.配置副本集

使用客户端程序连上刚启动任意一个的shard节点

rsconf={_id:"rs0",members:[{_id:0,host:"${ip1}:7111"},{_id:0,host:"${ip2}.164:7111"},{_id:0,host:"${ip3}:7111"}]}
rs.initiate(rsconf)

然后连接shard节点就是带角色的

3.启动config server

配置server的conf/mongo.conf 配置如下./bin/mongod -f ./conf/mongod.conf --configsvr --fastsync --keyFile=./conf/pcskey

logpath = ./log/mongod.log
logappend = true

port = 7222
dbpath = ./data.7222
directoryperdb = true
nssize = 500
maxConns = 2048

oplogSize = 10240

#monitor
rest = true

4.启动路由server

配置server的conf/mongos.conf 配置如下./bin/mongos -f ./conf/mongos.conf --keyFile=./conf/pcskey

logpath = /home/work/var/mongo/log/mongos.log
logappend = true

port = 8111
configdb = ${ip1}:7222,${ip2}:7222,${ip3}:7222
maxConns = 2048

路由服务器配置shard节点

db.runCommand({addshard:"rs0/${ip3}:7111,${ip1}:7111,${ip2}.164:7111"});
db.runCommand({ enablesharding: 'db'})
发布了92 篇原创文章 · 获赞 14 · 访问量 5837

猜你喜欢

转载自blog.csdn.net/sarafina527/article/details/103355898