mongoDB 分片集群搭建

1.搭建环境

OS:centos7

mem:8G

2.软件版本

mongodb-linux-x86_64-3.2.22

端口规划 

    ip port
mongos   127.0.0.1 28017
config 镜像 127.0.0.1 28018
镜像 127.0.0.1 28019
镜像 127.0.0.1 28020
shard1 p 127.0.0.1 28021
s 127.0.0.1 28022
s 127.0.0.1 28023
shard2 p 127.0.0.1 28024
s 127.0.0.1 28025
s 127.0.0.1 28026

3.搭建步骤

3.1 shard1集群

[root@db-test log]# cat /data/mongodb/28021/conf/mongod.conf
dbpath= /data/mongodb/28021/data
directoryperdb = true
logpath=/data/mongodb/28021/log/mongodb.log   
logappend=true
port=28021
pidfilepath=/data/mongodb/28021/log/mongodb.pid
syncdelay = 60
cpu = true
verbose = true
httpinterface = true 
noprealloc = true
replSet = flagm01
oplogSize = 2048
fork = true
keyFile=/data/mongodb/28021/conf/keyfile
auth = true
journal = true

 其他2个节点一致

3.2 shard2集群

[root@db-test log]# cat /data/mongodb/28024/conf/mongod.conf
dbpath= /data/mongodb/28024/data
directoryperdb = true
logpath=/data/mongodb/28024/log/mongodb.log   
logappend=true
port=28024
pidfilepath=/data/mongodb/28024/log/mongodb.pid
syncdelay = 60
cpu = true
verbose = true
httpinterface = true 
noprealloc = true
replSet = flagm02
oplogSize = 2048
fork = true
keyFile=/data/mongodb/28024/conf/keyfile
auth = true
journal = true

3.3 configserver

[root@db-test log]# cat /data/mongodb/28018/conf/mongod.conf
dbpath=/data/mongodb/28018/data
directoryperdb = true
logpath=/data/mongodb/28018/log/mongodb.log
logappend=true
port=28018
pidfilepath=/data/mongodb/28018/data/mongodb.pid
syncdelay = 60
cpu = true
verbose = true
httpinterface = true
noprealloc = true
oplogSize = 2048
fork = true
keyFile=/data/mongodb/28018/conf/keyfile
auth = true
journal = true
configsvr=true

storageEngine=wiredTiger
wiredTigerCacheSizeGB=1
wiredTigerDirectoryForIndexes=true
wiredTigerCollectionBlockCompressor=snappy
wiredTigerJournalCompressor=snappy
wiredTigerIndexPrefixCompression=1

3.4 mongos

[root@db-test log]# cat /data/mongodb/28017/conf/mongos.conf
configdb=localhost:28018,localhost:28019,localhost:28020
port=28017
chunkSize=100
keyFile=/data/mongodb/28017/data/keyfile
logpath=/data/mongodb/28017/log/mongos.log
fork=true

3.5 启动

[root@db-test log]# ps -ef|grep mongo
root       8535      1  1 15:25 ?        00:01:38 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28021/conf/mongod.conf
root       8571      1  1 15:25 ?        00:02:02 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28022/conf/mongod.conf
root       8612      1  1 15:25 ?        00:01:39 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28023/conf/mongod.conf
root       9795      1  1 15:30 ?        00:01:24 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28024/conf/mongod.conf
root       9829      1  1 15:30 ?        00:01:20 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28025/conf/mongod.conf
root       9865      1  1 15:31 ?        00:01:21 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28026/conf/mongod.conf
root      10734      1  0 15:34 ?        00:01:05 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28018/conf/mongod.conf
root      10768      1  0 15:34 ?        00:01:02 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28020/conf/mongod.conf
root      10946      1  0 15:36 ?        00:00:28 /opt/mongodb-linux-x86_64-3.2.22/bin/mongos -f /data/mongodb/28017/conf/mongos.conf
root      13179      1  0 16:08 ?        00:00:44 /opt/mongodb-linux-x86_64-3.2.22/bin/mongod -f /data/mongodb/28019/conf/mongod.conf

3.6 登录配置

配置
shard1
shard2


登录mongos
/opt/module/mongodb-linux-x86_64-3.2.4/bin/mongo --port 25500

db.runCommand({addshard:"f01/localhost:28024,localhost:28025,localhost:28026",name:"fSetA02"})
db.runCommand({addshard:"f02/localhost:28021,localhost:28022,localhost:28023",name:"fSetA02"})
#查看分片
sh.status();

#创建管理员账户
use admin
db.createUser(  
  {  
    user: "admin",  
    pwd: "admin",  
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]  
  }  
)

 

你可能感兴趣的:(mongoDB)