文档章节

21.38 mongodb分片搭建(中)

脑洞老湿_
 脑洞老湿_
发布于 2017/10/20 11:06
字数 1329
阅读 5
收藏 0

21.38 mongodb分片搭建(中)

分片搭建–分片配置
添加配置文件shard1.conf(三台机器都操作)

vim /etc/mongod/shard1.conf //加入如下内容
pidfilepath = /var/run/mongodb/shard1.pid
dbpath = /data/mongodb/shard1/data
logpath = /data/mongodb/shard1/log/shard1.log
logappend = true
bind_ip = 0.0.0.0   ##生产环境,最好设为绑定ip本机;因为我们没有设密码
port = 27001
fork = true
httpinterface=true #打开web监控
rest=true
replSet=shard1 #副本集名称
shardsvr = true #declare this is a shard db of a cluster;
maxConns=20000 #设置最大连接数

添加配置文件shard2.conf(三台机器都操作)

 vim /etc/mongod/shard2.conf //加入如下内容
pidfilepath = /var/run/mongodb/shard2.pid
dbpath = /data/mongodb/shard2/data
logpath = /data/mongodb/shard2/log/shard2.log
logappend = true
bind_ip = 0.0.0.0
port = 27002
fork = true
httpinterface=true #打开web监控
rest=true
replSet=shard2 #副本集名称
shardsvr = true #declare this is a shard db of a cluster;
maxConns=20000 #设置最大连接数

添加配置文件shard3.conf(三台机器都操作)

 vim /etc/mongod/shard3.conf //加入如下内容
pidfilepath = /var/run/mongodb/shard3.pid
dbpath = /data/mongodb/shard3/data
logpath = /data/mongodb/shard3/log/shard3.log
logappend = true
bind_ip = 0.0.0.0
port = 27003
fork = true
httpinterface=true #打开web监控
rest=true
replSet=shard3 #副本集名称
shardsvr = true #declare this is a shard db of a cluster;
maxConns=20000 #设置最大连接数

启动shard1

mongod -f /etc/mongod/shard1.conf //三台机器都要操作
 登录130或者132任何一台机器的27001端口初始化副本集,133之所以不行,是因为shard1我们把133这台机器的27001端口作为了仲裁节点
 mongo --port 27001
 use admin
 config = { _id: "shard1", members: [ {_id : 0, host : "192.168.133.130:27001"}, {_id: 1,host : "192.168.133.132:27001"},{_id : 2, host : "192.168.133.133:27001",arbiterOnly:true}] }
 rs.initiate(config)

启动shard2

mongod -f /etc/mongod/shard2.conf //三台机器都要操作
 登录132或者133任何一台机器的27002端口初始化副本集,130之所以不行,是因为shard2我们把130这台机器的27002端口作为了仲裁节点
 mongo --port 27002
 use admin
 config = { _id: "shard2", members: [ {_id : 0, host : "192.168.133.130:27002" ,arbiterOnly:true},{_id : 1, host : "192.168.133.132:27002"},{_id : 2, host : "192.168.133.133:27002"}] }
 rs.initiate(config)

启动shard3

mongod -f /etc/mongod/shard3.conf //三台机器都要操作
 登录130或者133任何一台机器的27003端口初始化副本集,132之所以不行,是因为shard3我们把132这台机器的27003端口作为了仲裁节点
 mongo --port 27003
 use admin
 config = { _id: "shard3", members: [ {_id : 0, host : "192.168.133.130:27003"},  {_id : 1, host : "192.168.133.132:27003", arbiterOnly:true}, {_id : 2, host : "192.168.133.133:27003"}] }
 rs.initiate(config)

完成了副本集shard1、2、3的操作之后,接下来就是配置路由服务器;

21.39 mongodb分片搭建(下)

分片搭建–配置路由服务器

  • 添加配置文件(三台机器都操作)
  • vim /etc/mongod/mongos.conf //加入如下内容
    pidfilepath = /var/run/mongodb/mongos.pid
    logpath = /data/mongodb/mongos/log/mongos.log
    logappend = true
    bind_ip = 0.0.0.0
    port = 20000
    fork = true
    configdb = configs/192.168.133.130:21000,192.168.133.132:21000,192.168.133.133:21000 #监听的配置服务器,只能有1个或者3个,configs为配置服务器的副本集名字
    maxConns=20000 #设置最大连接数
  • 启动mongos服务,注意命令,前面都是mongod,这里是mongos
  • mongos -f /etc/mongod/mongos.conf

分片搭建–启用分片

  • 登录任何一台20000端口
  • mongo --port 20000
  • 把所有分片和路由器串联
    sh.addShard("shard1/192.168.133.130:27001,192.168.133.132:27001,192.168.133.133:27001")
    sh.addShard("shard2/192.168.133.130:27002,192.168.133.132:27002,192.168.133.133:27002")
    sh.addShard("shard3/192.168.133.130:27003,192.168.133.132:27003,192.168.133.133:27003")
  • 查看集群状态
    sh.status()
[root@Dasoncheng ~]# cat /etc/mongod/mongos.conf 
pidfilepath = /var/run/mongodb/mongos.pid
logpath = /data/mongodb/mongos/log/mongos.log
logappend = true
bind_ip = 0.0.0.0
port = 20000
fork = true
configdb = configs/192.168.60.11:21000,192.168.60.12:21000,192.168.60.13:21000 #监听的配置服务器,只能有1个或者3个,configs为配置服务器的副本集名字
maxConns=20000 #设置最大连接数
[root@Dasoncheng ~]# mongos -f /etc/mongod/mongos.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3379
child process started successfully, parent exiting
[root@Dasoncheng ~]# mongo --port 20000
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:20000/
MongoDB server version: 3.4.9
mongos> sh.addShard("shard1/192.168.60.11:27001,192.168.60.12:27001,192.168.60.13:27001")
{ "shardAdded" : "shard1", "ok" : 1 }
mongos> sh.addShard("shard2/192.168.60.11:27002,192.168.60.12:27002,192.168.60.13:27002")
{ "shardAdded" : "shard2", "ok" : 1 }
mongos> sh.addShard("shard3/192.168.60.11:27003,192.168.60.12:27003,192.168.60.13:27003")
{ "shardAdded" : "shard3", "ok" : 1 }
mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
	"_id" : 1,
	"minCompatibleVersion" : 5,
	"currentVersion" : 6,
	"clusterId" : ObjectId("59e957b4b1833892fcc37ec7")
}
  shards:
	{  "_id" : "shard1",  "host" : "shard1/192.168.60.11:27001,192.168.60.12:27001",  "state" : 1 }
	{  "_id" : "shard2",  "host" : "shard2/192.168.60.12:27002,192.168.60.13:27002",  "state" : 1 }
	{  "_id" : "shard3",  "host" : "shard3/192.168.60.11:27003,192.168.60.13:27003",  "state" : 1 }
  active mongoses:
	"3.4.9" : 1
 autosplit:
	Currently enabled: yes
  balancer:
	Currently enabled:  yes
	Currently running:  no
		Balancer lock taken at Fri Oct 20 2017 14:44:12 GMT+0800 (CST) by ConfigServer:Balancer
	Failed balancer rounds in last 5 attempts:  0
	Migration Results for the last 24 hours: 
		No recent migrations
  databases:

有一个小错误:

[root@Dasoncheng ~]# mongos -f /etc/mongod/mongos.conf   
##启动mongos报错,只有60.11启动了;根据报错提示 查看了mongos.conf发现逗号","后面多了一个空格;我删掉重新启动 又报错 ,看下面
2017-10-20T15:38:02.214+0800 I NETWORK  [main] getaddrinfo(" 192.168.60.12") failed: Name or service not known
2017-10-20T15:38:02.330+0800 I NETWORK  [main] getaddrinfo(" 192.168.60.13") failed: Name or service not known
about to fork child process, waiting until server is ready for connections.
forked process: 3316
child process started successfully, parent exiting
[root@Dasoncheng ~]# cat /etc/mongod/mongos.conf 
pidfilepath = /var/run/mongodb/mongos.pid
logpath = /data/mongodb/mongos/log/mongos.log
logappend = true
bind_ip = 0.0.0.0
port = 20000
fork = true
configdb = configs/192.168.60.11:21000, 192.168.60.12:21000, 192.168.60.13:21000 #监听的配置服务器,只能有1个或者3个,configs为配置服务器的副本集名字
maxConns=20000 #设置最大连接数
[root@Dasoncheng ~]# !v
vim /etc/mongod/mongos.conf 
[root@Dasoncheng ~]# mongos -f /etc/mongod/mongos.conf  
##在这里启动报错,我就把进程mongos杀死了,pkill mongos=killall monogs
about to fork child process, waiting until server is ready for connections.
forked process: 3354
ERROR: child process failed, exited with error number 48
[root@Dasoncheng ~]# pkill mongos
[root@Dasoncheng ~]# mongos -f /etc/mongod/mongos.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3379
child process started successfully, parent exiting
##启动成功;

© 著作权归作者所有

共有 人打赏支持
脑洞老湿_
粉丝 3
博文 152
码字总数 124412
作品 0
荆州
21.36 mongodb分片介绍

21.36 mongodb分片介绍 分片就是将数据库进行拆分,将大型集合分隔到不同服务器上。比如,本来100G的数据,可以分割成10份存储到10台服务器上,这样每台机器只有10G的数据。 通过一个mongos的...

脑洞老湿_
2017/10/20
0
0
mongodb 集群搭建 分片+副本集

mkdir -p /home/mongodb/conf mkdir -p /home/mongodb/mongos/log mkdir -p /home/mongodb/config/data mkdir -p /home/mongodb/config/log mkdir -p /home/mongodb/shard1/data mkdir -p /h......

674591788
06/26
0
0
Mongodb 副本集+分片集群搭建

环境需求: 在三台机器上搭建副本集,在副本集上做分片 服务器IP: 192.168.1.232/192.168.1.238/192.168.1.241 安装Mongodb all nodes: tar zxvf mongodb-linux-x86_64-rhel62-3.4.4.tgz c...

startuppp
06/26
0
0
MongoDB4.0搭建分布式集群-笔记

搭建之前先了解一下MongoDB分片群集主要有如下三个组件: Shard:分片服务器,用于存储实际的数据块,实际生产环境中一个shard server 角色可以由几台服务器组成一个Peplica Set 承担,防止主...

Calon
09/13
0
0
MongoDB集群部署 - 带访问控制的分片副本集

1. 前言   Ceilometer将meter、event等数据保存在MongoDB中,之前将MongoDB部署在控制节点上,使用三副本模式,时间长了发现meter数据爆炸式增长,区区2T的磁盘捉襟见肘,而想删除旧数据,...

Sai18
08/16
0
0

没有更多内容

加载失败,请刷新页面

加载更多

解决访问swaggerUI接口文档显示basic-error-controler问题

使用swagger生成接口文档后,访问http://localhost:8888/swagger-ui.html#/,显示如下: 解决方法: public Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2)......

张欢19933
23分钟前
1
0
区块链教程以太坊源码分析core-state-process源码分析(二)

兄弟连区块链教程以太坊源码分析core-state-process源码分析(二):关于g0的计算,在黄皮书上由详细的介绍和黄皮书有一定出入的部分在于if contractCreation && homestead {igas.SetUin...

兄弟连区块链入门教程
28分钟前
0
0
BLAKE2 — fast secure hashing

BLAKE2 — fast secure hashing SPECS | CODE | B2SUM | CONTACT | USERS | THIRD-PARTY SOFTWARE | CRYPTANALYSIS | FAQ Come from http://www.blake2.net/ BLAKE2 is a cryptographic has......

openthings
35分钟前
4
0
Titan Framework MongoDB深入理解3

在前两篇文章中,我们介绍了操作Mongo数据库的类型Curd和Finder,下面要理解的是框架内mongoDB操作的条件类型——MongoDBQueryCondition。 MongoDBQueryCondition是一个接口,规定了一些实现...

云季科技
35分钟前
0
0
数据结构(算法)-树

#include <iostream>#include <malloc.h>using namespace std;#define MaxSize 100typedef char ElemType;typedef struct node{ElemType data;struct node *left ,*......

ashuo
37分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部