Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Quick installation of MongoDB 3.2.1 under CentOS 6.3

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MongoDB is a database based on distributed file storage. Written in C++ language. Designed to provide scalable high-performance data storage solutions for WEB applications.

It is a product between relational database and non-relational database, which is the most functional and most like relational database in non-relational database. The data structure he supports is very loose, which is similar to json's bson format, so it can store more complex data types. The most important feature of Mongo is that the query language it supports is very powerful, and its syntax is somewhat similar to the object-oriented query language. It can almost achieve most of the functions similar to the single table query of relational database, and also supports the establishment of data indexing.

MongoDB is a very popular non-relational database (NoSql) in the IT industry, and its flexible data storage method is favored by current IT employees. MongoDB well implements the object-oriented idea (OO idea). In MongoDB, each record is a Document object. The biggest advantage of MongoDB is that all data persistence operations do not need developers to write SQL statements manually, and you can easily implement CRUD operations by calling methods directly. This article describes how to quickly install mongodb for your reference.

1. Install and configure mongodb

Useradd mongodb

Step 1: set up the system environment and make sure the default port 27107 is available

# current environment

Cat / etc/issue

# vi / etc/selinux/config

SELINUX=disabled

Step 2: download installation files

Download address: https://www.mongodb.org/downloads.

Or use the curl command to download directly from the command prompt

Curl-O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.1.tgz

Step 3: extract downloaded files

# pwd

/ home/mongo

# tar-xvf mongodb-linux-x86_64-rhel62-3.2.1.gz # Note, this article is downloaded directly from the website, so the file is .gz

Click (here) to collapse or open

[mongo@mysql ~] $tar-xvf mongodb-linux-x86_64-3.2.1.tgz

Mongodb-linux-x86_64-3.2.1/README

Tar: mongodb-linux-x86_64-3.2.1/README: time stamp 2016-01-12 02:37:17 is 48732.469243332 s in the future

Mongodb-linux-x86_64-3.2.1/THIRD-PARTY-NOTICES

Tar: mongodb-linux-x86_64-3.2.1/THIRD-PARTY-NOTICES: time stamp 2016-01-12 02:37:17 is 48732.468806195 s in the future

Mongodb-linux-x86_64-3.2.1/MPL-2

Tar: mongodb-linux-x86_64-3.2.1/MPL-2: time stamp 2016-01-12 02:37:17 is 48732.468729339 s in the future

Mongodb-linux-x86_64-3.2.1/GNU-AGPL-3.0

Tar: mongodb-linux-x86_64-3.2.1/GNU-AGPL-3.0: time stamp 2016-01-12 02:37:17 is 48732.468416571 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongodump

Tar: mongodb-linux-x86_64-3.2.1/bin/mongodump: time stamp 2016-01-12 02:37:30 is 48745.395380045 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongorestore

Tar: mongodb-linux-x86_64-3.2.1/bin/mongorestore: time stamp 2016-01-12 02:37:28 is 48743.308178108 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongoexport

Tar: mongodb-linux-x86_64-3.2.1/bin/mongoexport: time stamp 2016-01-12 02:37:25 is 48740.256976344 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongoimport

Tar: mongodb-linux-x86_64-3.2.1/bin/mongoimport: time stamp 2016-01-12 02:37:26 is 48741.205864231 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongostat

Tar: mongodb-linux-x86_64-3.2.1/bin/mongostat: time stamp 2016-01-12 02:37:23 is 48738.158042438 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongotop

Tar: mongodb-linux-x86_64-3.2.1/bin/mongotop: time stamp 2016-01-12 02:37:31 is 48746.110027909 s in the future

Mongodb-linux-x86_64-3.2.1/bin/bsondump

Tar: mongodb-linux-x86_64-3.2.1/bin/bsondump: time stamp 2016-01-12 02:37:21 is 48736.074523763 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongofiles

Tar: mongodb-linux-x86_64-3.2.1/bin/mongofiles: time stamp 2016-01-12 02:37:24 is 48739.014639938 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongooplog

Tar: mongodb-linux-x86_64-3.2.1/bin/mongooplog: time stamp 2016-01-12 02:37:33 is 48747.960322499 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongoperf

Tar: mongodb-linux-x86_64-3.2.1/bin/mongoperf: time stamp 2016-01-12 02:49:50 is 49484.63946251 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongod

Tar: mongodb-linux-x86_64-3.2.1/bin/mongod: time stamp 2016-01-12 02:49:50 is 49484.277970529 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongos

Tar: mongodb-linux-x86_64-3.2.1/bin/mongos: time stamp 2016-01-12 02:49:49 is 49483.120921568 s in the future

Mongodb-linux-x86_64-3.2.1/bin/mongo

Tar: mongodb-linux-x86_64-3.2.1/bin/mongo: time stamp 2016-01-12 02:49:50 is 49483.896681132 s in the future

Step 4: copy the extracted files to the running directory

[mongo@mysql ~] $pwd

/ home/mongo

[mongo@mysql] $mv mongodb-linux-x86_64-3.2.1 mongo

[mongo@mysql ~] $ll

Total 55108

Drwxrwxr-x. 3 mongo mongo 4096 Jan 11 13:05 mongo

-rw-r-. 1 mongo mongo 56419937 Jan 21 2016 mongodb-linux-x86_64-3.2.1.tgz

[mongo@mysql ~] $

Step 5: setting environment variables

[mongo@mysql ~] $vi .bash _ profile

PATH=$PATH:$HOME/bin:/home/mongo/mongo/bin

Export PATH

Step 6: create a data directory

# mkdir-p / data/mongodata

2. Start and verify mongodb

# start mongo

# mongod-- dbpath / home/mongo/mongo/data

# the following is the relevant information output after startup

[mongo@mysql ~] $mongod-dbpath / home/mongo/mongo/data/

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] MongoDB starting: pid=12579 port=27017 dbpath=/home/mongo/mongo/data/ 64-bit host=mysql

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] db version v3.2.1

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] allocator: tcmalloc

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] modules: none

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] build environment:

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] distarch: x86

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] target_arch: x86

2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] options: {storage: {dbPath: "/ home/mongo/mongo/data/"}}

2016-01-11T13:08:33.725+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction= (threads_max=4), config_base=false,statistics= (fast), log= (enabled=true,archive=true,path=journal,compressor=snappy), file_manager= (close_idle_time=100000), checkpoint= (wait=60,log_size=2GB), statistics_log= (wait=0)

2016-01-11T13:08:33.828+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory'/ home/mongo/mongo/data/diagnostic.data'

2016-01-11T13:08:33.829+0800 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker

2016-01-11T13:08:33.844+0800 I NETWORK [initandlisten] waiting for connections on port 27017

# stop mongo and use ctrl + c directly

F ^ C2016-01-11T13:09:46.734+0800 I CONTROL [signalProcessingThread] got signal 2 (Interrupt), will terminate after current cmd ends

2016-01-11T13:09:46.734+0800 I FTDC [signalProcessingThread] Shutting down full-time diagnostic data capture

2016-01-11T13:09:46.735+0800 I CONTROL [signalProcessingThread] now exiting

2016-01-11T13:09:46.735+0800 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...

2016-01-11T13:09:46.735+0800 I NETWORK [signalProcessingThread] closing listening socket: 5

2016-01-11T13:09:46.735+0800 I NETWORK [signalProcessingThread] closing listening socket: 6

2016-01-11T13:09:46.735+0800 I NETWORK [signalProcessingThread] removing socket file: / tmp/mongodb-27017.sock

2016-01-11T13:09:46.737+0800 I NETWORK [signalProcessingThread] shutdown: going to flush diaglog...

2016-01-11T13:09:46.737+0800 I NETWORK [signalProcessingThread] shutdown: going to close sockets...

2016-01-11T13:09:46.737+0800 I STORAGE [signalProcessingThread] WiredTigerKVEngine shutting down

2016-01-11T13:09:46.781+0800 I STORAGE [signalProcessingThread] shutdown: removing fs lock...

2016-01-11T13:09:46.781+0800 I CONTROL [signalProcessingThread] dbexit: rc: 0

# repair two warnings during startup. Ignore the warning about using root users to start mongo.

# echo "never" > / sys/kernel/mm/transparent_hugepage/enabled

# echo "never" > / sys/kernel/mm/transparent_hugepage/defrag

# restart again and put it in the background process

# mongod-- dbpath / home/mongo/mongo/data &

# View the process after startup

# ps-ef | grep mongo

# use mongo to connect to mongod

# mongo

MongoDB shell version: 3.2.1

> 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 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

# there is README under the installation file, which describes the commonly used command line tools related to mongodb

# 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 are available at mongodb.org. Use the

Shell ("mongo") for administrative tasks.

# get a single command usage

#-help

# mongod-- help | more

Options:

General options:

-h [--help] show this usage information

-- version show version information

# mongod-version

Db version v3.2.1

Git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report