mongodb分片+复制集环境规划:
192.168.0.105、
192.168.0.106、
192.168.0.107、
192.168.0.108、
192.168.0.105 mongod shard1_1 40000 (rs0-primayr)
mongod shard2_3 40005 (rs2-arbiter)
mongod config1 50000
192.168.0.106 mongod shard1_2 40001 (rs0-secondary)
mongod config2 50000
mongod mongos1 60000
192.168.0.107 mongod shard2_1 40003 (rs1-primayr)
mongod shard1_3 40002 (rs0-arbiter)
mongod mongos2 60000
192.168.0.108 mongod shard2_2 40004 (rs1-secondary)
mongod config3 50000
mongod mongos3 60000
192.168.0.105上创建目录:
mkdir -p /appl/data/shard1_1
mkdir -p /appl/data/shard1_1/log
mkdir -p /appl/data/shard2_3
mkdir -p /appl/data/shard2_3/log
mkdir -p /appl/data/config1
mkdir -p /appl/data/config1/log
192.168.0.106上创建目录:
mkdir -p /appl/data/shard1_2
mkdir -p /appl/data/shard1_2/log
mkdir -p /appl/data/config2
mkdir -p /appl/data/config2/log
mkdir -p /appl/data/mongos
192.168.0.107上创建目录:
mkdir -p /appl/data/shard2_1
mkdir -p /appl/data/shard2_1/log
mkdir -p /appl/data/shard1_3
mkdir -p /appl/data/shard1_3/log
mkdir -p /appl/data/mongos
192.168.0.108上创建目录:
mkdir -p /appl/data/shard2_2
mkdir -p /appl/data/shard2_2/log
mkdir -p /appl/data/config3
mkdir -p /appl/data/config3/log
mkdir -p /appl/data/mongos
复制集rs0启动
192.168.0.105:
/appl/mongo/bin/mongod --shardsvr --replSet rs0 --port 40000 --dbpath /appl/data/shard1_1 --logpath /appl/data/shard1_1/log/shard1_1.log --logappend --fork
配置文件
rs0_1.conf
dbpath=/appl/data/shard1_1
logpath=/appl/data/shard1_1/log/shard1_1.log
journal=true
port=40000
replset=rs0
oplogSize = 5000M
fork = true
directoryperdb = true
***************************************************************
dbpath=/appl/data/shard1_1
logpath=/appl/data/shard1_1/log/shard1_1.log
journal=true
port=40000
replSet=rs0
oplogSize = 5000
fork = true
*****************************************************************
/appl/mongo/bin/mongod -f /appl/mongo/rs0_1.conf
192.168.0.106:
/appl/mongo/bin/mongod --shardsvr --replSet rs0 --port 40001 --dbpath /appl/data/shard1_2 --logpath /appl/data/shard1_2/log/shard1_2.log --logappend --fork
rs0_2.conf
dbpath=/appl/data/shard1_2
logpath=/appl/data/shard1_2/log/shard1_2.log
journal=true
port=40001
replSet=rs0
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs0_2.conf
192.168.0.107:
/appl/mongo/bin/mongod --shardsvr --replSet rs0 --port 40002 --dbpath /appl/data/shard1_3 --logpath /appl/data/shard1_3/log/shard1_3.log --logappend --fork
rs0_3.conf
dbpath=/appl/data/shard1_3
logpath=/appl/data/shard1_3/log/shard1_3.log
journal=true
port=40002
replSet=rs0
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs0_3.conf
配置复制rs0
config = {_id: 'rs0', members: [
{_id: 0, host: '192.168.0.105:40000'},
{_id: 1, host: '192.168.0.106:40001'},
{_id: 2, host: '192.168.0.107:40002','arbiterOnly':true}]
}
rs.initiate(config)
复制集rs1启动
192.168.0.107:
/appl/mongo/bin/mongod --shardsvr --replSet rs1 --port 40003 --dbpath /appl/data/shard2_1 --logpath /appl/data/shard2_1/log/shard2_1.log --logappend --fork
配置文件
rs1_1.conf
dbpath=/appl/data/shard2_1
logpath=/appl/data/shard2_1/log/shard2_1.log
journal=true
port=40003
replSet=rs1
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs1_1.conf
192.168.0.108:
/appl/mongo/bin/mongod --shardsvr --replSet rs1 --port 40004 --dbpath /appl/data/shard2_2 --logpath /appl/data/shard2_2/log/shard2_2.log --logappend --fork
配置文件
rs1_2.conf
dbpath=/appl/data/shard2_2
logpath=/appl/data/shard2_2/log/shard2_2.log
journal=true
port=40004
replSet=rs1
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs1_2.conf
192.168.0.105:
/appl/mongo/bin/mongod --shardsvr --replSet rs1 --port 40005 --dbpath /appl/data/shard2_3 --logpath /appl/data/shard2_3/log/shard2_3.log --logappend --fork
配置文件
rs1_3.conf
dbpath=/appl/data/shard2_3
logpath=/appl/data/shard2_3/log/shard2_3.log
journal=true
port=40005
replSet=rs1
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs1_3.conf
配置复制rs1
config = {_id: 'rs1', members: [
{_id: 0, host: '192.168.0.107:40003'},
{_id: 1, host: '192.168.0.108:40004'},
{_id: 2, host: '192.168.0.105:40005','arbiterOnly':true}]
}
rs.initiate(config)
启动配置节点:
192.168.0.105:
/appl/mongo/bin/mongod --configsvr --dbpath /appl/data/config1 --port 50000 --logpath /appl/data/config1/log/config1.log --logappend --fork
config_1.conf
dbpath=/appl/data/config1
logpath=/appl/data/config1/log/config1.log
journal=true
port=50000
oplogSize = 5000
fork = true
configsvr=true
/appl/mongo/bin/mongod -f /appl/mongo/config_1.conf
192.168.0.106:
/appl/mongo/bin/mongod --configsvr --dbpath /appl/data/config2 --port 50000 --logpath /appl/data/config2/log/config2.log --logappend --fork
config_2.conf
dbpath=/appl/data/config2
logpath=/appl/data/config2/log/config2.log
journal=true
port=50000
oplogSize = 5000
fork = true
configsvr=true
/appl/mongo/bin/mongod -f /appl/mongo/config_2.conf
192.168.0.108:
/appl/mongo/bin/mongod --configsvr --dbpath /appl/data/config3 --port 50000 --logpath /appl/data/config3/log/config3.log --logappend --fork
config_3.conf
dbpath=/appl/data/config3
logpath=/appl/data/config3/log/config3.log
journal=true
port=50000
oplogSize = 5000
fork = true
configsvr=true
/appl/mongo/bin/mongod -f /appl/mongo/config_3.conf
启动路由服务器:
192.168.0.106:
/appl/mongo/bin/mongos --configdb 192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000 --port 60000 --logpath /appl/data/mongos/mongos.log --logappend --fork
mongos_1.conf
logpath=/appl/data/mongos/mongos.log
port=60000
fork = true
configdb=192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000
/appl/mongo/bin/mongos -f /appl/mongo/mongos_1.conf
192.168.0.107:
/appl/mongo/bin/mongos --configdb 192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000 --port 60000 --logpath /appl/data/mongos/mongos.log --logappend --fork
mongos_2.conf
logpath=/appl/data/mongos/mongos.log
port=60000
fork = true
configdb=192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000
/appl/mongo/bin/mongos -f /appl/mongo/mongos_2.conf
192.168.0.108:
/appl/mongo/bin/mongos --configdb 192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000 --port 60000 --logpath /appl/data/mongos/mongos.log --logappend --fork
mongos_3.conf
logpath=/appl/data/mongos/mongos.log
port=60000
fork = true
configdb=192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000
/appl/mongo/bin/mongos -f /appl/mongo/mongos_3.conf
配置 Shard Cluster
连接到其中一台机器的端口 60000 的 mongos 进程,并切换到 admin 数据库做以下配置
db.runCommand({addshard:"rs0/192.168.0.105:40000,192.168.0.106:40001,192.168.0.107:40002"});
db.runCommand({addshard:"rs1/192.168.0.107:40003,192.168.0.108:40004,192.168.0.105:40005"});
192.168.0.105、
192.168.0.106、
192.168.0.107、
192.168.0.108、
192.168.0.105 mongod shard1_1 40000 (rs0-primayr)
mongod shard2_3 40005 (rs2-arbiter)
mongod config1 50000
192.168.0.106 mongod shard1_2 40001 (rs0-secondary)
mongod config2 50000
mongod mongos1 60000
192.168.0.107 mongod shard2_1 40003 (rs1-primayr)
mongod shard1_3 40002 (rs0-arbiter)
mongod mongos2 60000
192.168.0.108 mongod shard2_2 40004 (rs1-secondary)
mongod config3 50000
mongod mongos3 60000
192.168.0.105上创建目录:
mkdir -p /appl/data/shard1_1
mkdir -p /appl/data/shard1_1/log
mkdir -p /appl/data/shard2_3
mkdir -p /appl/data/shard2_3/log
mkdir -p /appl/data/config1
mkdir -p /appl/data/config1/log
192.168.0.106上创建目录:
mkdir -p /appl/data/shard1_2
mkdir -p /appl/data/shard1_2/log
mkdir -p /appl/data/config2
mkdir -p /appl/data/config2/log
mkdir -p /appl/data/mongos
192.168.0.107上创建目录:
mkdir -p /appl/data/shard2_1
mkdir -p /appl/data/shard2_1/log
mkdir -p /appl/data/shard1_3
mkdir -p /appl/data/shard1_3/log
mkdir -p /appl/data/mongos
192.168.0.108上创建目录:
mkdir -p /appl/data/shard2_2
mkdir -p /appl/data/shard2_2/log
mkdir -p /appl/data/config3
mkdir -p /appl/data/config3/log
mkdir -p /appl/data/mongos
复制集rs0启动
192.168.0.105:
/appl/mongo/bin/mongod --shardsvr --replSet rs0 --port 40000 --dbpath /appl/data/shard1_1 --logpath /appl/data/shard1_1/log/shard1_1.log --logappend --fork
配置文件
rs0_1.conf
dbpath=/appl/data/shard1_1
logpath=/appl/data/shard1_1/log/shard1_1.log
journal=true
port=40000
replset=rs0
oplogSize = 5000M
fork = true
directoryperdb = true
***************************************************************
dbpath=/appl/data/shard1_1
logpath=/appl/data/shard1_1/log/shard1_1.log
journal=true
port=40000
replSet=rs0
oplogSize = 5000
fork = true
*****************************************************************
/appl/mongo/bin/mongod -f /appl/mongo/rs0_1.conf
192.168.0.106:
/appl/mongo/bin/mongod --shardsvr --replSet rs0 --port 40001 --dbpath /appl/data/shard1_2 --logpath /appl/data/shard1_2/log/shard1_2.log --logappend --fork
rs0_2.conf
dbpath=/appl/data/shard1_2
logpath=/appl/data/shard1_2/log/shard1_2.log
journal=true
port=40001
replSet=rs0
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs0_2.conf
192.168.0.107:
/appl/mongo/bin/mongod --shardsvr --replSet rs0 --port 40002 --dbpath /appl/data/shard1_3 --logpath /appl/data/shard1_3/log/shard1_3.log --logappend --fork
rs0_3.conf
dbpath=/appl/data/shard1_3
logpath=/appl/data/shard1_3/log/shard1_3.log
journal=true
port=40002
replSet=rs0
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs0_3.conf
配置复制rs0
config = {_id: 'rs0', members: [
{_id: 0, host: '192.168.0.105:40000'},
{_id: 1, host: '192.168.0.106:40001'},
{_id: 2, host: '192.168.0.107:40002','arbiterOnly':true}]
}
rs.initiate(config)
复制集rs1启动
192.168.0.107:
/appl/mongo/bin/mongod --shardsvr --replSet rs1 --port 40003 --dbpath /appl/data/shard2_1 --logpath /appl/data/shard2_1/log/shard2_1.log --logappend --fork
配置文件
rs1_1.conf
dbpath=/appl/data/shard2_1
logpath=/appl/data/shard2_1/log/shard2_1.log
journal=true
port=40003
replSet=rs1
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs1_1.conf
192.168.0.108:
/appl/mongo/bin/mongod --shardsvr --replSet rs1 --port 40004 --dbpath /appl/data/shard2_2 --logpath /appl/data/shard2_2/log/shard2_2.log --logappend --fork
配置文件
rs1_2.conf
dbpath=/appl/data/shard2_2
logpath=/appl/data/shard2_2/log/shard2_2.log
journal=true
port=40004
replSet=rs1
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs1_2.conf
192.168.0.105:
/appl/mongo/bin/mongod --shardsvr --replSet rs1 --port 40005 --dbpath /appl/data/shard2_3 --logpath /appl/data/shard2_3/log/shard2_3.log --logappend --fork
配置文件
rs1_3.conf
dbpath=/appl/data/shard2_3
logpath=/appl/data/shard2_3/log/shard2_3.log
journal=true
port=40005
replSet=rs1
oplogSize = 5000
fork = true
/appl/mongo/bin/mongod -f /appl/mongo/rs1_3.conf
配置复制rs1
config = {_id: 'rs1', members: [
{_id: 0, host: '192.168.0.107:40003'},
{_id: 1, host: '192.168.0.108:40004'},
{_id: 2, host: '192.168.0.105:40005','arbiterOnly':true}]
}
rs.initiate(config)
启动配置节点:
192.168.0.105:
/appl/mongo/bin/mongod --configsvr --dbpath /appl/data/config1 --port 50000 --logpath /appl/data/config1/log/config1.log --logappend --fork
config_1.conf
dbpath=/appl/data/config1
logpath=/appl/data/config1/log/config1.log
journal=true
port=50000
oplogSize = 5000
fork = true
configsvr=true
/appl/mongo/bin/mongod -f /appl/mongo/config_1.conf
192.168.0.106:
/appl/mongo/bin/mongod --configsvr --dbpath /appl/data/config2 --port 50000 --logpath /appl/data/config2/log/config2.log --logappend --fork
config_2.conf
dbpath=/appl/data/config2
logpath=/appl/data/config2/log/config2.log
journal=true
port=50000
oplogSize = 5000
fork = true
configsvr=true
/appl/mongo/bin/mongod -f /appl/mongo/config_2.conf
192.168.0.108:
/appl/mongo/bin/mongod --configsvr --dbpath /appl/data/config3 --port 50000 --logpath /appl/data/config3/log/config3.log --logappend --fork
config_3.conf
dbpath=/appl/data/config3
logpath=/appl/data/config3/log/config3.log
journal=true
port=50000
oplogSize = 5000
fork = true
configsvr=true
/appl/mongo/bin/mongod -f /appl/mongo/config_3.conf
启动路由服务器:
192.168.0.106:
/appl/mongo/bin/mongos --configdb 192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000 --port 60000 --logpath /appl/data/mongos/mongos.log --logappend --fork
mongos_1.conf
logpath=/appl/data/mongos/mongos.log
port=60000
fork = true
configdb=192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000
/appl/mongo/bin/mongos -f /appl/mongo/mongos_1.conf
192.168.0.107:
/appl/mongo/bin/mongos --configdb 192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000 --port 60000 --logpath /appl/data/mongos/mongos.log --logappend --fork
mongos_2.conf
logpath=/appl/data/mongos/mongos.log
port=60000
fork = true
configdb=192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000
/appl/mongo/bin/mongos -f /appl/mongo/mongos_2.conf
192.168.0.108:
/appl/mongo/bin/mongos --configdb 192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000 --port 60000 --logpath /appl/data/mongos/mongos.log --logappend --fork
mongos_3.conf
logpath=/appl/data/mongos/mongos.log
port=60000
fork = true
configdb=192.168.0.105:50000,192.168.0.106:50000,192.168.0.108:50000
/appl/mongo/bin/mongos -f /appl/mongo/mongos_3.conf
配置 Shard Cluster
连接到其中一台机器的端口 60000 的 mongos 进程,并切换到 admin 数据库做以下配置
db.runCommand({addshard:"rs0/192.168.0.105:40000,192.168.0.106:40001,192.168.0.107:40002"});
db.runCommand({addshard:"rs1/192.168.0.107:40003,192.168.0.108:40004,192.168.0.105:40005"});