MongoDB分片集群部署详解


本文整理自网络,侵删。

 一、环境说明

1、我们prod环境MongoDB的集群架构是做的分片集群的部署,但是目前我们没有分片,即所有数据都在一个分片上,后期如果数量大,需要分配,集群随时可以分片,对业务方透明

2、各个角色的部署情况

角色 IP 端口 复制集名称
mongos 172.21.244.101,172.21.244.102,172.21.244.94 27000
config server 172.21.244.101,172.21.244.102,172.21.244.94 27100 repl_configsvr
存储节点(shard) 172.21.244.101,172.21.244.102,172.21.244.94 27101 shard1

3、MongoDB版本

mongos> db.version()
4.0.4-62-g7e345a7

二、基础信息准备

0、系统优化

echo "never" >/sys/kernel/mm/transparent_hugepage/enabled
echo "never" >/sys/kernel/mm/transparent_hugepage/defrag

1、下载MongoDB二进制文件

cd /chj/app
wget ops.chehejia.com:9090/pkg/chj_mongodb_4.0.4.tar.gz
tar -zxvf chj_mongodb_4.0.4.tar.gz

2、相关目录建立

#建立base目录
mkdir /chj/data/mongodb/chj_db
#把MongoDB二进制文件移动到base目录下的bin文件夹
mv chj_mongodb_4.0.4/bin /chj/data/mongodb/chj_db/bin
#建立认证文件目录
mkdir /chj/data/mongodb/chj_db/auth
#建立配置文件目录
mkdir /chj/data/mongodb/chj_db/conf
#建立config server的data和日志目录
mkdir /chj/data/mongodb/chj_db/config/data -p
mkdir /chj/data/mongodb/chj_db/config/log
#建立mongos的日志目录
mkdir /chj/data/mongodb/chj_db/mongos/log -p
#建立数据节点data和日志目录 
mkdir /chj/data/mongodb/chj_db/shard1/data -p
mkdir /chj/data/mongodb/chj_db/shard1/log

3、相关配置文件编写

A、mongos的配置文件编写

vim /chj/data/mongodb/chj_db/conf/mongos.conf
systemLog:
 destination: file
 logAppend: true
 path: /chj/data/mongodb/chj_db/mongos/log/mongos.log

processManagement:
 fork: true # fork and run in background
 pidFilePath: /chj/data/mongodb/chj_db/mongos/log/mongos.pid # location of pidfile
 timeZoneInfo: /usr/share/zoneinfo

net:
 port: 27000
 bindIpAll: true
 maxIncomingConnections: 1000
 unixDomainSocket:
  enabled: true
  pathPrefix: /chj/data/mongodb/chj_db/mongos/log
  filePermissions: 0700

security:
 keyFile: /chj/data/mongodb/chj_db/auth/keyfile.key
# authorization: enabled

#replication:

sharding:
 configDB: repl_configsvr/172.21.244.101:27100,172.21.244.102:27100,172.21.244.94:27100

B、config server的配置文件编写

vim /chj/data/mongodb/chj_db/conf/config.conf
systemLog:
 destination: file
 logAppend: true
 path: /chj/data/mongodb/chj_db/config/log/congigsrv.log

storage:
 dbPath: /chj/data/mongodb/chj_db/config/data
 journal:
  enabled: true
 wiredTiger:
  engineConfig:
   directoryForIndexes: true

processManagement:
 fork: true # fork and run in background
 pidFilePath: /chj/data/mongodb/chj_db/config/log/configsrv.pid # location of pidfile
 timeZoneInfo: /usr/share/zoneinfo

net:
 port: 27100
 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
 #bindIpAll: true
 maxIncomingConnections: 1000
 unixDomainSocket:
  enabled: true
  pathPrefix: /chj/data/mongodb/chj_db/config/data
  filePermissions: 0700

security:
 keyFile: /chj/data/mongodb/chj_db/auth/keyfile.key
 authorization: enabled

replication:
 replSetName: repl_configsvr
sharding:
 clusterRole: configsvr

C、存储节点的配置文件编写

vim /chj/data/mongodb/chj_db/conf/shard1.conf
systemLog:
 destination: file
 logAppend: true
 path: /chj/data/mongodb/chj_db/shard1/log/shard1.log

storage:
 dbPath: /chj/data/mongodb/chj_db/shard1/data
 journal:
  enabled: true
 wiredTiger:
  engineConfig:
   directoryForIndexes: true

processManagement:
 fork: true # fork and run in background
 pidFilePath: /chj/data/mongodb/chj_db/shard1/log/shard1.pid # location of pidfile
 timeZoneInfo: /usr/share/zoneinfo

net:
 port: 27101
 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
 #bindIpAll: true
 maxIncomingConnections: 1000
 unixDomainSocket:
  enabled: true
  pathPrefix: /chj/data/mongodb/chj_db/shard1/data
  filePermissions: 0700

security:
 keyFile: /chj/data/mongodb/chj_db/auth/keyfile.key
 authorization: enabled

replication:
 replSetName: shard1
sharding:
 clusterRole: shardsvr

4、生产key认证文件

echo "chj123456" >/chj/data/mongodb/chj_db/auth/keyfile.key
#设置文件的权限为400,不然服务无法启动
chmod 400 /chj/data/mongodb/chj_db/auth/keyfile.key

三、集群初始化

阅读剩余部分

相关阅读 >>

mongodb入门教程(包含安装、常用命令、相关概念、使用技巧、常见操作等)

mongodb数据更新方法干货篇

centos系统搭建mongodb数据库

mongodb 用户管理

mongodb集合中的文档管理

mongodblinux下集群搭建过程

关于单台mongodb实例开启oplog的过程详解

mongodb最大连接数设置失效的异常分析过程与解决方法

分析mongodb和mysql各自的关键特性、差别和优势

mongodb入门教程之常用的运维技术介绍

更多相关阅读请进入《mongodb》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...