“芒果数据库”————mongodb分片全集和管理
目录
- 一、mongodb分片群集
- 二、分片管理
一、mongodb分片群集
cd /opt
tar zxvf mongodb-linux-x86_64-3.2.1.tgz #将包拖入至/opt下
mv mongodb-linux-x86_64-3.2.1 /usr/local/mongodb
cd /usr/local/mongodb
cd bin/
ln -s /usr/local/mongodb/bin/mongo /usr/bin/mongo
ln -s /usr/local/mongodb/bin/mongod /usr/bin/mongod
mkdir -p /data/mongodb/mongodb{1,2,3,4}
cd /data/mongodb
mkdir logs
cd logs
touch mongodb{1,2,3,4}.log
chmod 777 *
ulimit -u 25000 #优化打开进程和文件数量,否则会造成缓存卡死
ulimit -n 25000cd /usr/local/mongodb/bin/
vim mongodb1.conf
port=37017
dbpath=/data/mongodb/mongodb1
logpath=/data/mongodb/logs/mongodb1.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
configsvr=true
如果某节点内存不足时,从其他节点分配内存
sysctl -w vm.zone_reclaim_mode=0
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
启动
mongod -f mongodb1.conf
mongo --port 37017
再创建二个实例
cp -p mongodb1.conf mongodb2.conf
vim mongodb2.conf
port=47017
dbpath=/data/mongodb/mongodb2
logpath=/data/mongodb/logs/mongodb2.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
shardsvr=truecp -p mongodb2.conf mongodb3.conf
vim mongodb3.conf
port=47018
dbpath=/data/mongodb/mongodb3
logpath=/data/mongodb/logs/mongodb3.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
shardsvr=truemongod -f mongodb2.conf
mongod -f mongodb3.conf #启动mongo --port 47017
mongo --port 47018
启动路由服务器
./mongos --port 27017 --fork --logpath=/usr/local/mongodb/bin/route.log --configdb 192.168.241.9:37017 --chunkSize 1 ##mongos开启路由服务器
2021-04-13T09:13:29.225+0800 W SHARDING [main] Running a sharded cluster with fewer than 3 config servers should only be done for testing purposes and is not recommended for production.
about to fork child process, waiting until server is ready for connections.
forked process: 63252
child process started successfully, parent exiting
查看分片
[root@localhost bin]# mongo
MongoDB shell version: 3.2.1
connecting to: test
Server has startup warnings:
2021-04-13T09:46:43.802+0800 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
2021-04-13T09:46:43.802+0800 I CONTROL [main] mongos> show dbs
config 0.031GBmongos> sh.status() #shards下为空,没有分片服务器
--- Sharding Status --- sharding version: {"_id" : 1,"minCompatibleVersion" : 5,"currentVersion" : 6,"clusterId" : ObjectId("6074f039076ea44dc58c1a90")
}shards:active mongoses:"3.2.1" : 1balancer:Currently enabled: yesCurrently running: noFailed balancer rounds in last 5 attempts: 0Migration Results for the last 24 hours: No recent migrationsdatabases:
# shards此时为空的#添加分片
mongos> sh.addShard("192.168.241.9:47017")
{ "shardAdded" : "shard0000", "ok" : 1 }
mongos> sh.addShard("192.168.241.9:47018")
{ "shardAdded" : "shard0001", "ok" : 1 }
mongos> sh.status()
--- Sharding Status --- sharding version: {"_id" : 1,"minCompatibleVersion" : 5,"currentVersion" : 6,"clusterId" : ObjectId("6074f039076ea44dc58c1a90")
}shards:{ "_id" : "shard0000", "host" : "192.168.241.9:47017" }{ "_id" : "shard0001", "host" : "192.168.241.9:47018" }active mongoses:"3.2.1" : 1balancer:Currently enabled: yesCurrently running: noFailed balancer rounds in last 5 attempts: 0Migration Results for the last 24 hours: No recent migrationsdatabases:————分片功能——————
use info
db.test.insert({"id":1,"name":"tx"})
for (var i=2;i<=1000;i++)db.test.insert ({"id":i,"name":"tom"+i})show tables
db.test.find().limit(5)
{ "_id" : ObjectId("6074fb0a08763fc9b512d6ee"), "id" : 1, "name" : "tx" }
{ "_id" : ObjectId("6074fb3908763fc9b512d6ef"), "id" : 2, "name" : "tom2" }
{ "_id" : ObjectId("6074fb3908763fc9b512d6f0"), "id" : 3, "name" : "tom3" }
{ "_id" : ObjectId("6074fb3908763fc9b512d6f1"), "id" : 4, "name" : "tom4" }
{ "_id" : ObjectId("6074fb3908763fc9b512d6f2"), "id" : 5, "name" : "tom5" }
这里说明数据已经成功导入sh.status()
--- Sharding Status --- sharding version: {"_id" : 1,"minCompatibleVersion" : 5,"currentVersion" : 6,"clusterId" : ObjectId("6074f039076ea44dc58c1a90")
}shards:{ "_id" : "shard0000", "host" : "192.168.241.9:47017" }{ "_id" : "shard0001", "host" : "192.168.241.9:47018" }active mongoses:"3.2.1" : 1balancer:Currently enabled: yesCurrently running: noFailed balancer rounds in last 5 attempts: 0Migration Results for the last 24 hours: No recent migrationsdatabases:{ "_id" : "info", "primary" : "shard0000", "partitioned" : false }
#"partitioned" : false 说明没有分片sh.enableSharding("info") #启动数据库分片
sh.status()databases:{ "_id" : "info", "primary" : "shard0000", "partitioned" : true }db.test.createIndex({"id":1}) #对test表创建索引
{"raw" : {"192.168.241.9:47017" : {"createdCollectionAutomatically" : false,"numIndexesBefore" : 1,"numIndexesAfter" : 2,"ok" : 1}},"ok" : 1
}sh.shardCollection("info.test",{"id":1}) #表分片
{ "collectionsharded" : "info.test", "ok" : 1 }sh.status()
二、分片管理
use info
for (var i=1;i<=50000;i++)db.test2.insert({"id":1,"name":"jack"+i})
db.test2.createIndex({"id":1})
sh.shardCollection("info.test2",{"id":1})
db.test2.stats()#添加标签
sh.addShardTag("shard0000","sales00")
sh.addShardTag("shard0001","sales01")#连接配置服务器
mongo --port 37017use config
show tables
...
chunks
collections
databases #这3个集合是之前定义的分片服务器的信息
...cd /use/local/mongodb/bin
cp -p mongodb3.conf mongodb4.conf
vim mongodb4.conf
port=47019
dbpath=/data/mongodb/mongodb4
logpath=/data/mongodb/logs/mongodb4.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
shardsvr=truemongod -f mongodb4.confmongo
sh.addShard("192.168.241.9:47019")
chunks:shard0000 4shard0001 4shard0000 3删除分片节点
use admin
db.runCommand({"removeshard":"192.168.241.9:47019"})
“芒果数据库”————mongodb分片全集和管理相关推荐
- MongoDB(芒果数据库)学习(三)——Mongoose搭建及运用(Schemas、Model、Document)
MongoDB(芒果数据库)学习(三)---Mongoose搭建以及基础 一.mongoose前言 mongoose的官方网站:https://mongoosejs.com/ 简介: 之前我们通过sh ...
- MongoDB芒果数据库学习笔记一
MongoDB–开源的NoSQL数据库.最接近sql 得数据库 MongoDB的概念:1.mongo 2.索引 3.集合 4.复制集 5.分片 6.数据均衡 MongoDB搭建 MongoDB的使用 ...
- 战神引擎mud2没有mysql文件_战神引擎架设不要(MongoDB)芒果数据库配置教程
教程准备 战神引擎服务端一套 Vc运行库 libmySQL.dll logincenter网关(用于MYSQL注册) phpStudy纯净版套件 Account数据库 Pay.php(网页在线充值) ...
- 芒果数据库 四天学习笔记分享
第一天 数据库 MongoDB(芒果数据库) 数据存储阶段 文件管理阶段(.txt .doc .xls) 优点:数据可以长期保存 可以存储大量的数据 使用简单 缺点:数据一 ...
- mongodb分片扩展架构
目录 一.简介 二.分片集群 三.数据分布策略 四.Mongos访问模式 五.Config元数据 六.分片均衡 参考文档 一.简介 MongoDB目前3大核心优势:『灵活模式』+ 『高可用性』 + 『 ...
- NoSQL数据库-MongoDB和Redis
NoSQL数据库-MongoDB和Redis 发布于2012-12-20,来源:比特网 1NoSQL简述 CAP(Consistency,Availabiity,Partitiontolera ...
- 微信小游戏爆款秘笈 数据库MongoDB攻略篇
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯云数据库 TencentDB 发表于云+社区专栏 随着微信小游戏的爆发,越来越多开发者关注到MongoDB与小游戏业务的契合度. ...
- MongoDb分片集群认证
本文主要基于已经搭建好的未认证集群,结合上篇Mongodb副本集分片集群模式环境部署(https://www.cnblogs.com/woxingwoxue/p/9875878.html), Mong ...
- (更新时间)2021年5月11日 MongoDB数据库 MongoDB面试题
MongoDB高频面试题 文章目录 MongoDB高频面试题 1.MongoDB是什么? 2.MongoDB有哪些特点? 3.MySQL与MongoDB之间最基本的差别是什么? 4.monogodb中 ...
最新文章
- 数字汽车钥匙的安全性增强技术
- Pytorch预训练模型下载并加载(以VGG为例)自定义路径
- 跟我一起学.NetCore之WebApi接口裸奔有风险(Jwt)
- php 小知识随手记 new self() 和new static()作用和区别
- Linux下基于 Docker 搭建 MySQL 主从复制(1 Master+2 Slave)
- 轻量级 Java Web 服务框架漫谈
- 携程签约日本爱知县 探索主题游促中日交流
- 2015-12-01 存储过程
- jQuery学习整理 (3) 使用jQuery操作元素的属性与样式
- android 监听网络的详细例子,android 短信 发送 监听 拦截等自己写的demo
- A4988驱动步进电机教学
- 2019年全国大学生电子设计竞赛D题简易电路特性测试仪试题
- 【数说人物】170个热搜刷屏网络 起底康巴汉子丁真爆红路径
- 新手学编程?选python吧!
- 游戏外挂开发原理初探——植物大战僵尸内存挂为例
- Liunx下Intel无线网卡驱动安装
- 山特UPS不间断电源的主要技术参数
- ubuntu命令行 播放音乐
- 数据库中删除重复数据并保留一条。
- linux中wq和wq 的区别,wq+linux+wq什么意思