mkdir -p /var/mongodb/db/{1,2,3}
sudo mkdir -p /var/mongodb/pki/
openssl rand -base64 741 > /var/mongodb/pki/m103-keyfile
chmod 400 /var/mongodb/pki/m103-keyfile
storage:
dbPath: /var/mongodb/db/1
net:
bindIp: localhost
port: 27001
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/logs/mongod1.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
storage:
dbPath: /var/mongodb/db/2
net:
bindIp: localhost
port: 27002
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/logs/mongod2.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
storage:
dbPath: /var/mongodb/db/3
net:
bindIp: localhost
port: 27003
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/logs/mongod3.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl
mongo --port 27001
rs.initiate()
use admin
db.createUser({
user: "m103-admin",
pwd: "m103-pass",
roles: [
{role: "root", db: "admin"}
]
})
# then exit
mongo --host "localhost:27001" -u "m103-admin"
-p "m103-pass" --authenticationDatabase "admin"
rs.status()
rs.add("localhost:27012")
rs.add("localhost:27013")