mongodb sharding

安装monodb软件

su – mongodb
tar zxvf mongodb-linux-x86_64-1.6.2.tar

创建数据目录
根据本例sharding架构图所示,在各台sever上创建shard数据文件目录
Server1:

su – monodb
cd /monodb
mkdir -p data/shard11
mkdir -p data/shard21

 

Server2:

su – monodb
cd /monodb
mkdir -p data/shard12
mkdir -p data/shard22

 

Server3:
su – monodb
cd /monodb
mkdir -p data/shard13
mkdir -p data/shard23

 

配置relica sets(复制集)

1.    配置shard1所用到的replica sets:

Server1:

cd /mongodb/mongodb-linux-x86_64-1.6.2

mkdir –p conf

cd conf

vim shard11.conf

shardsvr=true

replSet=shard1/172.16.2.14:27018

port=27018

dbpath=/mongoSharding/mongodata/data/shard11

oplogSize=10240

logpath=/mongoSharding/mongodata/logs/shard11.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/shard11.conf

Server2:
cd /mongodb/mongodb-linux-x86_64-1.6.2

mkdir –p conf

cd conf

vim shard21.conf

shardsvr=true

replSet=shard1/172.16.2.13:27018

port=27018

dbpath=/mongoSharding/mongodata/data/shard12

oplogSize=10240

logpath=/mongoSharding/mongodata/logs/shard12.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/shard12.conf

Server3:
cd /mongodb/mongodb-linux-x86_64-1.6.2

mkdir –p conf

cd conf

vim shard13.conf

shardsvr=true

replSet=shard1/172.16.2.15:27018

port=27018

dbpath=/mongoSharding/mongodata/data/shard13

oplogSize=10240

logpath=/mongoSharding/mongodata/logs/shard13.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/shard13.conf

 

初始化replica set
mongo连接其中一个mongod,执行:
> config = {_id: 'shard1', members: [

       {_id: 0, host: '172.16.2.13:27018'},

       {_id: 1, host: '172.16.2.14:27018'},

       {_id: 2, host: '172.16.2.15:27018'}]

       }

> rs.initiate(config);

同样方法,配置shard2用到的replica sets:

Server1:

cd /mongodb/mongodb-linux-x86_64-1.6.2

cd conf

vim shard21.conf

shardsvr=true

replSet=shard2/172.16.2.14:27019

port=27019

dbpath=/mongoSharding/mongodata/data/shard21

oplogSize=10240

logpath=/mongoSharding/mongodata/logs/shard21.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/shard21.conf

Server2:
cd /mongodb/mongodb-linux-x86_64-1.6.2

cd conf

vim shard22.conf

shardsvr=true

replSet=shard2/172.16.2.13:27019

port=27019

dbpath=/mongoSharding/mongodata/data/shard22

oplogSize=10240

logpath=/mongoSharding/mongodata/logs/shard22.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/shard22.conf

Server3:
cd /mongodb/mongodb-linux-x86_64-1.6.2

cd conf

vim shard23.conf

shardsvr=true

replSet=shard2/172.16.2.15:27019

port=27019

dbpath=/mongoSharding/mongodata/data/shard23

oplogSize=10240

logpath=/mongoSharding/mongodata/logs/shard23.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/shard23.conf

 

初始化replica set
mongo连接其中一个mongod,执行:
> config = {_id: 'shard2', members: [

       {_id: 0, host: '172.16.2.13:27019'},

       {_id: 1, host: '172.16.2.14:27019'},

       {_id: 2, host: '172.16.2.15:27019'}]

       }

> rs.initiate(config);

 

2.3配置三台config server

Server1:
mkdir -p /mongodb/data/config

cd /mongodb/mongodb-linux-x86_64-1.6.2

cd conf

vim config.conf

configsvr=true

dbpath=/mongoSharding/mongodata/data/config

port=30000

logpath=/mongoSharding/mongodata/logs/config.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/config.conf


Server2:
mkdir -p /mongodb/data/config
cd /mongodb/mongodb-linux-x86_64-1.6.2

cd conf

vim config.conf

configsvr=true

dbpath=/mongoSharding/mongodata/data/config

port=30000

logpath=/mongoSharding/mongodata/logs/config.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/config.conf

Server3:
mkdir -p /mongodb/data/config
cd /mongodb/mongodb-linux-x86_64-1.6.2

cd conf

vim config.conf

configsvr=true

dbpath=/mongoSharding/mongodata/data/config

port=30000

logpath=/mongoSharding/mongodata/logs/config.log

logappend=true

fork=true

:wq

cd /mongodb/mongodb-linux-x86_64-1.6.2/bin

./mongod –f ../conf/config.conf

2.4配置mongs

server1,server2,server3上分别执行:

Cd conf

Vim mongos.conf

configdb=172.16.2.13:30000,172.16.2.14:30000,172.16.2.15:30000

port=40000

chunkSize=5

logpath=/mongoSharding/mongodata/logs/mongos.log

logappend=true

fork=true

:wq

Cd bin

./mongos –f ../conf/mongos.conf

 

 

添加复制集

连接到其中一个mongos进程,并切换到admin数据库做以下配置
1. 
连接到mongs,并切换到admin

 

./mongo 172.16.2.14:40000/amdin

>use admin;

>db.runCommand( { addshard : "shard1/172.16.2.13:27018,172.16.2.14:27018,172.16.2.15:27018,name:s1,maxsize:20480} );


你可能感兴趣的:(mongodb sharding)