§2023-08-07
A mongos is the MongoDB Shard Router, responsible for routing client requests to the appropriate shards within a sharded cluster. It is not part of the MongoDB replica set architecture. You do not run it as a replicationSet.
You can run multiple mongos instances on separate server machines, and clients can choose which mongos instance to connect to. Each mongos instance acts as a shard router and handles client requests, directing them to the appropriate shard within the sharded cluster.
¶1. Setup orgpi5Arch.yushei.net:27991, as first mongos server
- /etc/mongos-27991.conf
# mongos-27991.conf
# mongos server
# for documentation of all options, see:
# https://www.mongodb.com/docs/manual/reference/program/mongos/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /opt/xfs/mongodb/log/mongos-27991.log
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27991
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/orgpi5arch.yushei.net.pem
CAFile: /opt/xfs/mongodb/x.509/mongoCA.crt
# security:
# authorization: enabled
# keyFile: /opt/xfs/mongodb/x.509/MuneTakaHomeKey # for replicaSet
# clusterAuthMode: x509
#operationProfiling:
# sharding:
# configDB: <configReplSetName>/cfg1.example.net:27019, cfg2.example.net:27019,..
sharding:
configDB: configServer/n2Mnjaro.yushei.net:27997,hc4Lunar.yushei.net:27997,orgpi5Jammy.yushei.net:27997
## Enterprise-Only Options
#auditLog:
#snmp:
¶ 2. /etc/systemd/system/Mongos-27991.service
[Unit]
Description=Mongos Server, port 27991,
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target
[Service]
TimeoutStartSec=infinity
User=mongodb
Group=mongodb
Environment="OPTIONS=-f /etc/mongos-27991.conf"
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
ExecStart=/usr/local/bin/mongos $OPTIONS
RuntimeDirectory=mongodb
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
[Install]
WantedBy=multi-user.target