§2023-08-08
The final will be as follows,
ConfigServer [primary] admin> rs.status().members.forEach(member => print(member.name))
orgpi5jammy.yushei.net:27987
n2mnjaro.yushei.net:27987
hc4lunar.yushei.net:27987
- ShardA
-
- replication.replSetName: "ShardA", sharding.clusterRole: "shardsvr"
-
ShardA [primary] admin> rs.status().members.forEach(member => print(member.name))
n2Mnjaro-01.yushei.net:27985
hc4Bookworm.yushei.net:27985
hc4Lunar.yushei.net:27985
- 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:27983
hc4Bookworm.yushei.net:27983
hc4Lunar.yushei.net:27983
- /etc/mongodb-27987.conf
# mongodb-27987.conf configsvr, no X.509
# 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-27987.log
# Where and how to store data.
storage:
dbPath: /opt/xfs/mongodb/data-27987/
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27987
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/orgpi5jammy.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:
security was turn off, till you assign the "siteRootAdmin"
- /etc/systemd/system/Mongodb-27987.service
/*
* .mongoshrc.js
* db = connect("mongodb://127.0.0.1:27017/admin?replicaSet=ys20210904");
* db = connect("mongodb://x8664Arch.yushei.com.tw:27017,hc4Jammy.yushei.com.tw:27017,n2Jammy.yushei.com.tw:27017/?authSource=admin")
* db = connect("mongodb://siteRootAdmin:b23258585@x8664Arch.yushei.com.tw:27017,hc4Jammy.yushei.com.tw:27017,n2Jammy.yushei.com.tw:27017/?replicaSet=odroid01?authSource=admin");
* db.auth("siteRootAdmin", "b23258585");
* all the above lines failed
*/
db = connect("mongodb://orgpi5jammy.yushei.net:27987,n2mnjaro.yushei.net:27987,hc4lunar.yushei.net:27987/");
// let log = rs.status().members;
// console.table(log);
function alert() {
let log = rs.status().members;
let simpleLog = [];
// console.log(log);
for (let i = 0; i < log.length; i++){
// console.log("_id: ", log[i]._id, "name: ", log[i].name, "health: ", log[i].health, "state: ", log[i].state, "stateStr: ", log[i].stateStr);
simpleLog[i] = {
"_id": log[i]._id,
"name": log[i].name,
"health": log[i].health,
"state": log[i].state,
"stateStr": log[i].stateStr
}
}
console.log('\n');
console.table(simpleLog);
console.log(Date().toLocaleString());
}
alert();
let timerId = setInterval(() => alert(), 60000); // 単位 is milli-second, 1 sec = 1000
/*
// The following codes are to tail on inLaneCapped
// Replace 'your_capped_collection_name' with the name of your capped collection
const collection = db.getCollection('inLaneCapped');
// Watch the capped collection for changes
const changeStream = collection.watch();
// Function to process each change and print specific fields
const processChange = (change) => {
if (change.operationType === 'insert') {
// _id: , plateText: 'NEF6953', cameraSource: '002', inTime: '2023-07-25T17:17:04',
const { _id, plateText, cameraSource, inTime } = change.fullDocument; // Add the specific fields you want to print
print(`Change ID: ${_id}`);
print(`plateText: ${plateText}`);
print(`camerSource: ${cameraSource}`);
print(`inTime: ${inTime}`);
}
};
// Start the change stream and monitor for changes
const monitorChanges = async () => {
while (true) {
const change = await changeStream.tryNext();
if (change) {
processChange(change);
} else {
// Sleep for a short interval before checking again
// alert();
sleep(100);
}
}
};
let timerId = setInterval(() => alert(), 60000); // 単位 is milli-second, 1 sec = 1000
*/
[Unit]
Description=MongoDB Config Server, port 27987, replication.replSetName: 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-27987.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:27987" },
{ _id: 1, host: "n2Mnjaro.yushei.net:27987" },
{ _id: 2, host: "hc4Lunar.yushei.net:27987" }
]
});
- ~/scripts/startMongosh-27987.sh
#!/bin/bash
# for 27997 confisrc
# mongosh "mongodb://siteRootAdmin:b23258585@\
mongosh "mongodb://\
orgpi5jammy.yushei.net:27987,\
n2mnjaro.yushei.net:27987,\
hc4lunar.yushei.net:27987/
# admin\
# ?tls=true&\
# tlsCertificateKeyFile=/opt/xfs/mongodb/x.509/orgpi5jammy.yushei.net.pem&\
# tlsCAFile=/opt/xfs/mongodb/x.509/mongoCA.crt"
- ~/.mongoshrc.js
/*
* .mongoshrc.js
* db = connect("mongodb://127.0.0.1:27017/admin?replicaSet=ys20210904");
* db = connect("mongodb://x8664Arch.yushei.com.tw:27017,hc4Jammy.yushei.com.tw:27017,n2Jammy.yushei.com.tw:27017/?authSource=admin")
* db = connect("mongodb://siteRootAdmin:b23258585@x8664Arch.yushei.com.tw:27017,hc4Jammy.yushei.com.tw:27017,n2Jammy.yushei.com.tw:27017/?replicaSet=odroid01?authSource=admin");
* db.auth("siteRootAdmin", "b23258585");
* all the above lines failed
*/
db = connect("mongodb://orgpi5jammy.yushei.net:27987,n2mnjaro.yushei.net:27987,hc4lunar.yushei.net:27987/");
// let log = rs.status().members;
// console.table(log);
function alert() {
let log = rs.status().members;
let simpleLog = [];
// console.log(log);
for (let i = 0; i < log.length; i++){
// console.log("_id: ", log[i]._id, "name: ", log[i].name, "health: ", log[i].health, "state: ", log[i].state, "stateStr: ", log[i].stateStr);
simpleLog[i] = {
"_id": log[i]._id,
"name": log[i].name,
"health": log[i].health,
"state": log[i].state,
"stateStr": log[i].stateStr
}
}
console.log('\n');
console.table(simpleLog);
console.log(Date().toLocaleString());
}
alert();
let timerId = setInterval(() => alert(), 60000); // 単位 is milli-second, 1 sec = 1000
/*
// The following codes are to tail on inLaneCapped
// Replace 'your_capped_collection_name' with the name of your capped collection
const collection = db.getCollection('inLaneCapped');
// Watch the capped collection for changes
const changeStream = collection.watch();
// Function to process each change and print specific fields
const processChange = (change) => {
if (change.operationType === 'insert') {
// _id: , plateText: 'NEF6953', cameraSource: '002', inTime: '2023-07-25T17:17:04',
const { _id, plateText, cameraSource, inTime } = change.fullDocument; // Add the specific fields you want to print
print(`Change ID: ${_id}`);
print(`plateText: ${plateText}`);
print(`camerSource: ${cameraSource}`);
print(`inTime: ${inTime}`);
}
};
// Start the change stream and monitor for changes
const monitorChanges = async () => {
while (true) {
const change = await changeStream.tryNext();
if (change) {
processChange(change);
} else {
// Sleep for a short interval before checking again
// alert();
sleep(100);
}
}
};
let timerId = setInterval(() => alert(), 60000); // 単位 is milli-second, 1 sec = 1000
*/