MongoDB集群分片安装部署手册

一、集群规划

1.1 集群安装规划

在这里插入图片描述

1.2 端口规划

mongos:20000
config:21000
shard1:27001
shard2:27002
shard3:27003

1.3 目录创建

数据目录:
/mongodb/data/config
/mongodb/data/shard1
/mongodb/data/shard2
/mongodb/data/shard3
日志目录:
/mongodb/logs/mongos
/mongodb/logs/config
/mongodb/logs/shard1
/mongodb/logs/shard2
/mongodb/logs/shard3
配置目录:
/usr/local/mongodb/conf
/usr/local/mongodb/server

二、mongodb安装(三台均需要操作)

2.1 下载、解压

https://www.mongodb.com/try/download/community-edition/releases/archive

cd /usr/local/
tar -zxvf mongodb-linux-x86_64-rhel70-4.0.26.tgz

2.2 配置环境变量

vim /etc/profile

#mongodb path
export MONGODB_HOME=/usr/local/mongodb
export PATH=$MONGODB_HOME/bin:$PATH

source /etc/profile

三、mongodb组件配置

3.1 配置config server的副本集

3.1.1 config配置文件

vim /usr/local/mongodb/conf/config.conf

## content
systemLog:
  destination: file
  logAppend: true
  path: /mongodb/logs/config.log

# Where and how to store data.
storage:
  dbPath: /mongodb/data/config
  journal:
    enabled: true

# how the process runs
processManagement:
  fork: true
  pidFilePath: /mongodb/logs/config/configsrv.pid

# network interfaces
net:
  port: 21000
  bindIp: 0.0.0.0

#operationProfiling:
replication:
  replSetName: config        
sharding:
  clusterRole: configsvr
3.1.2 config server启动

/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/config.conf &

3.1.3 初始化config

只需要在一台主机上执行

mongo 10.10.3.134:21000

config = {
   
   _id : "config",members : [{
   
   _id : 0, host : "10.10.3.134:21000" },{
   
   _id : 1, host : "10.10.3.135:21000" },{
   
   _id : 2, host : "10.10.3.136:21000" }]}

rs.initiate(config)

在这里插入图片描述
需要关闭防火墙,selinux

3.2 配置shard1 server的副本集

3.2.1 shard1配置文件

vim /usr/local/mongodb/conf/shard1.conf

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /mongodb/logs/shard1/shard1.log

# Where and how to store data.
storage:
  dbPath: /mongodb/data/shard1
  journal:
    enabled: true
  wiredTiger:
    engineConfig:
       cacheSizeGB: 1

# how the process runs
processManagement:
  fork: true
  pidFilePath: /mongodb/logs/shard1/shard1.pid

# network interfaces
net:
  port: 27001
  bindIp: 0.0.0.0

#operationProfiling:
replication:
  replSetName: shard1
sharding:
  clusterRole: shardsvr

同步配置文件

scp /usr/local/m
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值