码迷,mamicode.com
首页 > 数据库 > 详细

mongodb之rpm包安装

时间:2015-02-13 16:35:38      阅读:417      评论:0      收藏:0      [点我收藏+]

标签:mongodb   install   

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

mongodb之rpm包安装

标签:mongodb   install   

原文地址:http://blog.csdn.net/beiigang/article/details/43794885

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!