声明: 本人系统 Gentoo
一.安装编译需要的包
Fedora:
sudo yum -y install git-core scons gcc-c++ glibc-devel
Ubuntu:
sudo apt-get install git-core build-essential scons
Gentoo:
emerege scons
二. 编译安装
1. 确认已安装先决包(步骤一)
2. 下载源码:
git clone git://github.com/mongodb/mongo.git cd mongo
git tag -l
git checkout r2.1.1
scons all
scons --prefix=/opt/mongo install
三. 测试
1. 创建数据目录( 默认/data/db )
$ sudo mkdir -p /data/db/ $ sudo chown `id -u` /data/db
$ ./mongodb-**/bin/mongod
$ ./mongodb-**/bin/mongo > db.foo.save( { foo : 1 } ) > db.foo.find()
四. 配置
1. 创建配置文件:/opt/mongo/ext/mongo.conf (目录ext 需要自己创建)
#!/bin/bash # file name: mongo.conf # Configuration Options for MongoDB # date: 2012年 05月 17日 星期四 11:30:34 CST # # For More Information, Consider: # - Configuration Parameters: http://www.mongodb.org/display/DOCS/Command+Line+Parameters # - File Based Configuration: http://www.mongodb.org/display/DOCS/File+Based+Configuration dbpath=/opt/wsms/mongo-data logpath=/opt/wsms/mongo-data/mongodb.log logappend=true # bind_ip = 127.0.0.1 # port = 27017 fork = true auth = true # noauth = true
2. Gentoo启动脚本
#!/sbin/runscript # Copyright 2000-2012 # created by cc # $Header: $ MONGO_HOME=/opt/mongodb depend() { use net } start() { ebegin "Starting mongodb..." ${MONGO_HOME}/bin/mongod \ --config ${MONGO_HOME}/etc/mongo.conf eend $? } stop() { ebegin "Stoping mongodb..." ${MONGO_HOME}/bin/mongod \ --shutdown \ --config ${MONGO_HOME}/etc/mongo.conf eend $? } restart() { start stop }
参考:http://www.mongodb.org/display/DOCS/Building+for+Linux