以下是在Ubuntu上配置MongoDB集群的步骤:
sudo apt update,sudo apt install -y mongodb-org。/etc/mongod.conf,添加replication: replSetName: "rs0"(rs0为副本集名称,可自定义)。sudo systemctl restart mongod。mongo命令连接数据库,执行rs.initiate(),再添加其他节点rs.add("节点IP:27017")。mongo shell中执行rs.status()查看副本集状态。sharding.clusterRole: configsvr等参数,启动服务并初始化副本集。sharding.clusterRole: shardsvr等参数,启动服务并初始化副本集。sharding.configdb为配置服务器副本集地址,启动mongos。mongos,使用sh.addShard()添加分片。