CentOS 6 Installation MongoDB

Source: Internet
Author: User
Tags auth openssl ssh iptables

MongoDB Installation and Configuration


First step, go to MongoDB website to download MongoDB database

The download version is based on your operating system,

MongoDB such as: mongodb-linux-x86_64-3.2.10.tgz


Step two, install the virtual machine

Virtual machine installation skipped


Step three, install the Linux system

Linux installation skipped


Fourth step, install the SSH connection Linx tool

Skip Over


Fifth step, after the Linx system is installed, log in according to your user password Linx

Connect Linx using the SSH tool


Above own Baidu a bit can find



The sixth step, the dry goods come.

Installing MongoDB under Linux

Unzip MongoDB

Modify the folder name: MongoDB

The file structure is as follows:

Mongodb

->bin

->gnu-agpl-3.0

->mpl-2

->readme

->third-party-notices

Create two folders in this folder for data files and log files (of course you can choose your preferred location)

Folder name is: DB

Log

Input command: cd/usr/local/

Copy the previous MongoDB paste into this directory



Input command: Cd/usr/local/mongodb/bin

/** Start Service **/

./mongod--dbpath=/usr/local/mongodb/db/--logpath=/usr/local/mongodb/log/mongo.log--logappend--auth--port=27017 --fork


/** Success Information **/

About-to-fork child process, waiting until server was ready for connections.

Forked process:12999

Child process started successfully, parent exiting


It finally started.

./mongod


Use admin


/** Create Super Admin, MongoDB 3.0 later version for create created, not add **/

Db.createuser ({User: "Super", pwd: "Super", roles: [{role: "root", DB: "Admin"}]})


Db.auth ("Super", "Super")


/** Creating a database **/

Use MyDB

Add data

Db.usr.insert ({' name ': ' Tompig '});




/** above is just the account that created the Admin database, the newly created database is not yet accessible **/

Log in using super account to create

./mongo

Use admin

Db.auth ("Super", "Super")

Use MyDB

Db.createuser ({User: "Testx", pwd: "Testx", roles: [{role: "DbAdmin", DB: "MyDB"}]})

After successful creation, access is made using the TESTX user connection data.


/** Close Service **/

1. General Command:

$./mongo

> Use admin

> Db.shutdownserver ()



Note: You must turn off the firewall or you cannot access the

/** shutting down the firewall **/

Service Iptables Stop


/** permanently shuts down the firewall **/

Chkconfig--level iptables off



Encountered the following

Error:

Permission denied.


Input command: Chmod-r 777/usr/local/mongodb (the path here is the path of mongodb) cause = Whether it is root permission, and ssh copy sticky in, and do not give permission


Error:

./mongod:/usr/lib64/libcrypto.so.10:no version information available (required by./mongod)

./mongod:/usr/lib64/libssl.so.10:no version information available (required by./mongod)

./mongod:relocation error:./mongod:symbol Tlsv1_2_client_method, version libssl.so.10 not defined in file libssl.so.10 With Link Time reference


Input command: Yum install-y openssl-devel OpenSSL solution, installation of OpenSSL dependent operation is required



Error:

About-to-fork child process, waiting until server was ready for connections.

Forked process:12981

Error:child process failed, exited with error number 1

Input command:./mongod--repair--dbpath/usr/local/mongodb/db/--repairpath/tmp/mongodb




The above settings more trouble Ah, the following configuration shortcut start mode


Create a new Notepad, change the name to Mongo.conf, and paste in the following copy

dbpath=/usr/local/mongodb/db

Logpath=/usr/local/mongodb/log/mongo.log

port=27017

Fork=true

Auth=true

bindip=0.0.0.0


I believe you see the above configuration can also understand,

Database storage path for DBPATH=MONGODB

Log file storage path for Logpath=mongodb

port= Port number

Fork=true This is running in a daemon way.

Auth=true If you need authentication login

bind_ip= bound port number, 0.0.0.0 is any IP can access, otherwise you need to specify IP such as: 192.168.1.102




After the configuration, put this file into the/usr/mongodb/bin directory

Input command: Cd/usr/local/mongodb/bin Enter directory

Enter command:./mongod-f mongo.conf Start


Over, below is the help of DB












Help with DB

Db.createuser (username,password) Add user

Db.auth (Usrename,password) setting Up Database connection validation

Db.clonedatabase (fromhost) cloning a database from the target server

DB.COMMANDHELP (name) returns the Help for the command

Db.copydatabase (fromdb,todb,fromhost) Copy database fromdb---Source database name, TODB---target database name, fromhost---source database server address

Db.createcollection (name,{size:3333,capped:333,max:88888}) creates a data set that is equivalent to a table

Db.currentop () cancels the current operation of the current library

Db.dropdatabase () Delete the current database

Db.eval (Func,args) Run code server-side

Db.getcollection (CNAME) get a data set, same usage: db[' cname ') or

Db.getcollenctionnames () Gets a list of all data collection names

Db.getlasterror () returns the last Error prompt message

Db.getlasterrorobj () returns the last Error object

Db.getmongo () Gets the connection object of the current server get the server

Db.getmondo (). Setslaveok () Allow this connection to read from then Nonmaster membr of a replica pair

Db.getname () returns the name of the operation database

Db.getpreverror () returns the previous Error object

Db.getprofilinglevel () Get profile level

Db.getreplicationinfo () to get duplicate data

DB.GETSISTERDB (name) get the db at the same server as this onew

Db.killop () Stop (kill) The current operation in the current library

Db.printcollectionstats () returns the current library's dataset status

Db.printreplicationinfo () Print replication status information for the primary database

Db.printslavereplicationinfo () Print replication status information from the database

Db.printshardingstatus () returns whether the current database is a shared database

Db.removeuser (username) Delete User

Db.repairdatabase () repairing the current database

Db.reseterror ()

Db.runcommand (cmdobj) run a database command. If Cmdobj is a string, turns it into {cmdobj:1}

Db.setprofilinglevel (level) Set profile level 0=off,1=slow,2=all

Db.shutdownserver () Close the current service program

Db.version () returns the version information for the current program


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


table, format, db. Table name. Help ()

Db.test.find ({id:10}) returns the DataSet id=10 the test dataset

Db.test.find ({id:10}). Count () returns the total number of data id=10 the test dataset

Db.test.find ({id:10}). Limit (2) returns the data set from the second bar of the dataset id=10 the test dataset

Db.test.find ({id:10}). Skip (8) returns the dataset from 0 to eighth for the DataSet id=10 the test dataset

Db.test.find ({id:10}). Limit (2). Skip (8) Returns the data from the second to eighth data set of the test dataset id=1=

Db.test.find ({id:10}). Sort () returns the sorted data set id=10 the test dataset

Db.test.findOne ([query]) returns a piece of data that meets the criteria

Db.test.getDB () returns the name of the database to which this dataset belongs

Db.test.getIndexes () returns the index information for some datasets

Db.test.group ({key:...,initial:...,reduce: ...  [, cond: ...]}) Return grouping information

Db.test.mapReduce (mayfunction,reducefunction,<optional params>) This is kind of like a stored procedure.

Db.test.remove (query) deletes a single piece of data in a data set

Db.test.renameCollection (newName) Rename some data set names

Db.test.save (obj) inserts a piece of data into the data set

Db.test.stats () Returns the state of this dataset

Db.test.storageSize () returns the storage size of this dataset

Db.test.totalIndexSize () returns the index file size of this dataset

Db.test.totalSize () returns the total size of some datasets

Db.test.update (Query,object[,upsert_bool]) update a data set in this dataset

Db.test.validate () validates this data set

Db.test.getShardVersion () returns the data set share version number



This article is from the "Green Years" blog, be sure to keep this source http://alex233.blog.51cto.com/8904951/1858856

CentOS 6 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.