Installation and configuration of mongodb under centos7

1. Download the mongodb installation package

https://www.mongodb.com/download-center#community

Choose RHEL 7 Linux 64-bit x64

 

2. Unzip the installation package

tar -zxvf mongodb-linux-x86_64-rhel70-3.4.3.tgz

Enter the decompressed directory and set the files in the bin folder to executable permissions

chmod -R 755 bin

 

3. Write the configuration file mongodb.conf 

vi mongodb.conf

 

port=27017  

dbpath=/usr/local/dev/mongodb/data/db  

  

logappend=true  

fork=true  

 

logpath=/usr/local/dev/mongodb/data/logs 

 

Note to create /usr/local/dev/mongodb/data/db folder, /usr/local/dev/mongodb/data/logs file

mongodb.conf is placed under /usr/local/dev/mongodb/bin

chmod -R 777  /usr/local/dev/mongodb/data/ give data directory permission

 

4. Register mongodb service

Create mongodb.service in the /lib/systemd/system directory

vi mongodb.service

content:

[Unit]

Description=mongodb

After=network.target remote-fs.target nss-lookup.target

 

[Service]

Type=forking

ExecStart=/usr/local/dev/mongodb/bin/mongod -f /usr/local/dev/mongodb/bin/mongodb.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/usr/local/dev/mongodb/bin/mongod --shutdown -f /usr/local/dev/mongodb/bin/mongodb.conf

PrivateTmp=true

 

[Install]

 

WantedBy=multi-user.target

 

Then give permission chmod 754 mongodb.service, register to start   systemctl enable mongodb.service 

 

5. Permission settings

First create a super administrator for the admin library

> use admin

> db.createUser({user:'admin',pwd:'admin',roles:[{role:'root',db:'admin'}]})

 

Create another business library, such as

use test

Then create a read-write user for this business library

> db.createUser({user:'test',pwd:'123456',roles:[{role:'readWrite',db:'test'}]})

 

Finally, modify the mongodb.conf file, add an auth=true, and restart the service

 

Enter the command line with ./mongo

> use test

> db.auth('test','123456')

 read and write operations

 

in addition

> show users; #View the users under the current library

 

View all users

> use admin

> db.system.users.find().pretty()

 

Modify user password
> db.changeUserPassword("test","22222222");

delete a single user
> db.dropUser("test");
true


1.20, delete all users

> db.dropAllUsers();
1
>
return the number of deleted users .

 

 

 

 

 

 

Reference: http://blog.csdn.net/fangxiaoji/article/details/51175866

           http://www.cnblogs.com/shiyiwen/p/5552750.html

          http://blog.csdn.net/xuzheng_java/article/details/42550653

Guess you like

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