install mongodb
tar -zxvf mongodb-linux-x86_64-4.0.22.tgz
useradd mongod
init passwd with “mongod”
passwd mongod
mkdir for data storage
mkdir /var/lib/mongo
mkdir for log storage
mkdir /var/log/mongodb
create mongo home dir
mkdir /opt/mongo
mv mongodb-linux-x86_64-4.0.22 /opt/mongo/
cd /opt/mongo/mongodb-linux-x86_64-4.0.22/
chown -R mongod:mongod mongo/
ln -s /opt/mongo/mongodb-linux-x86_64-4.0.22/bin/* /usr/local/bin/
create mongod.conf
touch /etc/mongod.conf
config mongod, create file /etc/mongod.conf, and content below
processManagement:
fork: true
net:
bindIp: localhost
port: 27017
storage:
dbPath: /var/lib/mongo
systemLog:
destination: file
path: “/var/log/mongodb/mongod.log”
logAppend: true
storage:
journal:
enabled: true
use user mongod
su mongod
start mongod
mongod -f /etc/mongod.conf
connect mongod
mongo -u “xx” --authenticationDatabase “admin” -p
add user
use admin
db.createUser(
{
user: “xx”,
pwd: “xxx”,
roles: [ { role: “userAdminAnyDatabase”, db: “admin” }, “readWriteAnyDatabase” ]
}
)
shut down mongod
db.adminCommand( { shutdown: 1 } )
edit config file to apply auth feature, append content below to /etc/mongd.conf
security:
authorization: enabled
restart mongod
mongod -f /etc/mongod.conf
stop with mongod
mongod --shutdown -f /etc/mongod.conf
create database
use projectx
db.myNewCollection1.insertOne( { x: 1 } )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)