以下是在Ubuntu上搭建MongoDB集群的步骤:
sudo apt update,sudo apt install -y mongodb-org。/etc/mongod.conf,设置replication.replSetName为副本集名称,如rs0,并设置bindIp为0.0.0.0以允许所有IP访问。sudo systemctl start mongod和sudo systemctl enable mongod。mongo进入shell,执行rs.initiate(),再执行rs.add("其他节点IP:27017")添加其他节点。rs.status(),查看节点状态。/etc/mongod-config.conf,设置storage.dbPath、net.port等,设置replication.replSetName为配置服务器副本集名称,启动服务并初始化副本集。/etc/mongos.conf,设置sharding.configdb为配置服务器副本集名称和地址,启动mongos。mongos,执行sh.addShard("分片副本集名称/分片主节点IP:端口")。mongos上执行sh.status()查看集群状态。