ยง2023-08-08
In leraning how to use MongoDB sharding, I did created three Config Server and Two Shards as ShardA abd ShardB as follows:
- replication.replSetName: "ConfigServer", sharding.clusterRole: "configsvr"
ConfigServer [primary] admin> rs.status().members.forEach(member => print(member.name))
orgpi5jammy.yushei.net:27997
n2mnjaro.yushei.net:27997
hc4lunar.yushei.net:27997
- replication.replSetName: "ShardA", sharding.clusterRole: "shardsvr"
ConfigServer [primary] admin> rs.status().members.forEach(member => print(member.name))
orgpi5jammy.yushei.net:27997
n2mnjaro.yushei.net:27997
hc4lunar.yushei.net:27997
ShardA [primary] admin> rs.status().members.forEach(member => print(member.name))
n2Mnjaro-01.yushei.net:27995
hc4Bookworm.yushei.net:27995
hc4Lunar.yushei.net:27995
- replication.replSetName: "ShardB", sharding.clusterRole: "shardsvr"
ShardB [direct: secondary] admin> db.auth("siteRootAdmin", "b23258585")
{ ok: 1 }
ShardB [direct: secondary] admin> rs.status().members.forEach(member => print(member.name))
n2Mnjaro-01.yushei.net:27993
hc4Bookworm.yushei.net:27993
hc4Lunar.yushei.net:27993
The above /etc/mongodb-*.conf are
net:
port: 27997
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
tls:
mode: requireTLS
certificateKeyFile: /opt/xfs/mongodb/x.509/hc4lunar.yushei.net.pem
CAFile: /opt/xfs/mongodb/x.509/mongoCA.crt
They are requireTLS. The turorial on how to use mongos is few, not to mention using TLS. So I decided to take TLS out and no security.