MongoDB是一個基于分布式文件存儲的數(shù)據(jù)庫。由C++語言編寫。旨在為WEB應用提供可擴展的高性能數(shù)據(jù)存儲解決方案。
是一個介于關(guān)系數(shù)據(jù)
庫和非關(guān)系數(shù)據(jù)庫之間的產(chǎn)品,是非關(guān)系數(shù)據(jù)庫當中功能最豐富,最像關(guān)系數(shù)據(jù)庫的。他支持的數(shù)據(jù)結(jié)構(gòu)非常松散,是類似json的bson格式,因此可以存儲
比較復雜的數(shù)據(jù)類型。Mongo最大的特點是他支持的查詢語言非常強大,其語法有點類似于面向?qū)ο蟮牟樵冋Z言,幾乎可以實現(xiàn)類似關(guān)系數(shù)據(jù)庫單表查詢的絕大
部分功能,而且還支持對數(shù)據(jù)建立索引。
MongoDB
是目前在IT行業(yè)非常流行的一種非關(guān)系型數(shù)據(jù)庫(NOSQL),其靈活的數(shù)據(jù)存儲方式備受當前IT從業(yè)人員的青睞。MongoDB很好的實現(xiàn)了面向?qū)ο蟮?思想(OO思想),在MongoDB中
每一條記錄都是一個Document對象。MongoDB最大的優(yōu)勢在于所有的數(shù)據(jù)持久操作都無需開發(fā)人員手動編寫SQL語句,直接調(diào)用方法就可以輕松的
實現(xiàn)CRUD操作。本文介紹了如何快速安裝mongodb供大家參考。
一、安裝配置mongodb
useradd mongodb
Step 1: 設(shè)置系統(tǒng)環(huán)境及確保缺省端口27107可用
###當前環(huán)境
cat /etc/issue
# vi /etc/selinux/config
SELINUX=disabled
Step 2: 下載安裝文件
下載地址: https://www.mongodb.org/downloads.
或者直接在命令提示符下使用curl命令下載
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.1.tgz
Step 3: 解壓下載的文件
# pwd
/home/mongo
# tar -xvf mongodb-linux-x86_64-rhel62-3.2.1.gz ###注,本文直接從網(wǎng)站下載,所以文件為.gz
點擊(此處)折疊或打開

專注于為中小企業(yè)提供網(wǎng)站制作、成都網(wǎng)站設(shè)計服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)五通橋免費做網(wǎng)站提供優(yōu)質(zhì)的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
-
[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: 復制解壓文件到運行目錄
[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: 設(shè)置環(huán)境變量
[mongo@mysql ~]$ vi .bash_profile
PATH=$PATH:$HOME/bin:/home/mongo/mongo/bin
export PATH
Step 6: 創(chuàng)建數(shù)據(jù)目錄
# mkdir -p /data/mongodata
二、啟動及驗證mongodb
###啟動mongo
# mongod --dbpath /home/mongo/mongo/data
###以下內(nèi)容為啟動后輸出的相關(guān)信息
[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_64
2016-01-11T13:08:33.684+0800 I CONTROL [initandlisten] target_arch: x86_64
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
###停止mongo,直接使用ctrl + c
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
###修復啟動過程中的兩個警告,關(guān)于使用root用戶啟動mongo的警告先忽略
# echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
# echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
###再次重啟,后置于后臺進程,
# mongod --dbpath /home/mongo/mongo/data &
###查看啟動后的進程
# ps -ef|grep mongo
###使用mongo連接到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
三、mongodb相關(guān)工具
###在安裝文件下有README,描述了常用的mongodb相關(guān)命令行工具
# 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.
###獲取單個命令用法
# --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
本文名稱:CentOS6.3下快速安裝MongoDB3.2.1
標題URL:http://chinadenli.net/article32/jhhpsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、搜索引擎優(yōu)化、全網(wǎng)營銷推廣、定制開發(fā)、移動網(wǎng)站建設(shè)、商城網(wǎng)站
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)