How to install MongoDB on Debian

Anonym23208111/09/2010 10:55 AM Report
I am trying to install MongoDB on Debian, but I am totally unsuccessful. When I try to download the deb package I obtain Access Denied error. Maybe I should use the binary manual installation but I have no clue how to do it.

Answers

Add a answer ▾

Discussion

Anonym23209711/09/2010 01:45 PM Report

Here are steps for MongDB Debian installation (based on German MongoDB documentation).

Download and unpack MongDB Linux binary (change the name of the downloaded file to the newest version):

# cd /tmp/                                                               
# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.6.3.tgz
# tar -xzf mongodb-linux-x86_64-1.6.3.tgz

Move the files to /opt/mongodb directory and make data directory:

# mv mongodb-linux-x86_64-1.6.3 /opt/mongodb
# mkdir /data 
# mkdir /data/mongodb

The basic files are now installed.
The next step is creating the config file and the start/stop scripts. Create the mongodb user and assign the data folder to it:

# useradd mongod -s /bin/false
# chown -R mongod:mongod /data/mongodb

Create the config file:

# mkdir /etc/mongodb
# cat << EOF > /etc/mongodb/mongodb.conf
MONGO_USER="mongod"
MONGO_OPTS="--dbpath /data/mongodb/"
EOF

Create start/stop script (note: the first and the last line are shell commands, the others are content of newly created /etc/init.d/mongodb file):

# cat << EOF > /etc/init.d/mongodb
#! /bin/sh
# start / stop script for mongodb

### BEGIN INIT INFO
# Provides:          mongod
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start mongod at boot time
# Description:       Enable service provided by mongod.
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

retval=0
pidfile=/var/run/mongodb.pid

exec="/opt/mongodb/bin/mongod"
prog="mongod"
config="/etc/mongodb/mongodb.conf"
lockfile="/var/lock/mongod"

[ -e $config ] && . $config

start() {
    if [ ! -x $exec ]
    then
        echo $exec not found
        exit 5
    fi

    log_daemon_msg "Starting mongoDB daemon"
    log_progress_msg $prog

    start-stop-daemon --start --pidfile $pidfile -m -c $MONGO_USER 
                      --exec $exec -- $MONGO_OPTS run > /dev/null 2>&1 &
    retval=$?
    
    if [ $retval -eq 0 ]
    then
        log_end_msg 0
    else
        log_end_msg 1
    fi
    return $retval
}

stop() {
  log_daemon_msg "Stopping mongoDB daemon"	
  log_progress_msg $prog
  start-stop-daemon --stop --pidfile $pidfile --retry 10 
    --exec $exec
    
    retval=$?
    
    if [ $retval -eq 0 ] && rm -f $lockfile 
    then
        log_end_msg 0
    else
        log_end_msg 1
    fi
    rm -f $pidfile 
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

# See how we were called.
case "$1" in
    start)
        $1
        ;;
    stop)
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        $1
        ;;
    *)
    echo "Usage: $0 {start|stop|status|restart|reload}"
    exit 2
esac

exit $?

EOF
# chmod +x /etc/init.d/mongodb
Include start / stop script to the boot process:
# update-rc.d mongodb defaults

Restart and that’s all!

Anonym26139304/21/2011 07:10 PM Report
thanks, i just would add
chown -R mongod:mongod /opt/mongodb/
Anonym Zakawov05/28/2015 09:22 AM Report
Here is the current Debian or Ubuntu MongoDB installation procedure step by step:

# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
# echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
# apt-get update
# apt-get install -y mongodb-org



Use sudo command before all listed commands if you are not a root user on Ubuntu.
Add a question comment ▾