mongodb installation and configuration

mongodb installation
1. Upload and extract the program
cd /u01/software
tar -zxvf mongodb-linux-x86_64-rhel70-3.6.3.tgz

2. Program installation and configuration
mv mongodb-linux-x86_64-rhel70-3.6.3 mongodb
mv mongodb /opt/
/opt/mongodb
mkdir data
mkdir conf
cd conf
rz ------ Upload the mongodb.conf file
vi mongodb.conf - ------------------Modify file related paths and turn off user verification authorization: disabled

3. User create
cd ../..
groupadd mongodb
useradd mongodb -g mongodb
chown -R mongodb:mongodb ./mongodb
cd mongodb/bin/
ls
pwd
vi /etc/profile---------export PATH=$ PATH:/opt/mongodb/bin
source /etc/profile
4. Start the program
mongod --config /opt/mongodb/conf/mongodb.conf ------ Start the program
mongo
ls
ps -ef|grep mongo
5. Create Database, user, etc. (user verification [authorization: disabled in the mongodb.conf file] needs to be turned off when logging in with admin)
mongo localhost:27017/admin ----- Log in as an administrator

use hislog-----------------------create databaseswitched
to db hislog
db----------------- -----Create database
hislog
show dbs---------------View database
admin 0.000GB
config 0.000GB
local 0.000GB

db.createUser({user:'his',pwd:'Chis2017',roles:[{role:'dbOwner',db:'hislog'}]}) -------------- ------Create user
db.dropUser("his") ------------------------- Delete user
mongod --shutdown --dbpath /u01/mongodb/data/-----------------stop program

vi mongodb.conf -------------------------- Enable user verification [authorization: enabled]
mongod --config /opt/mongodb/conf/ mongodb.conf -------- start the program
ps -ef|grep mongo
6 use the created user to log in to
mongo localhost:27017/hislog -u his -p Chis2017

Extension:
mongo --version

db.hislog.insert({"name":"Rookie Tutorial"})-----Insert
data./mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/ logs --logappend --port=27017 --fork --auth
--------fork specifies background operation --auth enables authentication --dbpath specifies database directory --logpath specifies log file --logappend log cumulative addition

There are two types of mongodb users, one is an administrator and the other is an ordinary user.
Create an administrator
1. Turn off user authentication,

  1. mongo localhost:27017/admin
    use admin
    db.createUser({user:'admin',pwd:'123456',roles:[{role:'readWriteAnyDatabase',db:'admin'}]})
    --readAnyDatabase: in admin Created under the database, can read the information of all databases
    --readWriteAnyDatabase: created under the admin database, can read and write the information of all databases--
    userAdminAnyDatabase: created under the admin database, can manage users of all databases--
    dbAdminAnyDatabase: in the admin Created under the database, you can manage the information of all databases (similar to the dbAdmin account of all databases)

Create ordinary user
use isdb ----isdb is database
db.createUser({user:'dev',pwd:'123456',roles:[{role:'dbOwner',db:'isdb'}]})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324781217&siteId=291194637