当前位置: 首页 > news >正文

《Linux运维总结:基于ARM64+X86_64架构CPU使用docker-compose一键离线部署mongodb 7.0.14容器版分片集群》

总结:整理不易,如果对你有帮助,可否点赞关注一下?

更多详细内容请参考:《Linux运维篇:Linux系统运维指南》


一、部署背景

由于业务系统的特殊性,我们需要面向不通的客户安装我们的业务系统,而作为基础组件中的mongodb针对不同的客户环境需要多次部署集群,作为一个运维工程师,提升工作效率也是工作中的重要一环。所以我觉得有必要针对 X86_64 + ARM64 CPU架构mongodb 7.0.14容器版 分片集群编写自动化部署工具。

CPU架构 docker版本 docker-compose版本
X86_64 26.1.3 v2.29.0
ARM64 26.1.3 v2.29.0

二、工具介绍

一键部署工具实现功能如下:

1、支持ARM64、X86_64架构CPU
2、支持单实例部署
3、支持单机伪分片集群部署(1个config副本集+2个分片副本集+3路由节点)
4、支持多机分布式分片集群部署(1个config副本集+2个分片副本集+3路由节点)
5、支持数据目录、日志目录、端口、账号、密码、副本集合名称、最大并发连接数等灵活配置
6、支持数据文件、日志文件、配置文件持久化
7、支持创建、启动、停止、卸载等操作
8、支持一键连接、一键备份、一键还原等操作

如下图所示:
在这里插入图片描述
在这里插入图片描述

说明:工具使用非常简单,只需要修改变量文件,就可以快速帮你快速部署mongodb 7.0.14分片集群。


三、工具下载

基于X86_64+ARM64架构CPU使用docker-compose一键离线部署mongodb 7.0.14容器版分片集群工具


四、部署步骤

说明:单机伪集群是指在单主机部署mongodb分片集群,分布式集群是指在多个不同主机上部署mongodb分片集群,这里部署的是多机分布式分片集群。


1、查看帮助命令
在这里插入图片描述


2、部署规划

说明:这里由于资源限制,使用4台服务器部署分片集群。如果你的资源充足,建议每个实例使用单独1台服务器部署。

宿主机IP 操作系统 内核版本 节点说明
192.168.1.111 操作系统 5.15.0-113-generic 配置服务副本集(1primary+2secondary,共3个实例)
192.168.1.112 操作系统 5.15.0-113-generic 分片1副本集(1primary+1secondary+1arbiter,共3个实例)
192.168.1.113 操作系统 5.15.0-113-generic 分片2副本集(1primary+1secondary+1arbiter,共3个实例)
192.168.1.114 操作系统 5.15.0-113-generic 路由节点(3个mongos实例)

3、准备一键部署工具包

说明:将一键部署工具包分别上传到mongodb分片集群所有节点上。


4、编辑变量文件

说明:以下操作分别在mongodb分片集群节点的部署工具包中修改cluster.conf文件, 三个节点上cluster.conf文件内容一致

root@localhost:/opt/mongodb-shard-cluster# cp cluster.conf.tpl cluster.conf
root@localhost:/opt/mongodb-shard-cluster# vim cluster.conf
# 部署顺序: 
#   1、配置节点 > 分片节点1 > 分片节点2 > 路由节点
#   2、配置节点顺序为secondary2>secondary1>primary,分片节点顺序为arbiter>secondary>primary,路由节点顺序为route1>route2>route3
# 建议填写为当前磁盘最大存储空间目录,如果系统盘空间最大,建议填写为/data,如果挂在盘空间最大,建议填写为挂载目录
export BASE_DIR="/data"# cpu架构,可选值为<x86_64和aarch64>,根据实际情况修改
export CPU_PLATFROM="x86_64"# mongodb版本,默认不修改
export MONGODB_VERSION="7.0.14"# Mongodb数据存放根目录,默认即可,建议不要修改
export MONGODB_DATA_DIR="${BASE_DIR}/basic-data/mongodb-shard-cluster"
##################################################################################################################
# 注意:容器网络模式为<host主机网络模式>,监听地址填写为宿主机内网地址,<主机名为容器的主机名,非宿主机主机名>
# mongodb<配置服务>副本集信息
export MONGODB_CONFIG_PRIMARY_HOST_IP="192.168.1.111"                     # primary实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_CONFIG_PRIMARY_HOST_NAME="config-primary.mongo.com"        # primary实例主机名,可根据实际情况修改
export MONGODB_CONFIG_PRIMARY_HOST_PORT="17101"                           # primary实例映射宿主机端口,端口不冲突情况下,建议不修改export MONGODB_CONFIG_SECONDARY1_HOST_IP="192.168.1.111"                  # secondary1实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_CONFIG_SECONDARY1_HOST_NAME="config-secondary1.mongo.com"  # secondary1实例主机名,可根据实际情况修改
export MONGODB_CONFIG_SECONDARY1_HOST_PORT="17102"                        # secondary1实例映射宿主机端口,端口不冲突情况下,建议不修改export MONGODB_CONFIG_SECONDARY2_HOST_IP="192.168.1.111"                  # secondary2实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_CONFIG_SECONDARY2_HOST_NAME="config-secondary2.mongo.com"  # secondary2实例主机名,可根据实际情况修改
export MONGODB_CONFIG_SECONDARY2_HOST_PORT="17103"                        # secondary2实例映射宿主机端口,端口不冲突情况下,建议不修改
export MONGODB_CONFIG_REPLICASET_NAME="config-rs"                         # config服务副本集合名称,默认即可,建议不修改# mongodb<分片1>副本集信息
export MONGODB_SHARD1_PRIMARY_HOST_IP="192.168.1.112"                     # primary实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_SHARD1_PRIMARY_HOST_NAME="shard1-primary.mongo.com"        # primary实例主机名,可根据实际情况修改
export MONGODB_SHARD1_PRIMARY_HOST_PORT="17201"                           # primary实例映射宿主机端口,端口不冲突情况下,建议不修改export MONGODB_SHARD1_SECONDARY_HOST_IP="192.168.1.112"                   # secondary实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_SHARD1_SECONDARY_HOST_NAME="shard1-secondary.mongo.com"    # secondary实例主机名,可根据实际情况修改
export MONGODB_SHARD1_SECONDARY_HOST_PORT="17202"                         # secondary实例映射宿主机端口,端口不冲突情况下,建议不修改export MONGODB_SHARD1_ARBITER_HOST_IP="192.168.1.112"                     # arbiter实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_SHARD1_ARBITER_HOST_NAME="shard1-arbiter.mongo.com"        # arbiter实例主机名,可根据实际情况修改
export MONGODB_SHARD1_ARBITER_HOST_PORT="17203"                           # arbiter实例映射宿主机端口,端口不冲突情况下,建议不修改
export MONGODB_SHARD1_REPLICASET_NAME="shard1-rs"                         # 分片1副本集合名称,默认即可,建议不修改# mongodb<分片2>副本集信息
export MONGODB_SHARD2_PRIMARY_HOST_IP="192.168.1.113"                     # primary实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_SHARD2_PRIMARY_HOST_NAME="shard2-primary.mongo.com"        # primary实例主机名,可根据实际情况修改
export MONGODB_SHARD2_PRIMARY_HOST_PORT="17301"                           # primary实例映射宿主机端口,端口不冲突情况下,建议不修改export MONGODB_SHARD2_SECONDARY_HOST_IP="192.168.1.113"                   # secondary实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_SHARD2_SECONDARY_HOST_NAME="shard2-secondary.mongo.com"    # secondary实例主机名,可根据实际情况修改
export MONGODB_SHARD2_SECONDARY_HOST_PORT="17302"                         # secondary实例映射宿主机端口,端口不冲突情况下,建议不修改export MONGODB_SHARD2_ARBITER_HOST_IP="192.168.1.113"                     # arbiter实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGODB_SHARD2_ARBITER_HOST_NAME="shard2-arbiter.mongo.com"        # arbiter实例主机名,可根据实际情况修改
export MONGODB_SHARD2_ARBITER_HOST_PORT="17303"                           # arbiter实例映射宿主机端口,端口不冲突情况下,建议不修改
export MONGODB_SHARD2_REPLICASET_NAME="shard2-rs"                         # 分片2副本集合名称,默认即可,建议不修改# mongods<路由实例>信息
export MONGOS_ROUTE1_HOST_IP="192.168.1.114"                              # mongos1实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGOS_ROUTE1_HOST_NAME="route1.mongo.com"                         # mongos1实例主机名,可根据实际情况修改
export MONGOS_ROUTE1_HOST_PORT="17401"                                    # mongos1实例映射宿主机端口,端口不冲突情况下,建议不修改export MONGOS_ROUTE2_HOST_IP="192.168.1.114"                              # mongos2实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGOS_ROUTE2_HOST_NAME="route2.mongo.com"                         # mongos2实例主机名,可根据实际情况修改
export MONGOS_ROUTE2_HOST_PORT="17402"                                    # mongos2实例映射宿主机端口,端口不冲突情况下,建议不修改export MONGOS_ROUTE3_HOST_IP="192.168.1.114"                              # mongos3实例监听地址,建议填写<宿主机内网地址>,根据实际情况填写
export MONGOS_ROUTE3_HOST_NAME="route3.mongo.com"                         # mongos3实例主机名,可根据实际情况修改
export MONGOS_ROUTE3_HOST_PORT="17403"                                    # mongos3实例映射宿主机端口,端口不冲突情况下,建议不修改# mongos或mongod接受的最大并行连接数,如果该设置高于操作系统配置<文件描述符,ulimit -n>的最大连接跟踪阈值,则该设置无效 
export MONGODB_MAX_CONNECTIONS="10000"# Mongodb分片集群<admin库+管理账号+密码>,密码要求大小写和数字,且8位以上,根据实际情况填写
# 注意:<分片集群用户admin库管理账号密码>与<本地分片admin库用户管理账号和密码>相同,均使用MONGODB_ADMIN_USER和MONGODB_ADMIN_PASSWORD变量
export MONGODB_ADMIN_USER="admin"          
export MONGODB_ADMIN_PASSWORD="Kzyh9nwyDWuL"# Mongodb分片集群<读写库+用户账号+密码>,密码要求大小写和数字,且8位以上,根据实际情况填写
# 注意:<分片集群读写库用户管理账号密码>与<本地分片读写库用户管理账号和密码>相同,均使用MONGODB_ADMIN_USER和MONGODB_ADMIN_PASSWORD变量
export MONGODB_READWRITE_DATABASE="lolaage"
export MONGODB_READWRITE_USER="lolaage"
export MONGODB_READWRITE_PASSWORD="Kzyh9nwyDWuL"
##################################################################################################################

5、执行部署

说明:部署顺序必须为
1、配置节点 > 分片节点1 > 分片节点2 > 路由节点
2、配置节点顺序为secondary2>secondary1>primary,分片节点顺序为arbiter>secondary>primary,路由节点顺序为route1>route2>route3


a、配置服务副本集部署(192.168.1.111)

root@localhost:/opt/mongodb-shard-cluster# ./op.sh build config-secondary2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh build config-secondary1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh build config-primary

如下图所示:
在这里插入图片描述


b、分片1副本集部署(192.168.1.112)

root@localhost:/opt/mongodb-shard-cluster# ./op.sh build shard1-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh build shard1-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh build shard1-primary

如下图所示:
在这里插入图片描述


c、分片2副本集部署(192.168.1.113)

root@localhost:/opt/mongodb-shard-cluster# ./op.sh build shard2-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh build shard2-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh build shard2-primary

如下图所示:
在这里插入图片描述


d、路由节点部署(192.168.1.114)

root@localhost:/opt/mongodb-shard-cluster# ./op.sh build route1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh build route2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh build route3

如下图所示:
在这里插入图片描述


6、检查集群状态

root@localhost:/opt/mongodb-shard-cluster# ./op.sh check route3

如下图所示:
在这里插入图片描述


五、其它操作

5.1、启动

说明:分别在对应主机节点上执行。

root@localhost:/opt/mongodb-shard-cluster# ./op.sh start config-secondary2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh start config-secondary1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh start config-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh start shard1-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh start shard1-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh start shard1-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh start shard2-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh start shard2-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh start shard2-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh start route1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh start route2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh start route3

5.2、停止

说明:分别在对应主机节点上执行。

root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop config-secondary2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop config-secondary1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop config-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh stop shard1-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop shard1-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop shard1-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh stop shard2-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop shard2-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop shard2-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh stop route1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop route2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh stop route3

5.3、检查

说明:分别在对应主机节点上执行。

root@localhost:/opt/mongodb-shard-cluster# ./op.sh check config-secondary2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh check config-secondary1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh check config-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh check shard1-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh check shard1-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh check shard1-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh check shard2-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh check shard2-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh check shard2-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh check route1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh check route2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh check route3

5.4、卸载

说明:分别在对应主机节点上执行。

root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear config-secondary2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear config-secondary1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear config-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh clear shard1-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear shard1-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear shard1-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh clear shard2-arbiter
root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear shard2-secondary
root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear shard2-primaryroot@localhost:/opt/mongodb-shard-cluster# ./op.sh clear route1
root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear route2
root@localhost:/opt/mongodb-shard-cluster# ./op.sh clear route3

5.5、连接

说明:分别在对应主机节点上执行。

root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect config-secondary2
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect config-secondary1
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect config-primaryroot@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect shard1-arbiter
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect shard1-secondary
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect shard1-primaryroot@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect shard2-arbiter
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect shard2-secondary
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect shard2-primaryroot@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect route1
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect route2
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_connect.sh connect route3

5.6、备份(支持单机和分片集群模式)

说明:在route3节点上执行。

root@localhost:/opt/mongodb-shard-cluster# cd tools
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_backup.sh backup route3

注意:如果你想手动备份还原,建议参考《Linux运维总结:使用 MongoDB工具备份和恢复mongodb 7.0.14分片集群(方案一)》。


5.7、还原(仅支持单机模式)

root@localhost:/opt/mongodb-shard-cluster# cd tools
root@localhost:/opt/mongodb-shard-cluster/tools# ./auto_backup.sh backup single

注意:由于分片集群还原操作,比较复杂,建议参考《Linux运维总结:使用 MongoDB工具备份和恢复mongodb 7.0.14分片集群(方案一)》。


总结:整理不易,如果对你有帮助,可否点赞关注一下?

更多详细内容请参考:《Linux运维篇:Linux系统运维指南》

http://www.lryc.cn/news/459369.html

相关文章:

  • Java利用ChromeDriver插件网页截图(Wondows版+Linux版)
  • 无人机之交互系统篇
  • MarsCode--找出数字比例超过n/2的【简单】
  • Python网络爬虫快速入门指南
  • C86 架构一键离线安装 docker 和 docker-compose 实战指南
  • 【LwIP源码学习2】调试输出相关宏
  • Python 列表专题:删除元素
  • Spring Boot 快速入门与核心原理详解
  • UniApp 与微信小程序详细对比
  • 【用大模型提示工程处理NLP任务】
  • 适配器模式、代理模式(C++)
  • unity 2d 近战攻击判定的三种方式以及精确获取碰撞点
  • 矩形函数的傅里叶变换——从一维到二维,从连续到离散
  • 潜水打捞系统助力,破解汽车打捞难题
  • 【深度学习】经典的深度学习模型-01 开山之作:CNN卷积神经网络LeNet-5
  • LeetCode 每日一题 2024/10/7-2024/10/13
  • ZYNQ使用XGPIO驱动外设模块(前半部分)
  • 【FastAdmin】全栈视角下的页面跳转实现:从原生html、javascrpt、php技术到jQuery、FastAdmin框架
  • 从零开始搭建一个node.js后端服务项目
  • 自定义注解和组件扫描在Spring Boot中动态注册Bean(一)
  • 如何在 IDEA 中导入 Java 项目的 Git 仓库并启动
  • BIO与NIO学习
  • 麒麟操作系统:解决umount命令卸载USB存储设备时报“device is busy”错误
  • Git客户端使用之TortoiseGit和Git
  • regionprops函数详解及应用
  • FPAG学习(5)-三种方法实现LED流水灯
  • 科迅网络阅卷系统存在存储型XSS漏洞
  • 【AAOS】Android Automotive 11模拟器源码下载及编译
  • 鹏哥C语言74---第12次作业:OJ题练习
  • Light灯光组件+组件的相关操作+游戏资源的加载