Quick install of MongoDB in Linux
MongoDB is a non-relational database (NoSql) that is very popular in the IT industry. Its flexible data storage method is favored by current IT practitioners. MongoDB implements the object-oriented idea (OO idea), and each record in MongoDB is a Document object. The biggest advantage of MongoDB is that all data persistence operations can easily implement CRUD operations without the need for developers to manually write SQL statements. This article describes how to quickly install mongodb for your reference.
1. install and configure mongodb
Step 1: set the system environment and make sure the default port 27107 is available
### Current Environment
# 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 you can 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: Decompress the downloaded file
# Pwd
/Usr/local/src
# Tar-xvf mongodb-linux-x86_64-rhel62-3.0.6.gz.
Step 4: Copy and decompress the file 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: Set 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 directory
# Mkdir-p/data/upload data
Ii. Start and verify mongodb
### Start mongo
# Mongod -- dbpath/data/mongodata
### The following information is output after startup
2015-10-28T10: 03: 33.100 + 0800 I JOURNAL [initandlisten] journal dir =/data/internal data/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/embedded data 64-bit host = java_2
2015-10-28T10: 03: 33.401 + 0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is 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 'alway '.
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 'alway '.
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
T10: 03: 33.402 + 0800 I CONTROL [initandlisten] build info: Linux ip-10-67-194-123 2.6.32-220. el6.x86 _ 64 #1 SMP Wed Nov 9 08:03:13 EST 2011 x86_64 BOOST_LIB_VERSION = listen 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/encrypted data "}}
2015-10-28T10: 03: 33.404 + 0800 I INDEX [initandlisten] allocating new ns file/data/partition data/local. ns, filling with zeroes...
2015-10-28T10: 03: 33.491 + 0800 I STORAGE [FileAllocator] allocating new datafile/data/partition data/local.0, filling with zeroes...
2015-10-28T10: 03: 33.491 + 0800 I STORAGE [FileAllocator] creating directory/data/parse data/_ tmp
2015-10-28T10: 03: 33.497 + 0800 I STORAGE [FileAllocator] done allocating datafile/data/partition data/local.0, size: 64 MB, took 0.001 secs
2015-10-28T10: 03: 33.511 + 0800 I NETWORK [initandlisten] waiting for connections on port 27017
### Stop mongo and directly use ctrl + c
^ C2015-10-28T10: 09: 21.510 + 0800 I CONTROL [signalProcessingThread] got signal 2 (Interrupt), will 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
T10: 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
### Fix the two warnings during the startup process. ignore the warnings about using the root user to start mongo.
# Echo "never">/sys/kernel/mm/transparent_hugepage/enabled
# Echo "never">/sys/kernel/mm/transparent_hugepage/defrag
### Restart the instance and then place it in the background process,
# Mongod -- dbpath/data/mongodata &
### View started processes
# Ps-ef | grep mongo | grep-v grep
Root 11115 27956 0 00:00:00 pts/2 mongod -- dbpath/data/parse data
# Lsof-I: 27017
Command pid user fd type device size/OFF NODE NAME
Mongod 11115 root 5u IPv4 50567119 0t0 TCP *: 27017 (LISTEN)
### Connect to mongod using mongo
# 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:
T10: 11: 49.217 + 0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
T10: 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 ing to a db help
Help keys key shortcuts
Help misc things to know
Help mr mapreduce
Show dbs show database names
Show collections in current database
Show users in current database
Show profile show most recent system. profile entries with time> = 1 ms
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
Iii. mongodb related tools
### README in the installation file, which 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/Export-Export a single collection to test (JSON, CSV)
Bin/Export Import-Import from JSON or CSV
Bin/program files-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 ages are available at mongodb.org. Use
Shell ("mongo") for administrative tasks.
### Obtain the usage of a single command
# <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
For more information about MongoDB, see the following links:
MongoDB 3.0 official version released and downloaded
CentOS compilation and installation of MongoDB
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: