Mongodb4.0分片集群(Centos7)

环境

centos7.4 mongodb-4.0.22 

 

配置说明

 Shardconfigmongos
192.168.56.1270172701827019
192.168.56.22701727018 
192.168.56.32701727018 
192.168.56.427017  

安装过程

 Shard(27017)Config(27018)mongos(27019)

安装

useradd mongodb -p mongodb

su - mongodb

 

wget  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/mongodb-linux-x86_64-4.0.22.tgz

tar -zxf mongodb-linux-x86_64-4.0.22.tgz
mv mongodb-linux-x86_64-4.0.22   mongodb

 

vim .bash_profile
PATH=$PATH:$HOME/mongodb/bin
source .bash_profile

 

配置文件

processManagement:  
    fork: true

 

net:  
    bindIp: 0.0.0.0  
    port: 27017
    maxIncomingConnections: 10000
 

storage:  
    dbPath: /home/mongodb/mongodb_27017
    wiredTiger:  
        engineConfig:  
            cacheSizeGB: 16


sharding:  
    clusterRole: shardsvr
    archiveMovedChunks: false

processManagement:  
    fork: true  


net:  
    bindIp: 0.0.0.0
    port: 27018
    maxIncomingConnections: 10000

storage:  
    dbPath: /home/mongodb/mongodb_27018
    wiredTiger:  
        engineConfig:  
            cacheSizeGB: 1

replication:
    oplogSizeMB: 30720
    replSetName: repl_set

sharding:
    clusterRole: configsvr

processManagement:  
    fork: true  
 

net:  
    bindIp: 0.0.0.0  
    port: 27019  
 

sharding:  
    configDB: repl_set/192.168.56.1:27018,

192.168.56.2:27018,192.168.56.3:27018

创建目录

su - mongodb

mkdir mongodb_27017

touch mongodb_27017/mongodb.log

su - mongodb

mkdir mongodb_27018

touch mongodb_27018/mongodb.log

su - mongodb

mongodb_27019

touch mongodb_27019/mongodb.log

启动实例

/home/mongodb/mongodb/bin/mongod -f /home/mongodb/mongod_27017.conf &
/home/mongodb/mongodb/bin/mongod -f /home/mongodb/mongod_27018.conf &
/home/mongodb/mongodb/bin/mongos -f /home/mongodb/mongos_27019.conf &

初始化

副本集

 

mongo --host 127.0.0.1:27018


config = { _id: "repl_set", members: [

{_id: 0, host: "192.168.56.1:27018"},

{_id: 1, host: "192.168.56.2:27018"},

{_id: 2, host: "192.168.56.3:27018"}

]}


rs.initiate(config)

rs.status()

 
添加分片  

mongo --host 127.0.0.1:27019


use admin;
sh.addShard("192.168.56.1:27017")
sh.addShard("192.168.56.2:27017")

sh.addShard("192.168.56.3:27017")

sh.addShard("192.168.56.4:27017")

sh.status()

表分片  

mongo --host 127.0.0.1:27019

 

use admin;
db.runCommand({enablesharding:"test_db"});
db.runCommand({shardcollection:"test_db.test_tb",key:{'col_1':'hashed'} });

 

sh.status()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值