Mongodb学习笔记--Mongodb 安装

6685阅读 0评论2012-05-20 xiaozhenggang
分类:Mysql/postgreSQL

本文讲述如何通过rpm包进行安装,适用操作系统:RHEL,CentOS,Fedora

实验环境:CentOS 5.8 i386 fianl

具体步骤如下:

1)配置官方YUM源

点击(此处)折叠或打开

  1. [root@localhost ~]# vim /etc/yum.repos.d/10gen.repo
  2. [root@localhost ~]# cat /etc/yum.repos.d/10gen.repo
  3. [10gen]
  4. name=10gen Repository
  5. baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
  6. gpgcheck=0
  7. enabled=1
64位机器源配置文件如下

点击(此处)折叠或打开

  1. [root@localhost ~]# vim /etc/yum.repos.d/10gen.repo
  2. [root@localhost ~]# cat /etc/yum.repos.d/10gen.repo
  3. [10gen]
  4. name=10gen Repository
  5. baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
  6. gpgcheck=0
  7. enabled=1
#############################################################################################
#其中,官方源中包括以下软件包
#mongo-10gen 这个包包含了最新最稳定的mongodb工具
#mongo-server-10gen 这个包包含了最新最稳定版本的mongod和mongos守护进程及相关的配置和初始化脚本
#
#mongo18-10gen 这个包包含了之前发行版中的mongodb工具
#mongo18-server-10gen 这个包包含了前一个稳定版的mongod和mongos守护进程及相关的配置和初始化脚本
##############################################################################################

2)系统更新

点击(此处)折叠或打开

  1. [root@localhost ~]# yum update

3)安装mongodb

点击(此处)折叠或打开

  1. [root@localhost ~]# yum install mongo-10gen mongo-10gen-server
看到提示说明安装成功

点击(此处)折叠或打开

  1. Installed:
  2.   mongo-10gen.i686 0:2.0.5-mongodb_1 mongo-10gen-server.i686 0:2.0.5-mongodb_1

4)配置mongodb
配置文件为:/etc/mongod.conf
初始化脚本为:/etc/rc.d/init.d/mongod
数据存储路径:/var/lib/mongo/
日志文件存储路径:/var/log/mongo/
守护进程运行用户为:mongod
以上均为默认值

5)Mongodb控制

加入开机启动

点击(此处)折叠或打开

  1. [root@localhost ~]# chkconfig mongod on
  2. [root@localhost ~]# chkconfig --list | grep mongod
  3. mongod     0:off    1:off    2:on    3:on    4:on    5:on    6:off

启动mongodb

点击(此处)折叠或打开

  1. [root@localhost ~]# service mongod start
  2. Starting mongod: all output going to: /var/log/mongo/mongod.log
  3. forked process: 26351
  4.                                                            [ OK ]

停止mongodb

点击(此处)折叠或打开

  1. [root@localhost ~]# service mongod stop
  2. Stopping mongod: [ OK ]

重启mongodb

点击(此处)折叠或打开

  1. [root@localhost ~]# service mongod restart
  2. Stopping mongod: [ OK ]
  3. Starting mongod: all output going to: /var/log/mongo/mongod.log
  4. forked process: 26420
  5.                                                            [ OK ]

6)简单使用

查找

点击(此处)折叠或打开

  1. [root@localhost ~]# mongo
  2. MongoDB shell version: 2.0.5
  3. connecting to: test
  4. > db.test.save( { a: 1})
  5. > db.test.find()
  6. { "_id" : ObjectId("4fb83ca7698712e93dad12a7"), "a" : 1 }

插入

点击(此处)折叠或打开

  1. > doc = { author:'joe', created : new Date('03/28/2009')}
  2. { "author" : "joe", "created" : ISODate("2009-03-27T16:00:00Z") }
  3. > db.test.insert(doc)
  4. > db.test.find()
  5. { "_id" : ObjectId("4fb83ca7698712e93dad12a7"), "a" : 1 }
  6. { "_id" : ObjectId("4fb83e2c698712e93dad12a8"), "author" : "joe", "created" : ISODate("2009-03-27T16:00:00Z") }

更新

点击(此处)折叠或打开

  1. > db.test.update({author : 'joe'}, {$inc: { check: 1000 }});
  2. > db.test.find()
  3. { "_id" : ObjectId("4fb83ca7698712e93dad12a7"), "a" : 1 }
  4. { "_id" : ObjectId("4fb83e2c698712e93dad12a8"), "author" : "joe", "check" : 1000, "created" : ISODate("2009-03-27T16:00:00Z") }

删除

点击(此处)折叠或打开

  1. > db.test.remove({a:1});
  2. > db.test.find()
  3. { "_id" : ObjectId("4fb83e2c698712e93dad12a8"), "author" : "joe", "check" : 1000, "created" : ISODate("2009-03-27T16:00:00Z") }



上一篇:mysql备份脚本之SELECT INTO OUTFILE
下一篇:Mongodb学习笔记--Collections