IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> 单机mongodb测试集群 -> 正文阅读

[大数据]单机mongodb测试集群

在这里插入图片描述

三个角色

mongos 单节点或双节点
configserver 至少三节点副本集
shard 至少三节点副本集

分片集群生产搭建参考文档
https://www.mongodb.com/docs/v4.2/core/sharded-cluster-components/
https://www.mongodb.com/docs/v4.2/tutorial/deploy-shard-cluster/

注意一定要关闭SELINUX
查看sestatus

安装mongodb

vim /etc/yum.repos.d/mongodb-org-4.2.repo

[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

yum install -y mongodb-org mongodb-org-tools mongodb-org-shell

创建pid目录

mkdir /var/run/mongodb/

config搭建

config集群启动配置文件为3个组成replicaset

config1.conf
config2.conf
config3.conf

创建目录

mkdir -p /dbstorage/mongoconfig1
mkdir -p /dbstorage/mongoconfig2
mkdir -p /dbstorage/mongoconfig3

启动命令:

mongod --config config1.conf
mongod --config config2.conf
mongod --config config3.conf

配置文件

[root@localhost mongocluster]# cat config1.conf 
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongodconfig1.log

# Where and how to store data.
storage:
  dbPath: /dbstorage/mongoconfig1
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongodconfig1.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

sharding:
  clusterRole: configsvr
replication:
  replSetName: mc0
net:
  port: 27019
  bindIp: localhost,10.1.1.10

[root@localhost mongocluster]# cat config2.conf  
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongodconfig2.log

# Where and how to store data.
storage:
  dbPath: /dbstorage/mongoconfig2
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongodconfig2.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

sharding:
  clusterRole: configsvr
replication:
  replSetName: mc0
net:
  port: 27020
  bindIp: localhost,10.1.1.10

[root@localhost mongocluster]# cat config3.conf  
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongodconfig3.log

# Where and how to store data.
storage:
  dbPath: /dbstorage/mongoconfig3
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongodconfig3.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

sharding:
  clusterRole: configsvr
replication:
  replSetName: mc0
net:
  port: 27021
  bindIp: localhost,10.1.1.10

初始化replicaset

rs.initiate(
  {
    _id: "mc0",
    configsvr: true,
    members: [
      { _id : 0, host : "10.1.1.10:27019" },
      { _id : 1, host : "10.1.1.10:27020" },
      { _id : 2, host : "10.1.1.10:27021" }
    ]
  }
)

shard搭建

shard集群启动配置文件为3个组成replicaset

shard1.conf
shard2.conf
shard3.conf

创建目录

mkdir /dbstorage/mongoshard3
mkdir /dbstorage/mongoshard2
mkdir /dbstorage/mongoshard1

启动命令:

mongod --config shard1.conf
mongod --config shard2.conf
mongod --config shard3.conf

配置文件内容

[root@localhost mongocluster]# cat shard1.conf
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongodshard1.log

# Where and how to store data.
storage:
  dbPath: /dbstorage/mongoshard1
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongodshard1.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

sharding:
  clusterRole: shardsvr
replication:
  replSetName: s0
net:
  port: 27016
  bindIp: localhost,10.1.1.10

[root@localhost mongocluster]# cat shard2.conf
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongodshard2.log

# Where and how to store data.
storage:
  dbPath: /dbstorage/mongoshard2
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongodshard2.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

sharding:
  clusterRole: shardsvr
replication:
  replSetName: s0
net:
  port: 27017
  bindIp: localhost,10.1.1.10

[root@localhost mongocluster]# cat shard3.conf
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongodshard3.log

# Where and how to store data.
storage:
  dbPath: /dbstorage/mongoshard3
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongodshard3.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

sharding:
  clusterRole: shardsvr
replication:
  replSetName: s0
net:
  port: 27018
  bindIp: localhost,10.1.1.10

设置replicaset

rs.initiate(
  {
    _id : "s0",
    members: [
      { _id : 0, host : "10.1.1.10:27016" },
      { _id : 1, host : "10.1.1.10:27017" },
      { _id : 2, host : "10.1.1.10:27018" }
    ]
  }
)

mongos节点

mongos集群启动配置文件为1个节点

mongos1.conf

创建目录

mkdir /dbstorage/mongos1

启动命令:

mongos --config mongos1.conf

配置文件内容

[root@localhost mongocluster]# cat mongos1.conf 
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongodmongos1.log

# Where and how to store data.
#storage:
#  dbPath: /dbstorage/mongos1
#  journal:
#    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongodmongos1.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

sharding:
  configDB: mc0/10.1.1.10:27019,10.1.1.10:27020,10.1.1.10:27021
net:
  port: 3717
  bindIp: localhost,10.1.1.10

使用mongos连接mongo shard

mongo --host localhost --port 3717

将之前创建好的shard加入cluster,或者可以创建新的shard,加入集群

sh.addShard( "s0/10.1.1.10:27016,10.1.1.10:27017,10.1.1.10:27018")

查看状态

sh.status()

将一个数据库做sharding

sh.enableSharding("<database>")

对collection做sharding

sh.shardCollection("<database>.<collection>", { <shard key field> : "hashed" } )
sh.shardCollection("<database>.<collection>", { <shard key field> : 1, ... } )

附启动脚本,酌情修改

#!/bin/bash

/usr/bin/mongod --config /root/mongocluster/config1.conf
/usr/bin/mongod --config /root/mongocluster/config2.conf
/usr/bin/mongod --config /root/mongocluster/config3.conf
/usr/bin/mongod --config /root/mongocluster/shard1.conf
/usr/bin/mongod --config /root/mongocluster/shard2.conf
/usr/bin/mongod --config /root/mongocluster/shard3.conf
/usr/bin/mongos --config /root/mongocluster/mongos1.conf
  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-03-30 18:32:03  更:2022-03-30 18:36:03 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 6:04:45-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码