mongodb之rpm包安裝,mongodbrpm包

來源:互聯網
上載者:User

mongodb之rpm包安裝,mongodbrpm包
MonfoDB是開來源文件資料庫,提供共效能、高可用、自動擴充等

MongoDB中記錄是文檔,其是欄位和值組成的對結構。mongodb文檔類似JSON對象,欄位的值可以包含其它文檔、數組、文檔的數組。記錄組織成collection,相當於表。參考:



使用文檔的優點是:
文檔對應很多程式設計語言的內生資料對象
內嵌文檔和數組減少了join的開銷
動態schema支援順暢多態

關鍵功能:
高效能:
mongodb提供高效能資料持久。特別是:
  支援內嵌資料模型減少了資料庫系統的I/O
  索引支援快速查詢且內嵌文檔和數組可以包含鍵

高可用:
mongodb提供高可用的是replica sets
  自動失敗切換
  資料冗餘
replica set是一組mongodb伺服器,它們維護這同一個資料集,提供冗餘,增加資料可用性。

自動水平擴充:
水平擴充是mongodb的核心功能。
    在叢集上自動共用分布式資料
    replica sets能為低延遲,高輸送量的應用提供最終一致性讀。


安裝:

0
環境
[root@host2 ~]# uname -a
Linux host2 2.6.32-504.3.3.el6.x86_64 #1 SMP Wed Dec 17 01:55:02 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@host2 ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m

1
配置yum源
[root@host2 ~]# vi /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

2
用命令$ yum install -y mongodb-org安裝,該命令將自動安裝下面四個包
mongodb-org-server:This package contains the mongod daemon and associated configuration and init scripts.
mongodb-org-mongos:This package contains the mongos daemon.
mongodb-org-shell:This package contains the mongo shell.
mongodb-org-tools:This package contains the following MongoDB tools: mongoimport bsondump, mongodump, mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop.

要安裝特定版本,可以使用命令yum install -y mongodb-org-2.6.1 mongodb-org-server-2.6.1 mongodb-org-shell-2.6.1 mongodb-org-mongos-2.6.1 mongodb-org-tools-2.6.1

目前用yum install -y mongodb-org命令安裝的是2.6.7的版本
[root@host2 ~]# yum install -y mongodb-org
.。。。
Installed:
  mongodb-org.x86_64 0:2.6.7-1                                                  

Dependency Installed:
  mongodb-org-mongos.x86_64 0:2.6.7-1    mongodb-org-server.x86_64 0:2.6.7-1   
  mongodb-org-shell.x86_64 0:2.6.7-1     mongodb-org-tools.x86_64 0:2.6.7-1    

Complete!
[root@host2 ~]#

3
為防止自動更新,在/etc/yum.conf中加上如下行:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

4
配置selinux
semanage port -a -t mongod_port_t -p tcp 27017

$ yum search semanage
$ yum -y install libsemanage-python.x86_64

或者
 /etc/selinux.conf中
SELINUX=permissive/SELINUX=disabled

或者
[root@host2 ~]# getenforce
Enforcing
[root@host2 ~]# setenforce 0
[root@host2 ~]# getenforce
Permissive

5
查看
預設的資料檔案在/var/lib/mongo裡,記錄檔在/var/log/mongodb裡,
可以在設定檔/etc/mongod.conf裡更改資料和記錄檔目錄。
以使用者mongod運行。若以其它使用者運行,要改其資料目錄和日誌目錄的存取權限。

資料檔案相關
[root@host2 ~]# ll /var/lib/
。。。
drwxr-xr-x. 2 mongod  mongod  4096 1月  14 07:15 mongo
[root@host2 ~]# ll /var/lib/mongo
總用量 0

記錄檔相關
[root@host2 ~]# ll /var/log/
。。。
drwxr-xr-x. 2 mongod mongod    4096 2月   2 14:35 mongodb
[root@host2 ~]# ll /var/log/mongodb/
總用量 0
-rw-r-----. 1 mongod mongod 0 1月  14 07:15 mongod.log

6
運行mongodb
[root@host2 ~]# /etc/init.d/mongod status
mongod 已停
[root@host2 ~]# service mongod status
mongod is stopped
[root@host2 ~]# service mongod start
Starting mongod:                                           [  OK  ]

7
查驗:
[root@host2 ~]# netstat -ntpl | grep mongod
tcp        0      0 127.0.0.1:27017             0.0.0.0:*                   LISTEN      5334/mongod         

[root@host2 ~]# ll /var/lib/mongo/
總用量 81936
drwxr-xr-x. 2 mongod mongod     4096 2月   2 15:16 journal
-rw-------. 1 mongod mongod 67108864 2月   2 15:16 local.0
-rw-------. 1 mongod mongod 16777216 2月   2 15:16 local.ns
-rwxr-xr-x. 1 mongod mongod        5 2月   2 15:16 mongod.lock
drwxr-xr-x. 2 mongod mongod     4096 2月   2 15:16 _tmp

8
配置開機啟動
chkconfig mongod on

9
命令列進入測試
[root@host2 ~]# mongo
MongoDB shell version: 2.6.7
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
> show dbs
admin  (empty)
local  0.078GB
> db.version();
2.6.7
>
>
> 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
>
> exit
bye
[root@host2 ~]#

10
停止
sudo service mongod stop

可以通過記錄檔 /var/log/mongodb/mongod.log查看mongod進程的錯誤和相關資訊。


參考:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/


-----------------

轉載請著明出處:
blog.csdn.net/beiigang

相關文章

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.