mongo分片及驱动

安装

直接下载官方程序

 

在三台机器上如下配置,其中文件名称,ip,端口可作相应更改。

 

1、拷贝程序到/opt/下,创建分片配置文件。

#shard21.conf

dbpath=/data/shard21

logpath = /data/shard21.log

pidfilepath = /opt/mongodb/shard21.pid

directoryperdb = true

logappend = true

replSet = shard2

bind_ip=10.105.33.6

port = 27017

oplogSize = 100

fork = true

noprealloc=true

 

2、创建mongos配置文件

dbpath = /data/config

logpath =/data/config.log

logappend = true

bind_ip = 10.105.33.6

port = 20000

fork = true

 

启动

在三台机器分别执行如下,文件名称,ip地址相应修改。

/opt/mongodb/bin/mongod --shardsvr -f /opt/mongodb/shard21.conf

/opt/mongodb/bin/mongod --configsvr -f /opt/mongodb/config.conf

/opt/mongodb/bin/mongos --configdb 10.237.168.179:20000,10.131.154.192:20000,10.105.36.235:20000 --port 30000 --logpath /data/route.log --logappend --fork

 

 

配置

设置副本

use admin

config={_id:"shard2",members:[{"_id":0,"host":"10.105.33.6:27017,","priority":2},{"_id":1,"host":",10.247.40.202:27017","priority":1},{"_id":2,"host":"10.131.158.204:27017","arbiterOnly":true}]}

rs.initiate(config)

 

添加分片

use admin

db.runCommand({addshard:"shard2/10.105.33.6:27017,10.247.40.202:27017,10.131.158.204:27017",name:"shard2",maxsize:20480})

 

db.runCommand({addshard:"shard4/10.105.49.216:27017,10.131.185.59:27017,10.131.224.105:27017",name:"shard4",maxsize:0})

 

db.runCommand({enablesharding : "lbstest"})

db.runCommand({"shardCollection":"lbstest.test",key:{"line_way":1,"user_id":1}})

 

db.runCommand({listshards:1});

 

 

地理信息库测试

use lbstest;

db.test.ensureIndex({“location”:”2d”})

db.test.ensureIndex({“location”:” 2dsphere”})

db.test.ensureIndex({"line_way":1})

db.test.ensureIndex({"user_id":1})

db.test.ensureIndex({"line_way":1,"user_id":1});

db.test.insert({"user_id":3,"location":{"lat":22.111,"long":33.222},"target":"t3","line_way":"xiamen_2_zhangzhou"});

 

 

mongo c++驱动

下载mongo驱动

下载boost库

 

sh bootstrap.sh

sudo ./b2 --with-filesystem  --with-regex --with-system --with-thread --with-signals --with-regex install

 

mongo c++驱动安装

sudo yum install scons openssl-devel libgsasl libgsasl-develcyrus-sasl cyrus-sasl-devel

 

进入mongo驱动库

sudo scons --prefix=/opt/mongo-driver --ssl  --use-sasl-client  install

 

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值