本文讲述如何通过rpm包进行安装,适用操作系统:RHEL,CentOS,Fedora
实验环境:CentOS 5.8 i386 fianl
具体步骤如下:
1)配置官方YUM源
- [root@localhost ~]# vim /etc/yum.repos.d/10gen.repo
- [root@localhost ~]# cat /etc/yum.repos.d/10gen.repo
- [10gen]
- name=10gen Repository
- baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
- gpgcheck=0
- enabled=1
64位机器源配置文件如下
- [root@localhost ~]# vim /etc/yum.repos.d/10gen.repo
- [root@localhost ~]# cat /etc/yum.repos.d/10gen.repo
- [10gen]
- name=10gen Repository
- baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
- gpgcheck=0
- enabled=1
#############################################################################################
#其中,官方源中包括以下软件包
#mongo-10gen 这个包包含了最新最稳定的mongodb工具
#mongo-server-10gen 这个包包含了最新最稳定版本的mongod和mongos守护进程及相关的配置和初始化脚本
#
#mongo18-10gen 这个包包含了之前发行版中的mongodb工具
#mongo18-server-10gen 这个包包含了前一个稳定版的mongod和mongos守护进程及相关的配置和初始化脚本
##############################################################################################
2)系统更新
- [root@localhost ~]# yum update
3)安装mongodb
- [root@localhost ~]# yum install mongo-10gen mongo-10gen-server
看到提示说明安装成功
- Installed:
- 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控制
加入开机启动
- [root@localhost ~]# chkconfig mongod on
- [root@localhost ~]# chkconfig --list | grep mongod
- mongod 0:off 1:off 2:on 3:on 4:on 5:on 6:off
启动mongodb
- [root@localhost ~]# service mongod start
- Starting mongod: all output going to: /var/log/mongo/mongod.log
- forked process: 26351
- [ OK ]
停止mongodb
- [root@localhost ~]# service mongod stop
- Stopping mongod: [ OK ]
重启mongodb
- [root@localhost ~]# service mongod restart
- Stopping mongod: [ OK ]
- Starting mongod: all output going to: /var/log/mongo/mongod.log
- forked process: 26420
- [ OK ]
6)简单使用
查找
- [root@localhost ~]# mongo
- MongoDB shell version: 2.0.5
- connecting to: test
- > db.test.save( { a: 1})
- > db.test.find()
- { "_id" : ObjectId("4fb83ca7698712e93dad12a7"), "a" : 1 }
插入
- > doc = { author:'joe', created : new Date('03/28/2009')}
- { "author" : "joe", "created" : ISODate("2009-03-27T16:00:00Z") }
- > db.test.insert(doc)
- > db.test.find()
- { "_id" : ObjectId("4fb83ca7698712e93dad12a7"), "a" : 1 }
- { "_id" : ObjectId("4fb83e2c698712e93dad12a8"), "author" : "joe", "created" : ISODate("2009-03-27T16:00:00Z") }
更新
- > db.test.update({author : 'joe'}, {$inc: { check: 1000 }});
- > db.test.find()
- { "_id" : ObjectId("4fb83ca7698712e93dad12a7"), "a" : 1 }
- { "_id" : ObjectId("4fb83e2c698712e93dad12a8"), "author" : "joe", "check" : 1000, "created" : ISODate("2009-03-27T16:00:00Z") }
删除
- > db.test.remove({a:1});
- > db.test.find()
- { "_id" : ObjectId("4fb83e2c698712e93dad12a8"), "author" : "joe", "check" : 1000, "created" : ISODate("2009-03-27T16:00:00Z") }
阅读(6700) | 评论(0) | 转发(0) |