§2023-07-29
We will start the replication setup using x.509 from orgpi5Arch.yushei.net
- replicationSet : MuneTakaHome:27999
¶Step1: /etc/mongodb-27999.conf,
- 27999 is the port for MuneTakaHome ReplicationSet.
# mongodb-27999.conf
# 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
path: /opt/xfs/mongodb/log/mongod-27999.log
# Where and how to store data.
storage:
dbPath: /opt/xfs/mongodb/data-27999
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27999
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: /var/lib/mongodb/x.509/orgpi5Arch.yushei.net.pem
CAFile: /var/lib/mongodb/x.509/mongoCA.crt
allowInvalidCertificates: false
allowInvalidHostnames: false
# clusterFile: /var/lib/mongodb/x.509/orgpi5Arch.yushei.net.pem
# PEMKeyPassword: TxxxxYxxLxx#1nnn
# clusterPassword: TxxxxYxxLxx#1nnn
security:
authorization: enabled
clusterAuthMode: x509
#operationProfiling:
replication:
replSetName: "MuneTakaHome"
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
Don't forget to create directories
$ sudo mkdir /opt/xfs/mongodb/data-27999
[sudo] password for alexlai:
[alexlai@orpi5Arch x.509]$ sudo chown mongodb:mongodb /opt/xfs/mongodb/data-27999/
¶Step 2: /etc/systemd/system/Mongodb-27999.service
[Unit]
Description=MongoDB Database Server, port 27999, MuneTakaHome
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-27999.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
¶Step3, start and check
$ sudo systemctl daemoon-reload
$ sudo systemctl start Mongodb-27999.service
$ sudo systemctl status Mongodb-27999.service
alexlai@orgpiJammy:~/x.509$ sudo ls /opt/xfs/mongodb/data-27999/
collection-0--3399823647854825395.wt index-1--3399823647854825395.wt journal storage.bson WiredTiger.turtle
collection-2--3399823647854825395.wt index-3--3399823647854825395.wt _mdb_catalog.wt WiredTiger WiredTiger.wt
collection-4--3399823647854825395.wt index-5--3399823647854825395.wt mongod.lock WiredTigerHS.wt
diagnostic.data index-6--3399823647854825395.wt sizeStorer.wt WiredTiger.lock
alexlai@orgpiJammy:~/x.509$ sudo tail -f /opt/xfs/mongodb/log/mongod-27999.log
{"t":{"$date":"2023-07-29T15:33:28.023+08:00"},"s":"I", "c":"STORAGE", "id":22262,
"ctx":"initandlisten","msg":"Timestamp monitor starting"}
{"t":{"$date":"2023-07-29T15:33:28.026+08:00"},"s":"I", "c":"NETWORK", "id":23015,
"ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27999.sock"}}
{"t":{"$date":"2023-07-29T15:33:28.026+08:00"},"s":"I", "c":"NETWORK", "id":23015,
"ctx":"listener","msg":"Listening on","attr":{"address":"0.0.0.0"}}
{"t":{"$date":"2023-07-29T15:33:28.026+08:00"},"s":"I", "c":"NETWORK", "id":23016,
"ctx":"listener","msg":"Waiting for connections","attr":{"port":27999,"ssl":"on"}}
¶s;Step 4, check with mongosh
If ~/.mongoshrc.js
// .mongoshrc
// Configuration for connecting to the MongoDB instance
// running on port 27999 locally.
db = connect("mongodb://localhost:27999/admin");
// db.auth();
console.log("Hi! from orgpi5Jammy.yushei.net:27999");
[alexlai@orpi5Arch ~]$ mongosh mongodb://localhost:27999
Current Mongosh Log ID: 64c4b0b551cd35d9d0b3ea5e
Connecting to: mongodb://localhost:27999/?directConnection=true&serverSelectionTimeoutMS=2000&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/
Hi! from orgpi5Arch.yushei.net:27999
admin>
But,
[alexlai@orpi5Arch ~]$ mongosh
Current Mongosh Log ID: 64c4b0d0ef31bf88e41e51f7
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.1
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017