Linux下安装MongoDB教程

SQL/NoSQL 2013-03-30 Linux,NoSQL,MongoDB

MongoDB是NoSQL中的一种,随着越来越多公司产品使用,已经开始逐步取代一些高性能查询的地位了。它使用简单,安装更简单。

一、下载MongoDB

-bash-3.2# wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.4.1.tgz
--2013-03-29 23:25:20--  http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.4.1.tgz
Resolving fastdl.mongodb.org... 205.251.212.177, 205.251.212.190, 205.251.212.16, ...
Connecting to fastdl.mongodb.org|205.251.212.177|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 93077588 (89M) [application/x-tar]
Saving to: `mongodb-linux-i686-2.4.1.tgz'

100%[============================================================================================================================>] 93,077,588   114K/s   in 14m 6s  

2013-03-29 23:39:27 (107 KB/s) - `mongodb-linux-i686-2.4.1.tgz' saved [93077588/93077588]

-bash-3.2# ls
db  install.log  install.log.syslog  logs  mongodb-linux-i686-2.4.1.tgz
-bash-3.2# 

二、解压,目录任意

-bash-3.2# tar -xvf mongodb-linux-i686-2.4.1.tgz 
mongodb-linux-i686-2.4.1/README
mongodb-linux-i686-2.4.1/THIRD-PARTY-NOTICES
mongodb-linux-i686-2.4.1/GNU-AGPL-3.0
mongodb-linux-i686-2.4.1/bin/mongodump
mongodb-linux-i686-2.4.1/bin/mongorestore
mongodb-linux-i686-2.4.1/bin/mongoexport
mongodb-linux-i686-2.4.1/bin/mongoimport
mongodb-linux-i686-2.4.1/bin/mongostat
mongodb-linux-i686-2.4.1/bin/mongotop
mongodb-linux-i686-2.4.1/bin/mongooplog
mongodb-linux-i686-2.4.1/bin/mongofiles
mongodb-linux-i686-2.4.1/bin/bsondump
mongodb-linux-i686-2.4.1/bin/mongoperf
mongodb-linux-i686-2.4.1/bin/mongosniff
mongodb-linux-i686-2.4.1/bin/mongod
mongodb-linux-i686-2.4.1/bin/mongos
mongodb-linux-i686-2.4.1/bin/mongo
-bash-3.2# 

三、创建一个存储数据的目录

-bash-3.2# mkdir db
-bash-3.2# ls
db  install.log  install.log.syslog  logs  mongodb-linux-i686-2.4.1  mongodb-linux-i686-2.4.1.tgz
-bash-3.2# 

四、创建一个存储日志的目录以及文件

-bash-3.2# mkdir log
-bash-3.2# ls
db  install.log  install.log.syslog  log  logs  mongodb-linux-i686-2.4.1  mongodb-linux-i686-2.4.1.tgz
-bash-3.2# cd log
-bash-3.2# touch mongodb.log
-bash-3.2# chmod 777 mongodb.log 
-bash-3.2# ls
mongodb.log
-bash-3.2# 

五、启动MongoDB、MongoDB 服务端的默认连接端口:27017

-bash-3.2# cd ..
-bash-3.2# ls
db  install.log  install.log.syslog  log  logs  mongodb-linux-i686-2.4.1  mongodb-linux-i686-2.4.1.tgz
-bash-3.2# cd mongodb-linux-i686-2.4.1
-bash-3.2# ./bin/mongod --dbpath=/root/db --logpath=/root/log/mongodb.log
Fri Mar 29 23:49:21.920 
Fri Mar 29 23:49:21.920 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Fri Mar 29 23:49:21.920 
all output going to: /root/log/mongodb.log
log file [/root/log/mongodb.log] exists; copied to temporary file [/root/log/mongodb.log.2013-03-29T15-49-21]

六、客户端连接

-bash-3.2# ./bin/mongo
MongoDB shell version: 2.4.1
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
Server has startup warnings: 
Fri Mar 29 23:49:21.942 [initandlisten] 
Fri Mar 29 23:49:21.942 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Fri Mar 29 23:49:21.942 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).
Fri Mar 29 23:49:21.942 [initandlisten] **       Note that journaling defaults to off for 32 bit and is currently off.
Fri Mar 29 23:49:21.942 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
Fri Mar 29 23:49:21.942 [initandlisten] 
> show dbs 
local   0.03125GB
>

七、查看日志

-bash-3.2# cat ../log/mongodb.log
Fri Mar 29 23:49:21.942 [initandlisten] MongoDB starting : pid=24536 port=27017 dbpath=/root/db 32-bit host=localhost.localdomain
Fri Mar 29 23:49:21.942 [initandlisten] 
Fri Mar 29 23:49:21.942 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Fri Mar 29 23:49:21.942 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).
Fri Mar 29 23:49:21.942 [initandlisten] **       Note that journaling defaults to off for 32 bit and is currently off.
Fri Mar 29 23:49:21.942 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
Fri Mar 29 23:49:21.942 [initandlisten] 
Fri Mar 29 23:49:21.942 [initandlisten] db version v2.4.1
Fri Mar 29 23:49:21.942 [initandlisten] git version: 1560959e9ce11a693be8b4d0d160d633eee75110
Fri Mar 29 23:49:21.942 [initandlisten] build info: Linux bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Fri Mar 29 23:49:21.942 [initandlisten] allocator: system
Fri Mar 29 23:49:21.942 [initandlisten] options: { dbpath: "/root/db", logpath: "/root/log/mongodb.log" }
Fri Mar 29 23:49:21.944 [FileAllocator] allocating new datafile /root/db/local.ns, filling with zeroes...
Fri Mar 29 23:49:21.944 [FileAllocator] creating directory /root/db/_tmp
Fri Mar 29 23:49:22.013 [FileAllocator] done allocating datafile /root/db/local.ns, size: 16MB,  took 0.068 secs
Fri Mar 29 23:49:22.013 [FileAllocator] allocating new datafile /root/db/local.0, filling with zeroes...
Fri Mar 29 23:49:22.082 [FileAllocator] done allocating datafile /root/db/local.0, size: 16MB,  took 0.068 secs
Fri Mar 29 23:49:22.083 [initandlisten] command local.$cmd command: { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0  reslen:37 139ms
Fri Mar 29 23:49:22.083 [initandlisten] waiting for connections on port 27017
Fri Mar 29 23:49:22.083 [websvr] admin web console waiting for connections on port 28017
Fri Mar 29 23:51:39.357 [initandlisten] connection accepted from 127.0.0.1:53490 #1 (1 connection now open)
Fri Mar 29 23:52:25.981 [conn1] end connection 127.0.0.1:53490 (0 connections now open)
-bash-3.2# 

MongoDB默认是不需要用户名与密码验证就能连接,这样不太安全,下一篇我们给MongoDB加上用户名与密码验证,提高安全性。

文字链接:《Linux下安装MongoDB教程

文章地址:http://www.qttc.net/201303298.html

除非标注,琼台博客所有博文均为原创,转载请加文字链接注明来源

乳名?小名?昵称?网名?均可

email,放心,我不会给你乱投广告的

想获得回访就把你的站点URL写上(没有留空)

[NOTICE]木要投放广告
[NOTICE]木要骂人,说不该说的话
[NOTICE]自由言论,但要遵纪守法

Comments 4

  • 我在ubuntu13下装了个MongoDB 2.2.4,但是每次启动都报错说是0.0.0.0:27017端口被占用。看书上说是因为有别的MongoDB在运行,可是我的ubuntu上面没有别的MongoDB在运行呀,请教一下这该怎么解决呢?另外如何在ubuntu下面查看某个端口被谁占用了?还有在ubuntu下面怎么把MongoDB从2.2.4升级到2.4.1啊?谢谢!
    2013-05-17 18:01:18 [ 跟帖 ]
    ubuntu也是Linux,所以你通过linux命令就能查看MongoDB是否在运行,如果在运行直接把进程杀掉,如果不行就重启服务器试试,要么启动新的MongoDB时指定一个新的端口即可!
    2013-05-17 21:14:46 [ 跟帖 ]
    1 #
  • 这些 linux 神马的虽然很有兴趣,但是搞不了啊,还是专攻我的前端吧,先记下了有什么这方面的问题,还需多多请教!
    2013-03-30 09:23:12 [ 跟帖 ]
    换头像了?这个有点深度
    2013-03-30 11:37:34 [ 跟帖 ]
    2 #