1.下载:

mongodb.org/download

2. 将下载的压缩文件加压到/usr/lib下

3. 建立软链接

ln -s /usr/lib/mongodb-linux-i686-2.6.7/bin/mongod /usr/bin/mongod
ln -s /usr/lib/mongodb-linux-i686-2.6.7/bin/mongo /usr/bin/mongo

 这样就可以在命令行下调用mongod和mongo指令了。

当然也可以通过 apt-get install mongodb-server来安装,不过可能版本稍微旧了点。

---以下可选----

4. 启动默认的服务

mongod --dbpath /usr/lib/mongodb-linux-8686-2.6.7/db

但是这样子不是后台运行的,需要把它转为后台运行。

这该怎么办呢?

解答:在/etc/init.d下面建立一个脚本mongod,同时删除掉/usr/bin/mongod。如下:

#!/bin/sh
service mongodb-server start

  

同时设置为启动项:

update-rc.d mongod defaults

新建脚本文件 /etc/init.d/mongodb-server并设置好权限,内容如下:

#!/bin/sh
DAEMON=/usr/bin/mongodb-linux-i686-2.6.7/bin/mongod
DAEMON_OPTS="--dbpath /usr/lib/mongodb-linux-i686-2.6.7/db"
NAME=mongodb-server
DESC=mongodb-server
PIDFILE=/var/run/$NAME.pid
USER = tommy
case "${1}" in
case start)
echo "starting ${DESC}:"
start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--chuid $(USER} --background --make-pidfile \
--exec ${DEAMON} -- ${DEAMON_OPTS}
echo "[ok]"
;;
case stop)
echo "stopping ${DESC}:"
start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
--oknodo
echo "[ok]"
;;
esac
exit 0

 

需要创建pidfile,并设置好权限,过程略。

以上配置后,每次开机,自动启动mongodb的默认服务,数据库为 /usr/lib/mongodb-...../db

只需要在命令行键入mongo就可以连入默认的db。

----分割--------------

以下开发相关:

(比如mongoengine的情形)

from mongoengin import *
connect('local') class Test(Document):
name = StringField(max_length=100) #...

  

=====附注: centos下的安装======

下载redhat包,解压到/usr/local下,重命名为mongodb;

新建脚本/etc/init.d/mongod3, 如下(本人瞎掰的):

# !bin/sh
# chkconfig: - 64 36 NAME=mongod2
PROC=/usr/local/mongodb/bin/mongod
LOG_FILE=/var/log/mongodb.log
DB_PATH=/usr/local/mongodb/db
start(){
$PROC --fork --logpath $LOG_FILE --dbpath $DB_PATH
} stop(){
ps aufx | grep $PROC | grep -v grep | awk '{print $2}' | xargs kill -9
echo 'stoped ...'
} status(){
ps afux | grep $PROC | grep -v grep || echo 'stoped'
} case "$1" in start)
start
;; stop)
stop
;; status)
status $NAME
;; restart)
stop
start
;; *)
echo "Usage: $0 {start|stop|restart|status}"
;; esac

 

加入自动启动

su root
chmod 755 /etc/init.d/mongod3
chkconfig --add mongod3
chkconfig mongod3 on
chkconfig --list | grep mongod3

  

ubuntu 下mongodb安装的更多相关文章

  1. Ubuntu下MongoDB的安装和使用

    本博文介绍了MongoDB,并详细指引读者在Ubuntu下MongoDB的安装和使用.本教程在Ubuntu14.04下测试通过.(2017.09.07) 安装MongoDB MongoDB安装很简单, ...

  2. Ubuntu下软件安装方式、PATH配置、查找安装位置

    Ubuntu 18.04, 安装方式 目前孤知道的Ubuntu下安装软件方式有3种(命令): 1.make 2.apt/apt-get 3.dpkg 方式1基于软件源码安装,需要经历配置(可选).编译 ...

  3. Torch7在Ubuntu下的安装与配置

    Torch7的本系列教程的主要目的是介绍Torch的入门使用.今天首先分享一下Torch7的安装.(在Ubuntu14.04安装torch7) 为什么选择Torch Torch的目标是在建立科学算法的 ...

  4. ubuntu下git安装及使用

    ubuntu下git安装及使用   其实,好几个月前,就已经安装好了,可是一直搁置在那儿,所以密码等一些其它细节都忘的差不多了,所以今天就重新部署了一下,并开始积极使用......... 1,git ...

  5. premake Ubuntu下的安装

    premake是个跨平台的编译工具,先看看在Ubuntu下怎么安装. 首先下载,在/usr目录下: sudo wget -O premake-4.4-beta4-linux.tar.gz http:/ ...

  6. linux,windows,ubuntu下git安装与使用

    ubuntu下git安装与使用:首先应该检查本地是否已经安装了git ,如果没有安装的话,在命令模式下输入 sudo apt-get install git 进行安装 输入git命令查看安装状态及常用 ...

  7. ubuntu下如何安装codeblocks集成开发环境

    codeblocks是一个十分优秀的C/C++开发IDE,虽然后起之秀codelite目前来看大有超越之势哦. 不过在ubuntu下安装codeblocks却比较麻烦,不像其他linux发行版,比如s ...

  8. ubuntu下makeinfo安装,其实真正安装的是texinfo包

    操作系统环境:ubuntu 在终端中执行命令:sudo apt-get install texinfo   今天在打包的时候有个包需要 makeinfo,当时就各种搜结果就没有 makeinfo 这个 ...

  9. Windows下Mongodb安装及配置

    安装文件:MongoDB-win32-x86_64-2008plus-ssl-3.2.6-signed.msi 电脑配置:win7 64位 mongodb的安装很简单,设置好安装路径后,一直Next直 ...

随机推荐

  1. 适合于图像处理方向的SCI期刊杂志列表【转】

    适合于图像处理方向的SCI期刊杂志列表[转]   表1. 适合于图像处理方向的SCI期刊杂志列表 ISSN 期刊名 出版周期 1057-7149 IEEE TRANSACTIONS ON IMAGE ...

  2. CodeForces 689B Mike and Shortcuts (BFS or 最短路)

    题目链接:http://codeforces.com/problemset/problem/689/B 题目大意: 留坑 明天中秋~

  3. C#----Get和Set在属性中的使用

    Get和Set在属性中的作用: 第一个作用:保证数据的安全性,对字段进行了有效的保护. 第二个作用:起到监视作用 private int width=0; public int Width { get ...

  4. C# C++联调

    http://jingyan.baidu.com/article/fcb5aff7926344edab4a714d.html

  5. AutoMapper不用任何配置就可以从dynamic(动态)对象映射或映射到dynamic对象。

    http://www.cnblogs.com/farb/p/4934476.html#pz

  6. IdentityDbContext

    Move the ApplicationUser definition to your DAL. Inherit your MyDbContext from IdentityDbContext< ...

  7. 在Centos上安装RabbitMQ流程(转)

    在Centos上安装RabbitMQ流程------------------------ 1. 需求 由于项目中要用到消息队列,经过ActiveMQ与RabbitMQ的比较,最终选择了RabbbitM ...

  8. jquery access方法 有什么用

    Jquery设置对象属性的有几种方法1.获取属性attr(name) 2.设置属性attr(name,value)3.批量设置属性attr(properties)4.为所有匹配的元素设置一个计算的属性 ...

  9. Android Studio-设置快速修复错误提示代码

    File-Settings-keyMap-show intention actions.

  10. 【8-17】HTML测试

    Source : http://www.w3school.com.cn/html HTML 测验 结果:9/20 您的回答: 1.HTML 指的是? 您的回答:超文本标记语言(Hyper Text M ...