在CentOS上搭建MongoDB集群涉及多个步骤,包括安装、配置、初始化等。以下是详细的步骤指南:
storage.dbPath、systemLog.path、net.port、security.keyFile、replication.replSetName、security.authorization等。mongod --config /path/to/mongod.conf 。rs.initiate() 命令来初始化副本集,定义副本集名称和成员信息。rs.add("hostname:port") 。mongo --host <shard-server1>:27017 rs.initiate({_id: "rs0", members: [{_id: 0, host: "<shard-server1>:27017"}, {_id: 1, host: "<shard-server2>:27017"}, {_id: 2, host: "<shard-server3>:27017"}]}) 命令初始化一个副本集。mongo --host <mongos>:27017 sh.enableSharding("<database>") ,选择合适的分片键 sh.shardCollection("<database>.<collection>", {<field>: 1}) 。mongo --host <config-server1>:27017 rs.initiate({_id: "cfgReplSet", configsvr: true, members: [{_id: 0, host: "<config-server1>:27017"}, {_id: 1, host: "<config-server2>:27017"}, {_id: 2, host: "<config-server3>:27017"}]}) 命令初始化一个副本集。mongo --host <mongos>:27017 sh.addShard("<shard-server1>:<port>,<shard-server2>:<port>,<shard-server3>:<port>") 命令添加分片服务器,使用 sh.addConfigServer("<config-server1>:<port>,<config-server2>:<port>,<config-server3>:<port>") 命令添加配置服务器,使用 sh.enableSharding("<database>") 命令启用分片,使用 sh.shardCollection("<database>.<collection>", {<field>: 1}) 命令配置分片键。mongo --host <mongos>:27017 sh.status() 命令检查分片状态。mongo --host <mongos>:27017 sh.status("configsvr") 命令检查配置服务器状态。以上步骤可以帮助您在CentOS上成功搭建一个MongoDB集群。请根据您的具体环境和需求进行调整。