mongo Cluster部署

mongo cluster部署

Mongo机器分配

测试环境

    shard00:

           host1:8111,host2:8111,host3:8111

    shard01:

           host1:8112,host2:8112,host3:8112

    arbiter:

           host2:10000,host3:10000

           host2:10001,host3:10001

    config server:

           host1:8222,host2:8222,host3:8222

    mongos:

           host1:8333

生产环境

    shard00:

           hostA:8111,hostB:8111,hostC:8111

    shard01:

           hostD:8111,hostE:8111,hostF:8111

    arbiter:

           hostG:10000,hostH:10000

           hostG:10001,hostH:10001

    config server:

           hostI:8222,hostJ:8222,hostK:8222

    mongos:

           hostL:8333

分片搭建参照上篇文档:mongo Shard部署

configserver:

配置

vi ~/configserver/conf/configserver.conf

#log
logpath = ./log/configserver.log
logappend = true
#listen port
port = 8222
#db path
dbpath  = ./data/configserver/
#independent dir per db
directoryperdb = true
#namespace disk size
nssize = 500
#max connection numbers
maxConns = 2048
#relication log size
oplogSize = 10240
#monitor
rest = true

启动

nohup numactl --interleave=all ./bin/mongod -f ./conf/configserver.conf --configsvr --keyFile=./conf/secretKey >/dev/null 2>&1 &

    --configsvr    //启动mongod作为config server

mongos:

配置

vi ~/mongos/conf/mongos.conf

#log
logpath = ./log/mongos.log
logappend = true
#listen port = 8333
port = 8333
#config server ip:port
configdb = host1:8222,host2:8222,host36:8222
#max connection numbers
maxConns = 2048
noAutoSplit = true

启动

nohup  ./bin/mongos -f ./conf/mongos.conf --keyFile=./conf/secretKey >/dev/null 2>&1 &

加分片

./bin/mongo --host 127.0.0.1 --port 8333

>sh.addShard("shardName/ip:port")

shardName/ip:port      //shardName为具体分片名,ip:port为分片中的任意一个ip:port即可

本例中执行

>sh.addShard("shard00/host1:8111")
>sh.addShard("shard01/host1:8112")

查询状态

>sh.status()

添加用户

./bin/mongo --host 127.0.0.1 --port 8333

>use admin
>db.addUser("username","password")

登录

./bin/mongo 127.0.0.1:8333/admin -u username -p password

你可能感兴趣的:(mongo集群,mongos,configserver)