在Ubuntu上安装Mongodb
Ubuntu是目前十分受欢迎的UNIX系统的之一,本文将介绍如何在Ubuntu上进行安装mongodb。步骤如下:
1) 首先将如下的语句添加到/etc/apt/sources.list文件的最末,以便将包含最新版本的mongodb发行包进行下载deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen,修改后的sources.list文件如下:
#...content omitted ...
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu natty main
deb-src http://extras.ubuntu.com/ubuntu natty main
#mongo repo ###############new line
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu natty main
deb-src http://extras.ubuntu.com/ubuntu natty main
#mongo repo ###############new line
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
2) 更新包
sudo apt-get update
3) 增加GPG KEY
10gen 包需要GPG KEY,因此需要导入:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
4)安装 mongodb-10gen
一切准备好后,就可以安装了,命令如下:
sudo apt-get install mongodb-10gen
5) 修改相关设置
在ubuntu下,启动mongodb的脚本文件在/etc/init/mongo和/etc/init.d/mongo中可以找到,同时,会把mongodb下的所有文件复制到/usr/bin目录下。而主要的配置文件mongodb.conf则在/etc/mongodb.conf下,可以根据需要进行一些修改,如下:
# mongodb.conf
# 存储数据文件的位置
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb
#存放log的地方
logpath=/var/log/mongodb/mongodb.log
logappend=true
#port = 27017
#......
# 存储数据文件的位置
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb
#存放log的地方
logpath=/var/log/mongodb/mongodb.log
logappend=true
#port = 27017
#......
6) 验证安装
为了验证安装,只需要在客户端尝试连接就可以了,如下:
$ mongo
MongoDB shell version: 1.8.1
connecting to: test
>
MongoDB shell version: 1.8.1
connecting to: test
>