在Debian上搭建MongoDB集群可以通过多种方式实现,包括副本集集群和分片集群。以下是详细的步骤和方法:
/etc/mongod.conf
),配置副本集信息。mongosh
命令初始化副本集。例如:mongosh --host <主节点IP>:27018
rs.initiate(
{
_id: "replication-cluster",
members: [
{ _id: 0, host: "<主节点IP>:27018", priority: 2 },
{ _id: 1, host: "<副本节点IP>:27019", priority: 1 },
{ _id: 2, host: "<仲裁节点IP>:27020", arbiterOnly: true }
]
}
)
rs.status()
命令查看副本集状态,确保所有成员正常运行。mongosh
命令初始化配置服务器副本集。例如:mongosh --host <配置服务器IP>:27017
rs.initiate(
{
_id: "configReplSet",
configsvr: true,
members: [
{ _id: 0, host: "<配置服务器IP>:27017" },
{ _id: 1, host: "<另一个配置服务器IP>:27017" },
{ _id: 2, host: "<第三个配置服务器IP>:27017" }
]
}
)
sh.addShard()
命令添加分片到集群。例如:sh.addShard("<分片服务器IP>:40001")
sh.addShard("<分片服务器IP>:40002")
sh.addShard("<分片服务器IP>:40003")
mongosh --configdb <配置服务器IP>:27017,<另一个配置服务器IP>:27017,<第三个配置服务器IP>:27017 --port 30000
sh.status()
命令查看分片集群状态,确保所有分片和配置服务器正常运行。以上步骤提供了在Debian上搭建MongoDB副本集集群和分片集群的基本流程。根据实际需求,您可能需要进一步调整和优化配置。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>