Linux installation MongoDB

Source: Internet
Author: User
Tags mongodb server

First, download

Linux:centos 7.3 64-bit

mongodb:3.6.4

Installation directory:/usr/local

cd/usr/localwget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64- Rhel62-3.6.4.tgz
Second, decompression

Unzip the installation package and rename it (easy to manage)

tar -zxvf mongodb-linux-x86_64-rhel62-3.6. 4 . tgz MV mongodb-linux-x86_64-rhel62-3.6. 4 MongoDB
Third, configure MongoDB

Need to configure three items, one is the Data folder (db, file name can be customized), one is the log folder (logs, file name can be customized), a configuration file (mongo.conf)

1. Data folder

mkdir DB

2. log Folder

mkdir Logs

3. Create a configuration file

# Where to write logging data.systemlog:  destination:file  logappend:true  Path:/usr/local/mongodb/logs/ Mongod.log #日志文件存放目录 # Where and how to store Data.storage:  dbPath:/usr/local/mongodb/db #数据文件存放目录  Journal:    enabled:true# How the process runsprocessmanagement:  fork:true  #以守护程序的方式启用, which runs in the background  Pidfilepath:/ Usr/local/mongodb/mongod.pid  # Location of pidfile# network interfacesnet:  port:27017 #端口  Bindip: 0.0.0.0  # Listen to local interface only, comment to Listen on all interfaces. Ports open to the outside

4.

5. Start

MongoDB's Bin directory is executed under:

./mongod--config/usr/local/mongodb/mongod.conf
Iv. adding users

MongoDB installation After the default is not to verify the password, which in the production environment is absolutely not allowed to exist, we need to create users, and increase user authentication!

If a user is added to the admin database, the user will automatically get all the database permissions, i.e. the administrator account. If a user is added to a normal database, the user can only get the relevant permissions for that database, that is, the normal user.

Switch to the bin directory of MongoDB:

1. Add Administrator account

./MONGO> Useadmin>db.createuser ({User:"root",pwd: " Password ", roles:["root"]})

2. Enable MongoDB Authorization

After the mongod.conf, add:

Security:   // Enable authorization

3. Restart Effective

To close the MongoDB server:

./mongod-shutdown-dbpath=/usr/local/mongodb/db

After authorization, start the MONGODB server:

27017 --auth--fork

4. Authenticated Users

./MONGO>Use admin// will prompt user not to verify >db.auth ("root" ,"password")>show dbsadmin   0. 001GBconfig  0. 000GBlocal   0. 000GB

5, add ordinary users

 > Use LXCX //  CREATE DATABASE  > Db.createuser ({user: summer   ", pwd : "   , Roles:[{"  role  : "   ReadWrite  , "  db  : "   LXCX  }]}); //  

User: Username

PWD: Password

Roles: Specifies the role of the user, an empty array can be used to set the null role for the new user; In the Roles field, you can specify built-in roles and user-defined roles. Roles in role can be selected:

Built-in Roles (built-in role):    1. Database user role: Read, readWrite;    2. Database management roles: DbAdmin, Dbowner, Useradmin;    3. Cluster Management role: Clusteradmin, Clustermanager, Clustermonitor, Hostmanager;    4. Backup Restore role: backups, restore;    5. All database roles: Readanydatabase, Readwriteanydatabase, Useradminanydatabase, Dbadminanydatabase    6. Super User role: Root      //There are several roles here that indirectly or directly provide access to the system's Superuser (Dbowner, Useradmin, Useradminanydatabase)    7. Internal role: __system
READ: Allows the user to read the specified database ReadWrite: Allows the user to read and write to the specified database dbadmin: Allows the user to execute administrative functions in the specified database, such as index creation, deletion, View statistics or Access System.profileuseradmin: Allows the user to write to the System.users collection and can create, delete, and manage user clusteradmin in the specified database: Only available in the admin database. Gives the user administrative privileges on all shards and replica set related functions. Readanydatabase: Only available in the Admin database, giving the user read access to all databases Readwriteanydatabase: Only available in the admin database, Give users read and write access to all databases Useradminanydatabase: Available only in the admin database, giving the user useradmin permissions to all databases Dbadminanydatabase: Only available in the admin database, Gives the user dbadmin permissions for all databases. Root: Available only in the admin database. Super account, Super privilege

Linux installation MongoDB

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.