Recently, I researched MongoDB and documented the installation process.
Download link:Try MongoDB Community Edition[1]
# Download
wget https://repo.mongodb.org/apt/ubuntu/dists/jammy/mongodb-org/7.0/multiverse/binary-amd64/mongodb-org-server_7.0.2_amd64.deb
# Install
apt install mongodb-org-server_7.0.2_amd64.deb
systemctl status mongod
# Location of service and conf files
# /lib/systemd/system/mongod.service
# /usr/bin/mongod --config /etc/mongod.conf
<span>Modify the configuration file:</span>
- vim /etc/mongod.conf
- dbPath: Specify the data storage path
- logging: Log path
- port: Port number
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath:/data/mongodb
# engine:
# wiredTiger:
# where to write logging data.
systemLog:
destination:file
logAppend:true
path:/data/log/mongodb/mongod.log
# network interfaces
net:
port:27017
bindIp:127.0.0.1,192.168.1.11
#security:
# authorization: enabled
# how the process runs
processManagement:
timeZoneInfo:/usr/share/zoneinfo
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
<span>Start:</span>
systemctl start mongod
Next, enable authentication.
- Use SCRAM to Authenticate Clients[2]
# First connection. No password is needed since Auth is not enabled.
mongosh --port 27017
use admin
// Create a superuser
db.createUser({
user: "lab",
pwd: "8Kx4_QExImdMVYn7Ugh",
roles: [{ role: "root", db: "admin" }],
});
<span>Modify mongod.conf again:</span>
- vim /etc/mongod.conf
- authorization
security:
authorization: enabled
Re-start the MongoDB instance with <span><strong>access control</strong></span>
# Restart
systemctl restart mongod
References
[1]
Try MongoDB Community Edition: https://www.mongodb.com/try/download/community
[2]
Use SCRAM to Authenticate Clients: https://www.mongodb.com/docs/manual/tutorial/configure-scram-client-authentication/