§2023-07-30
- This is a two nodes only
configsrv
in a sharding.
Machine | IP | OS | mongod/mongos Version | Replication Set | momgosh Avialbale | configsvr/replSetName |
---|---|---|---|---|---|---|
n2Mnjaro.yushei.net | 192.168.48.245 | odroid-n2+, ManJaro | 7.0.0-rc8 | N/A | 1.10.1 no ssl | 27997, "configServer" |
hc4Lunar.yushei.net | 192.168.48.243 | Odroid-hc4 Ubuntu Jammy | 7.0.0-rc8 | N/A | 1.10.1 no ssl | 27997. "configServer" |
orpi5jammy.yushei.net | 192.168.48.247 | orgPi5 Ubuntu Jammy | 7.0.0-rc8 | N/A | 1.10.1 no ssl | 27997, "configServer" |
¶ First Node, n2Mnhjaro.yushei.net
[alexlai@n2Mnjaro ~]$ lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
└─sda1 xfs f8b1179e-372a-4aad-9695-41c7254247da 374.8G 60% /opt/sda1
mmcblk1
├─mmcblk1p1 vfat FAT16 BOOT_MNJRO 9F53-C1AE 400.5M 12% /boot
├─mmcblk1p2 ext4 1.0 ROOT_MNJRO f278e95a-9fe9-4864-b3a6-11245b333dab 57.7G 3% /
├─mmcblk1p3 swap 1 7e3a15b5-d99e-47ae-83af-b407b5e869d2 [SWAP]
└─mmcblk1p4 xfs ff9f8bb4-398b-4141-967c-796d2a7242a8 7G 84% /opt/xfs
mmcblk1boot0
mmcblk1boot1
zram0 [SWAP]
¶ Setup mongodb user and related directories
# useradd -u 966 -d /var/lib/mongodb -s /usr/bin/nologin mongodb
useradd warning: mongodb's uid 966 outside of the UID_MIN 1000 and UID_MAX 60000 range.
[root@n2Mnjaro sda1]# id mongodb
uid=966(mongodb) gid=1027(mongodb) groups=1027(mongodb)
# groupmod -g 966 mongodb
# id mongodb
uid=966(mongodb) gid=966(mongodb) groups=966(mongodb)
$ ls -l /var/lib/mongodb --> why it is not created ??
ls: cannot access '/var/lib/mongodb': No such file or directory
$ sudo mkdir /var/lib/mongodb
$ sudo chown mongodb:mongodb -R /var/lib/mongodb/
¶ /etc/mongodb-27997.conf
# mongodb-27997.conf configsrc
# replicationSet: ConfigServer
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /opt/xfs/mongodb/log/mongod-27997.log
# Where and how to store data.
storage:
dbPath: /opt/xfs/mongodb/data-27997/
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
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/n2mnjaro.yushei.net.pem
CAFile: /opt/xfs/mongodb/x.509/mongoCA.crt
security:
authorization: enabled
keyFile: /opt/xfs/mongodb/x.509/MuneTakaHomeKey
# clusterAuthMode: x509
#operationProfiling:
replication:
replSetName: "ConfigServer"
sharding:
clusterRole: "configsvr"
## Enterprise-Only Options
#auditLog:
#snmp:
- /etc/systemd/system/Mongodb-27997.service
[Unit]
Description=MongoDB Config Server, port 27997, ConfigServer
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/mongodb-27997.conf"
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
ExecStart=/usr/local/bin/mongod $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
Cannot start a configsvr as a standalone server. Please use the option --replSet to start the node as a replica set.
[root@n2Mnjaro sda1]# mkidr -p mongodb/data/data-27997
bash: mkidr: command not found
[root@n2Mnjaro sda1]# mkdir -p mongodb/data/data-27997
[root@n2Mnjaro sda1]# mkdir -p mongodb/log
[root@n2Mnjaro sda1]# pwd
/opt/sda1
[root@n2Mnjaro sda1]# chown -R mongodb:mongodb /opt/sda1/mongodb/
[root@n2Mnjaro sda1]# tree /opt/sda1/mongodb/
/opt/sda1/mongodb/
├── data
│ └── data-27997
└── log
4 directories, 0 files
¶ /etc/systemd/system/Mongodb-27997.service
[Unit]
Description=MongoDB Database Server
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/mongodb-27997.conf"
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
ExecStart=/usr/local/bin/mongod $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
rs.initiate( {
_id : "ConfigServer",
members: [
{ _id: 0, host: "orgpi5jammy.yushei.net:27997" },
{ _id: 1, host: "n2mnjaro.yushei.net:27997" },
{ _id: 2, host: "hc4lunar.yushei.net:27997" }
]
});
rs.initiate( { _id: "myReplSet", version: 1, members: [ { _id: 0, host : "mongodb0.example.net:27017" }, { _id: 1, host : "mongodb1.example.net:27017" }, { _id: 2, host : "mongodb2.example.net:27017" } ] } )
```alexlai@orgpi5Jammy:~$ ~/scripts/startMongosh-27997.sh
Current Mongosh Log ID: 64cf5ae4c554f5dfcf380554
Connecting to: mongodb://orgpi5jammy.yushei.net:27997/?tls=true&tlsCertificateKeyFile=%2Fopt%2Fxfs%2Fmongodb%2Fx.509%2Forgpi5jammy.yushei.net.pem&tlsCAFile=%2Fopt%2Fxfs%2Fmongodb%2Fx.509%2FmongoCA.crt&directConnection=true&appName=mongosh+1.10.1
Using MongoDB: 7.0.0-rc8
Using Mongosh: 1.10.1
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2023-08-06T15:49:25.370+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------
test> rs.initiate( {
... _id : "ConfigServer",
... members: [
... { _id: 0, host: "orgpi5jammy.yushei.net:27997" },
... { _id: 1, host: "n2mnjaro.yushei.net:27997" },
... { _id: 2, host: "hc4lunar.yushei.net:27997" }
... ]
... });
{ ok: 1 }
ConfigServer [direct: other] test>
- after rs.init(), then turn on the Access Control
- hc4Jammy.yushei.net |
alexlai@hc4Jammy:~$ lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 ext4 1.0 ce8221cc-e647-429c-9b3e-83eb002ade2f 391.6M 6% /boot
├─sda2 swap 1 26056ef1-58cf-4146-aca0-8c9a50dc5170 [SWAP]
└─sda3 xfs 8ea38ffd-50aa-4b2d-b0e3-8562bc12bda0 179.6G 17% /
alexlai@hc4Jammy:~$ grep mongodb /etc/passwd
mongodb:x:966:966::/var/lib/mongodb:/usr/bin/nologin
¶/etc/mongodb-27997.conf
# mongodb-27997.conf
# replSetName: "ShardingMuneTakaHome"
# MuneTakaHome replicationSet
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true # false
path: /opt/mongodb/log/mongod-27997.log
# Where and how to store data.
storage:
dbPath: /opt/mongodb/data/data-27997/
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
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.
# ssl:
# mode: preferSSL
# PEMKeyFile: /opt/mongodb/x.509/hc4Jammy.yushei.net.pem
# CAFile: /opt/mongodb/x.509/mongoCA.crt
# allowInvalidCertificates: false
# allowInvalidHostnames: false
# security:
# authorization: enabled
# clusterAuthMode: x509
#operationProfiling:
replication:
replSetName: "configServerr"
sharding:
clusterRole: "configsvr"
## Enterprise-Only Options
#auditLog:
#snmp:
¶ /etc/systemd/system/Mongodb-27997.service
[Unit]
Description=MongoDB Database Server, port 27997, ShardingMuneTakaHome
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/mongodb-27997.conf"
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
ExecStart=/usr/local/bin/mongod $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