溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

CentOS 6.3下快速安裝MongoDB 3.2.1

發布時間:2020-08-09 21:21:41 來源:ITPUB博客 閱讀:196 作者:wg0411 欄目:關系型數據庫
MongoDB是一個基于分布式文件存儲的數據庫。由C++語言編寫。旨在為WEB應用提供可擴展的高性能數據存儲解決方案。
是一個介于關系數據 庫和非關系數據庫之間的產品,是非關系數據庫當中功能最豐富,最像關系數據庫的。他支持的數據結構非常松散,是類似json的bson格式,因此可以存儲 比較復雜的數據類型。Mongo最大的特點是他支持的查詢語言非常強大,其語法有點類似于面向對象的查詢語言,幾乎可以實現類似關系數據庫單表查詢的絕大 部分功能,而且還支持對數據建立索引。

MongoDB 是目前在IT行業非常流行的一種非關系型數據庫(NoSql),其靈活的數據存儲方式備受當前IT從業人員的青睞。MongoDB很好的實現了面向對象的 思想(OO思想),在MongoDB中 每一條記錄都是一個Document對象。MongoDB最大的優勢在于所有的數據持久操作都無需開發人員手動編寫SQL語句,直接調用方法就可以輕松的 實現CRUD操作。本文介紹了如何快速安裝mongodb供大家參考。

一、安裝配置mongodb
useradd mongodb

Step 1: 設置系統環境及確保缺省端口27107可用
###當前環境
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  ###注,本文直接從網站下載,所以文件為.gz

點擊(此處)折疊或打開

  1. [mongo@mysql ~]$ tar -xvf mongodb-linux-x86_64-3.2.1.tgz
  2. mongodb-linux-x86_64-3.2.1/README
  3. tar: mongodb-linux-x86_64-3.2.1/README: time stamp 2016-01-12 02:37:17 is 48732.469243332 s in the future
  4. mongodb-linux-x86_64-3.2.1/THIRD-PARTY-NOTICES
  5. 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
  6. mongodb-linux-x86_64-3.2.1/MPL-2
  7. 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
  8. mongodb-linux-x86_64-3.2.1/GNU-AGPL-3.0
  9. 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
  10. mongodb-linux-x86_64-3.2.1/bin/mongodump
  11. 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
  12. mongodb-linux-x86_64-3.2.1/bin/mongorestore
  13. 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
  14. mongodb-linux-x86_64-3.2.1/bin/mongoexport
  15. 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
  16. mongodb-linux-x86_64-3.2.1/bin/mongoimport
  17. 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
  18. mongodb-linux-x86_64-3.2.1/bin/mongostat
  19. 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
  20. mongodb-linux-x86_64-3.2.1/bin/mongotop
  21. 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
  22. mongodb-linux-x86_64-3.2.1/bin/bsondump
  23. 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
  24. mongodb-linux-x86_64-3.2.1/bin/mongofiles
  25. 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
  26. mongodb-linux-x86_64-3.2.1/bin/mongooplog
  27. 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
  28. mongodb-linux-x86_64-3.2.1/bin/mongoperf
  29. 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
  30. mongodb-linux-x86_64-3.2.1/bin/mongod
  31. 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
  32. mongodb-linux-x86_64-3.2.1/bin/mongos
  33. 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
  34. mongodb-linux-x86_64-3.2.1/bin/mongo
  35. 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: 設置環境變量
[mongo@mysql ~]$ vi .bash_profile 
PATH=$PATH:$HOME/bin:/home/mongo/mongo/bin
export PATH

Step 6: 創建數據目錄
# mkdir -p /data/mongodata

二、啟動及驗證mongodb
###啟動mongo
# mongod --dbpath /home/mongo/mongo/data


###以下內容為啟動后輸出的相關信息
[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


###修復啟動過程中的兩個警告,關于使用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相關工具
###在安裝文件下有README,描述了常用的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.

###獲取單個命令用法
# --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 

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女