§2023-07-30
- This is a two nodes only
configsrv
in a sharding.
Machine | IP | OS | mongod/mongos Version | Replication Set | momgosh Avialbale | configrv/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
¶ systemctl start Mongodb-27997.service
# systemctl start Mongodb-27997
# systemctl status Mongodb-27997
● Mongodb-27997.service - MongoDB Database Server
Loaded: loaded (/etc/systemd/system/Mongodb-27997.service; disabled; preset: disabled)
Active: active (running) since Sun 2023-07-30 13:04:03 CST; 15s ago
Docs: https://docs.mongodb.org/manual
Main PID: 1497 (mongod)
Memory: 87.6M
CPU: 1.358s
CGroup: /system.slice/Mongodb-27997.service
└─1497 /usr/local/bin/mongod -f /etc/mongodb-27997.conf
Jul 30 13:04:03 n2Mnjaro systemd[1]: Started MongoDB Database Server.
Jul 30 13:04:03 n2Mnjaro mongod[1497]: {"t":{"$date":"2023-07-30T05:04:03.534Z"},"s":"I", "c":"CONTROL", "id":7484500, "ctx":"main","msg":"Environment variable MONGODB_CONFIG_OVERRIDE_NOFORK == 1, overriding \"processManagement.fork\" to false"}
- 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