path : /opt/mongodb-linux-x86_64-ubuntu1604-3.4.4
##Setting up user authentication ##
start mongod --config /<mongo.conf> (without --auth)
run mongo --port 27017
>use admin
switched to db admin
> db.createUser({user:"noxma",pwd:"noxma434", roles:[{role:"root",db:"admin"}]})
> exit
(Remark: other way in config file ,nano mongodb.conf)
security:
authorization: enabled
##Set auth option##
##Service Defination##
/lib/systemd/system/mongodb.service
---------------------------------------------------------------
[Unit]
Description=mongo database service
Requires=postgresql.service
After=network.target postgresql.service
[Service]
Type=simple
PermissionsStartOnly=true
SyslogIdentifier=mongodb
User=ubuntu
Group=ubuntu
ExecStart=/opt/mongodb-linux-x86_64-ubuntu1604-3.4.4/bin/mongod --auth --config /opt/mongodb-linux-x86_64-ubuntu1604-3.4.4/bin/mongod_nofork.conf
WorkingDirectory=/opt/mongodb-linux-x86_64-ubuntu1604-3.4.4
[Install]
WantedBy=multi-user.target
---------------------------------------------------------------
##Command ###
sudo systemctl status mongodb.service
sudo systemctl start mongodb.service
sudo systemctl stop mongodb.service
##Setting up user authentication ##
start mongod --config /<mongo.conf> (without --auth)
run mongo --port 27017
>use admin
switched to db admin
> db.createUser({user:"noxma",pwd:"noxma434", roles:[{role:"root",db:"admin"}]})
> exit
(Remark: other way in config file ,nano mongodb.conf)
security:
authorization: enabled
##Set auth option##
##Service Defination##
/lib/systemd/system/mongodb.service
---------------------------------------------------------------
[Unit]
Description=mongo database service
Requires=postgresql.service
After=network.target postgresql.service
[Service]
Type=simple
PermissionsStartOnly=true
SyslogIdentifier=mongodb
User=ubuntu
Group=ubuntu
ExecStart=/opt/mongodb-linux-x86_64-ubuntu1604-3.4.4/bin/mongod --auth --config /opt/mongodb-linux-x86_64-ubuntu1604-3.4.4/bin/mongod_nofork.conf
WorkingDirectory=/opt/mongodb-linux-x86_64-ubuntu1604-3.4.4
[Install]
WantedBy=multi-user.target
---------------------------------------------------------------
##Command ###
sudo systemctl status mongodb.service
sudo systemctl start mongodb.service
sudo systemctl stop mongodb.service