Fast installation of MongoDB under Linux

Source: Internet
Author: User
Tags install mongodb mongo shell

Mongo DB is a non-relational database (NOSQL) that is currently very popular in the IT industry, and its flexible data storage methods are highly favored by current it practitioners. Mongo DB is a good implementation of object-oriented thinking (Oo idea), in Mongo db each record is a document object. The biggest advantage of Mongo DB is that all data persistence requires no developers to write SQL statements manually, and it is easy to invoke methods to implement CRUD operations. This article describes how to quickly install MongoDB for everyone's reference.

First, install the configuration MongoDB
Step 1: Set up the system environment and ensure that the default port 27107 is available
# # #当前环境
# cat/etc/issue
Red Hat Enterprise Linux Server release 6.5 (Santiago)

# Vi/etc/selinux/config
Selinux=disabled

Step 2: Download the installation file
: Https://www.mongodb.org/downloads.
Or use the Curl command directly at the command prompt to download
Curl-o https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz

Step 3: Unzip the downloaded file
# pwd
/usr/local/src
# TAR-XVF mongodb-linux-x86_64-rhel62-3.0.6.gz # # #注, this article is downloaded directly from the website, so the file is. gz

Step 4: Copy the extracted files to the running directory
# mkdir-p/var/lib/mongodb
# Cp-r-n/usr/local/src/mongodb-linux-x86_64-rhel62-3.0.6/. /var/lib/mongodb/

Step 5: Setting Environment variables
e.g. export Path=<mongodb-install-directory>/bin: $PATH
# VI ~/.bash_profile
Export Path=/var/lib/mongodb/bin: $PATH
# source ~/.bash_profile

Step 6: Create a Data Catalog
# mkdir-p/data/mongodata

Second, start and verify MongoDB
# # #启动mongo
# Mongod--dbpath/data/mongodata

# # #以下内容为启动后输出的相关信息
2015-10-28t10:03:33.100+0800 I JOURNAL [Initandlisten] JOURNAL dir=/data/mongodata/journal
2015-10-28t10:03:33.101+0800 I JOURNAL [initandlisten] recover:no JOURNAL files present, no recovery needed
2015-10-28t10:03:33.264+0800 I JOURNAL [Initandlisten] preallocateisfaster=true 2.18
2015-10-28t10:03:33.398+0800 I JOURNAL [durability] durability thread started
2015-10-28t10:03:33.398+0800 I JOURNAL [JOURNAL writer] JOURNAL writer thread started
2015-10-28t10:03:33.401+0800 I CONTROL [Initandlisten] MongoDB starting:pid=10191 port=27017 dbpath=/data/mongodata 64 -bit host=java_2
2015-10-28t10:03:33.401+0800 i CONTROL [initandlisten] * * Warning:you is running this process as the root user, which I s not recommended.
2015-10-28t10:03:33.401+0800 I CONTROL [Initandlisten]
2015-10-28t10:03:33.402+0800 I CONTROL [Initandlisten]
2015-10-28t10:03:33.402+0800 I CONTROL [initandlisten] * * WARNING:/sys/kernel/mm/transparent_hugepage/enabled is ' Always '.
2015-10-28t10:03:33.402+0800 I CONTROL [initandlisten] * * We suggest setting it to ' never '
2015-10-28t10:03:33.402+0800 I CONTROL [Initandlisten]
2015-10-28t10:03:33.402+0800 I CONTROL [initandlisten] * * WARNING:/sys/kernel/mm/transparent_hugepage/defrag is ' Always '.
2015-10-28t10:03:33.402+0800 I CONTROL [initandlisten] * * We suggest setting it to ' never '
2015-10-28t10:03:33.402+0800 I CONTROL [Initandlisten]
2015-10-28t10:03:33.402+0800 I CONTROL [initandlisten] DB version v3.0.6
2015-10-28t10:03:33.402+0800 I CONTROL [Initandlisten] git version:1ef45a23a4c5e3480ac919b28afcba3c615488f2
2015-10-28t10:03:33.402+0800 I CONTROL [Initandlisten] Build info:linux ip-10-67-194-123 2.6.32-220.el6.x86_64 #1 SMP We D Nov 9 08:03:13 EST x86_64 boost_lib_version=1_49
2015-10-28t10:03:33.402+0800 I CONTROL [Initandlisten] Allocator:tcmalloc
2015-10-28t10:03:33.402+0800 I CONTROL [Initandlisten] options: {storage: {dbPath: '/data/mongodata '}}
2015-10-28t10:03:33.404+0800 I INDEX [Initandlisten] allocating new NS FILE/DATA/MONGODATA/LOCAL.NS, filling with zero Es...
2015-10-28t10:03:33.491+0800 I STORAGE [fileallocator] allocating new datafile/data/mongodata/local.0, filling with Zer OES ...
2015-10-28t10:03:33.491+0800 I STORAGE [fileallocator] Creating directory/data/mongodata/_tmp
2015-10-28t10:03:33.497+0800 I STORAGE [fileallocator] Done allocating datafile/data/mongodata/local.0, SIZE:64MB, too K 0.001 secs
2015-10-28t10:03:33.511+0800 I NETWORK [Initandlisten] waiting for connections on port 27017

# # #停止mongo, use CTRL + C directly
^c2015-10-28t10:09:21.510+0800 I CONTROL [Signalprocessingthread] got signal 2 (Interrupt), would terminate after current CMD ends
2015-10-28t10:09:21.511+0800 I CONTROL [Signalprocessingthread] now exiting
2015-10-28t10:09:21.511+0800 I NETWORK [Signalprocessingthread] shutdown:going to close listening sockets ...
2015-10-28t10:09:21.511+0800 I NETWORK [signalprocessingthread] closing listening socket:5
2015-10-28t10:09:21.511+0800 I NETWORK [signalprocessingthread] closing listening socket:6
2015-10-28t10:09:21.511+0800 I NETWORK [signalprocessingthread] removing socket file:/tmp/mongodb-27017.sock
2015-10-28t10:09:21.511+0800 I NETWORK [Signalprocessingthread] shutdown:going to flush diaglog ...
2015-10-28t10:09:21.511+0800 I NETWORK [Signalprocessingthread] shutdown:going to close sockets ...
2015-10-28t10:09:21.512+0800 I STORAGE [signalprocessingthread] shutdown:waiting for FS preallocator ...
2015-10-28t10:09:21.512+0800 I STORAGE [signalprocessingthread] shutdown:final commit ...
2015-10-28t10:09:21.512+0800 I JOURNAL [Signalprocessingthread] journalcleanup ...
2015-10-28t10:09:21.512+0800 I JOURNAL [Signalprocessingthread] Removejournalfiles
2015-10-28t10:09:21.515+0800 I JOURNAL [signalprocessingthread] terminating durability thread ...
2015-10-28t10:09:21.615+0800 I JOURNAL [JOURNAL writer] JOURNAL writer thread stopped
2015-10-28t10:09:21.615+0800 I JOURNAL [durability] durability thread stopped
2015-10-28t10:09:21.615+0800 I STORAGE [signalprocessingthread] shutdown:closing All Files ...
2015-10-28t10:09:21.618+0800 I STORAGE [Signalprocessingthread] Closeallfiles () finished
2015-10-28t10:09:21.618+0800 I STORAGE [Signalprocessingthread] shutdown:removing FS lock ...
2015-10-28t10:09:21.618+0800 I CONTROL [Signalprocessingthread] dbexit:rc:0

# # #修复启动过程中的两个警告, warning about starting MONGO with the root user is ignored first
# echo "Never" >/sys/kernel/mm/transparent_hugepage/enabled
# echo "Never" >/sys/kernel/mm/transparent_hugepage/defrag

# # #再次重启, followed by the background process,
# Mongod--dbpath/data/mongodata &

# # #查看启动后的进程
# ps-ef|grep MONGO |grep-v grep
Root 11115 27956 0 10:11 pts/2 00:00:00 mongod--dbpath/data/mongodata
# lsof-i:27017
COMMAND PID USER FD TYPE DEVICE size/off NODE NAME
Mongod 11115 root 5u IPv4 50567119 0t0 TCP *:27017 (LISTEN)

# # #使用mongo连接到mongod
# MONGO
MongoDB Shell version:3.0.6
Connecting To:test
2015-10-28t10:14:30.685+0800 I NETWORK [Initandlisten] connection accepted from 127.0.0.1:53907 #1 (1 connection now OPEN )
Server has startup warnings:
2015-10-28t10:11:49.217+0800 i CONTROL [initandlisten] * * Warning:you is running this process as the root user, which I s not recommended.
2015-10-28t10:11:49.217+0800 I CONTROL [Initandlisten]
> Help
Db.help () Help on DB methods
Db.mycoll.help () Help on collection methods
Sh.help () sharding Helpers
Rs.help () Replica set helpers
Help Admin Administrative Help
Help connect connecting to a DB help
Help keys key shortcuts
Help Misc Misc Things to Know
Help Mr MapReduce


Show DBS Show Database names
Show collections show collections in current database
Show users show users in current database
Show profile Show most recent system.profile entries with time >= 1ms
Show logs show the accessible logger names
Show log [name] prints out the last segment of log in memory, ' global ' is default
Use <db_name> Set current database
Db.foo.find () List objects in collection Foo
Db.foo.find ({a:1}) List objects in Foo where a = = 1
It result of the last line evaluated; Use to further iterate
dbquery.shellbatchsize = X Set default number of items to display on shell
Exit quit the MONGO shell
> db.getcollection ("Version");
Test.version
> Exit
Bye

Third, MongoDB related tools
# # #在安装文件下有README, describes common MongoDB-related command-line tools
# More/usr/local/mongodb/readme
MongoDB README
Welcome to mongodb!
Components

Bin/mongod-the database process.
Bin/mongos-sharding Controller.
Bin/mongo-the Database Shell (uses interactive JavaScript).

UTILITIES

Bin/mongodump-mongodb dump tool-for backups, snapshots, etc.
Bin/mongorestore-mongodb Restore a Dump
Bin/mongoexport-export a single collection to test (JSON, CSV)
Bin/mongoimport-import from JSON or CSV
Bin/mongofiles-utility for putting and getting files from MongoDB Gridfs
Bin/mongostat-show Performance Statistics

RUNNING

For command line options invoke:

$./mongod--help

To run a single server database:

$ mkdir/data/db
$./mongod
$
$ # The MONGO JavaScript shell connects to localhost and test database by default:
$./mongo
> Help

DRIVERS

Client drivers for most programming languages is available at mongodb.org. Use the
Shell ("MONGO") for administrative tasks.

# # #获取单个命令用法
# <command>--help
# Mongod--help|more
Options:

General Options:
-H [--help] Show this usage information
--version Show version Information

# Mongod--version
DB version v3.0.6
Git version:1ef45a23a4c5e3480ac919b28afcba3c615488f2

Copyright NOTICE: This article for Bo Master original article, welcome to spread, spread please be sure to indicate the source.

Fast installation of MongoDB under Linux

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.