在Debian Buster上安装MongoDB

在Debian Buster上安装MongoDB,mongodb,debian,stretch,sid,Mongodb,Debian,Stretch,Sid,如何安装最新的MongoDB 3.4甚至3.6? 他们支持Ubuntu,但我的服务器是Debian Buster,我一直使用MongoDB 3.2。我找到了构建脚本的解决方案,描述如下: 说明: Debian Stretch/Buster/Bullseye/Testing MongoDB和MongoDB工具构建稳定的构建器脚本,其具体功能如下: 它基本上是为Debian的最新MongoDB构建的 当前版本是r4.0.x版本 警告:将删除./scripts/build-server.sh和/et

如何安装最新的MongoDB 3.4甚至3.6?
他们支持Ubuntu,但我的服务器是Debian Buster,我一直使用MongoDB 3.2。

我找到了构建脚本的解决方案,描述如下:

说明:

Debian Stretch/Buster/Bullseye/Testing MongoDB和MongoDB工具构建稳定的构建器脚本,其具体功能如下:

它基本上是为Debian的最新MongoDB构建的

当前版本是r4.0.x版本

警告:将删除./scripts/build-server.sh和/etc/systemd/system/mongodb-server.service中的所有mongodb*apt包

它安装所需的apt依赖项并生成SystemD服务并使其启用

检查建筑是否正常(建筑在下方)。它运行所有的测试,所以如果它能工作,那么它真的能,实际上。当然,如果出现错误,您将不会在服务器上部署。因此,如果构建和测试工作正常,那么它会将二进制文件放在后面,这样您就可以确定并完成了

构建过程如下所示
buildserver.sh

#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source

# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# if an error exit right away, don't continue the build
set -e

# some info
echo
#echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.2.0"
echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.0.12"
echo

# check if we are root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
   exit 1
fi

# require mongo branch
#if [ -z "${1}" ]; then
#    echo "First argument must be the MONGODB_BRANCH for example 'v4.1'"
#    exit 1
#fi
#MONGODB_BRANCH="${1}"

# require mongo release
#if [ -z "${2}" ]; then
#    echo "The second argument must be the MONGODB_RELEASE for example 'r4.1.0'"
#    exit 1
#fi
#MONGODB_RELEASE="${2}"

# require mongo release
if [ -z "${1}" ]; then
    echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
    exit 1
fi
MONGODB_RELEASE="${1}"

# delete all mongo other programs, we self compile
apt remove --purge mongo*

# the required packages for debian
apt -y install libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev build-essential gcc python scons git glibc-source libssl-dev python-pip libffi-dev python-dev libcurl4-openssl-dev #libcurl-dev
pip install -U pip pyyaml typing


# generate build directory variable
BUILD=$DIR/../build

# delete previous build directory
rm -rf $BUILD/mongo

# generate new build directory
mkdir -p $BUILD

# the mongodb.conf and systemd services files in a directory variable
ROOT_FS=$DIR/../artifacts/root-filesystem

# find out how many cores we have and we use that many
if [ -z "$CORES" ]; then
    CORES=$(grep -c ^processor /proc/cpuinfo)
fi
echo Using $CORES cores

# go to the build directory
pushd $BUILD

    # clone the mongo by branch
    #git clone -b ${MONGODB_BRANCH} https://github.com/mongodb/mongo.git

    # clone the mongo by branch
    git clone https://github.com/mongodb/mongo.git

    # the mongo directory is a variables
    MONGO=$BUILD/mongo

    # go to the mongo directory
    pushd $MONGO

        # checkout the mongo release
        git checkout tags/${MONGODB_RELEASE}

        # hack to old version python pip cryptography from 1.7.2 to use the latest
        sed -i 's#cryptography == 1.7.2#\#cryptography == 1.7.2#g' buildscripts/requirements.txt
        # this is only because 4.0.12 uses 1.7.2 and
        # https://github.com/pyca/cryptography/issues/4193#issuecomment-381236459
        # support minimum latest (2.2)
        pip install cryptography

        # install the python requirements
        #pip install -r etc/pip/dev-requirements.txt
        pip install -r buildscripts/requirements.txt

        # somewhere in the build it says if we install this, it is faster to build
        pip2 install --user regex

        # build everything
        scons all --disable-warnings-as-errors -j $CORES --ssl

        # install the mongo programs all
        scons install --disable-warnings-as-errors -j $CORES --prefix /usr

        # create a copy of the old config
        #TIMESTAMP=$(($(date +%s%N)/1000000))
        #cp /etc/mongodb.conf /etc/mongodb.conf.$TIMESTAMP.save

        # copy the mongodb.conf configured and the systemd service file
        # dangerous!!! removed
        # cp -avr $ROOT_FS/. /

        MONGODB_SERVICE=etc/systemd/system/mongodb-server.service
        cp $ROOT_FS/$MONGODB_SERVICE /$MONGODB_SERVICE
        chown root:root /$MONGODB_SERVICE
        chmod o-rwx /$MONGODB_SERVICE

        # generate mongodb user and group
        useradd mongodb -d /var/lib/mongodb -s /bin/false || true

        # create the required mongodb database directory and add safety
        mkdir -p /var/lib/mongodb
        chmod o-rwx -R /var/lib/mongodb
        chown -R mongodb:mongodb /var/lib/mongodb

        # create the required mongodb log directory and add safety
        mkdir -p /var/log/mongodb
        chmod o-rwx -R /var/log/mongodb
        chown -R mongodb:mongodb /var/log/mongodb

        # create the required run socket directory and add safety
        mkdir -p /run/mongodb
        chmod o-rwx -R /run/mongodb
        chown -R mongodb:mongodb /run/mongodb

        # add safety to the mongodb config file
        chmod o-rwx /etc/mongodb.conf || true
        chown mongodb:mongodb /etc/mongodb.conf || true

        # reload systemd services
        systemctl daemon-reload

        # enable the mongodb-server
        systemctl enable mongodb-server

        # start the mongodb-server
        #service mongodb-server start

    # exit of the mongo directory
    popd

# exit the build directory
popd

# delete current build directory
rm -rf $BUILD/mongo
#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo-tools

# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# if an error exit right away, don't continue the build
set -e

# some info
echo
echo "Works like command: sudo ./scripts/build-tools.sh r4.0.12"
echo

# check if we are root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
   exit 1
fi

# require mongo release
if [ -z "${1}" ]; then
    echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
    exit 1
fi
MONGODB_RELEASE="${1}"

## delete all mongo other programs, we self compile
##apt remove --purge mongo*

## the required packages for debian
##apt -y install gcc python scons git glibc-source libssl-dev python-pip

apt -y install golang libpcap-dev

export GOROOT=$(go env GOROOT)


# generate build directory variable
BUILD=$DIR/../build/src/github.com/mongodb/

# delete previous build directory
rm -rf $BUILD/mongo-tools

# generate new build directory
mkdir -p $BUILD

# find out how many cores we have and we use that many
CORES=$(grep -c ^processor /proc/cpuinfo)

# go to the build directory
pushd $BUILD

    # clone the mongo by branch
    git clone https://github.com/mongodb/mongo-tools

    # the mongo directory is a variables
    MONGO_TOOLS=$BUILD/mongo-tools

    # go to the mongo directory
    pushd $MONGO_TOOLS

        # checkout the mongo release
        git checkout tags/${MONGODB_RELEASE}

        bash ./build.sh
        chown root:adm -R ./bin
        chmod o-rwx -R ./bin
        chmod ug+rx ./bin/*
        cp -r ./bin/. /usr/bin
#        for PROGRAM in bsondump mongodump mongoexport mongofiles mongoimport mongoreplay mongorestore mongostat mongotop
#        do
#            go build -o bin/${PROGRAM} -tags "ssl sasl" ${PROGRAM}/main/${PROGRAM}.go
#        done

    # exit of the mongo directory
    popd

# exit the build directory
popd

# delete current build directory
rm -rf $BUILD/mongo-tools
popd

# delete current build directory
rm -rf $BUILD/mongo-tools
构建过程如下
构建工具.sh

#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source

# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# if an error exit right away, don't continue the build
set -e

# some info
echo
#echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.2.0"
echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.0.12"
echo

# check if we are root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
   exit 1
fi

# require mongo branch
#if [ -z "${1}" ]; then
#    echo "First argument must be the MONGODB_BRANCH for example 'v4.1'"
#    exit 1
#fi
#MONGODB_BRANCH="${1}"

# require mongo release
#if [ -z "${2}" ]; then
#    echo "The second argument must be the MONGODB_RELEASE for example 'r4.1.0'"
#    exit 1
#fi
#MONGODB_RELEASE="${2}"

# require mongo release
if [ -z "${1}" ]; then
    echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
    exit 1
fi
MONGODB_RELEASE="${1}"

# delete all mongo other programs, we self compile
apt remove --purge mongo*

# the required packages for debian
apt -y install libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev build-essential gcc python scons git glibc-source libssl-dev python-pip libffi-dev python-dev libcurl4-openssl-dev #libcurl-dev
pip install -U pip pyyaml typing


# generate build directory variable
BUILD=$DIR/../build

# delete previous build directory
rm -rf $BUILD/mongo

# generate new build directory
mkdir -p $BUILD

# the mongodb.conf and systemd services files in a directory variable
ROOT_FS=$DIR/../artifacts/root-filesystem

# find out how many cores we have and we use that many
if [ -z "$CORES" ]; then
    CORES=$(grep -c ^processor /proc/cpuinfo)
fi
echo Using $CORES cores

# go to the build directory
pushd $BUILD

    # clone the mongo by branch
    #git clone -b ${MONGODB_BRANCH} https://github.com/mongodb/mongo.git

    # clone the mongo by branch
    git clone https://github.com/mongodb/mongo.git

    # the mongo directory is a variables
    MONGO=$BUILD/mongo

    # go to the mongo directory
    pushd $MONGO

        # checkout the mongo release
        git checkout tags/${MONGODB_RELEASE}

        # hack to old version python pip cryptography from 1.7.2 to use the latest
        sed -i 's#cryptography == 1.7.2#\#cryptography == 1.7.2#g' buildscripts/requirements.txt
        # this is only because 4.0.12 uses 1.7.2 and
        # https://github.com/pyca/cryptography/issues/4193#issuecomment-381236459
        # support minimum latest (2.2)
        pip install cryptography

        # install the python requirements
        #pip install -r etc/pip/dev-requirements.txt
        pip install -r buildscripts/requirements.txt

        # somewhere in the build it says if we install this, it is faster to build
        pip2 install --user regex

        # build everything
        scons all --disable-warnings-as-errors -j $CORES --ssl

        # install the mongo programs all
        scons install --disable-warnings-as-errors -j $CORES --prefix /usr

        # create a copy of the old config
        #TIMESTAMP=$(($(date +%s%N)/1000000))
        #cp /etc/mongodb.conf /etc/mongodb.conf.$TIMESTAMP.save

        # copy the mongodb.conf configured and the systemd service file
        # dangerous!!! removed
        # cp -avr $ROOT_FS/. /

        MONGODB_SERVICE=etc/systemd/system/mongodb-server.service
        cp $ROOT_FS/$MONGODB_SERVICE /$MONGODB_SERVICE
        chown root:root /$MONGODB_SERVICE
        chmod o-rwx /$MONGODB_SERVICE

        # generate mongodb user and group
        useradd mongodb -d /var/lib/mongodb -s /bin/false || true

        # create the required mongodb database directory and add safety
        mkdir -p /var/lib/mongodb
        chmod o-rwx -R /var/lib/mongodb
        chown -R mongodb:mongodb /var/lib/mongodb

        # create the required mongodb log directory and add safety
        mkdir -p /var/log/mongodb
        chmod o-rwx -R /var/log/mongodb
        chown -R mongodb:mongodb /var/log/mongodb

        # create the required run socket directory and add safety
        mkdir -p /run/mongodb
        chmod o-rwx -R /run/mongodb
        chown -R mongodb:mongodb /run/mongodb

        # add safety to the mongodb config file
        chmod o-rwx /etc/mongodb.conf || true
        chown mongodb:mongodb /etc/mongodb.conf || true

        # reload systemd services
        systemctl daemon-reload

        # enable the mongodb-server
        systemctl enable mongodb-server

        # start the mongodb-server
        #service mongodb-server start

    # exit of the mongo directory
    popd

# exit the build directory
popd

# delete current build directory
rm -rf $BUILD/mongo
#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo-tools

# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# if an error exit right away, don't continue the build
set -e

# some info
echo
echo "Works like command: sudo ./scripts/build-tools.sh r4.0.12"
echo

# check if we are root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
   exit 1
fi

# require mongo release
if [ -z "${1}" ]; then
    echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
    exit 1
fi
MONGODB_RELEASE="${1}"

## delete all mongo other programs, we self compile
##apt remove --purge mongo*

## the required packages for debian
##apt -y install gcc python scons git glibc-source libssl-dev python-pip

apt -y install golang libpcap-dev

export GOROOT=$(go env GOROOT)


# generate build directory variable
BUILD=$DIR/../build/src/github.com/mongodb/

# delete previous build directory
rm -rf $BUILD/mongo-tools

# generate new build directory
mkdir -p $BUILD

# find out how many cores we have and we use that many
CORES=$(grep -c ^processor /proc/cpuinfo)

# go to the build directory
pushd $BUILD

    # clone the mongo by branch
    git clone https://github.com/mongodb/mongo-tools

    # the mongo directory is a variables
    MONGO_TOOLS=$BUILD/mongo-tools

    # go to the mongo directory
    pushd $MONGO_TOOLS

        # checkout the mongo release
        git checkout tags/${MONGODB_RELEASE}

        bash ./build.sh
        chown root:adm -R ./bin
        chmod o-rwx -R ./bin
        chmod ug+rx ./bin/*
        cp -r ./bin/. /usr/bin
#        for PROGRAM in bsondump mongodump mongoexport mongofiles mongoimport mongoreplay mongorestore mongostat mongotop
#        do
#            go build -o bin/${PROGRAM} -tags "ssl sasl" ${PROGRAM}/main/${PROGRAM}.go
#        done

    # exit of the mongo directory
    popd

# exit the build directory
popd

# delete current build directory
rm -rf $BUILD/mongo-tools
popd

# delete current build directory
rm -rf $BUILD/mongo-tools

我已经找到了构建脚本的解决方案,描述如下:

说明:

Debian Stretch/Buster/Bullseye/Testing MongoDB和MongoDB工具构建稳定的构建器脚本,其具体功能如下:

它基本上是为Debian的最新MongoDB构建的

当前版本是r4.0.x版本

警告:将删除./scripts/build-server.sh和/etc/systemd/system/mongodb-server.service中的所有mongodb*apt包

它安装所需的apt依赖项并生成SystemD服务并使其启用

检查建筑是否正常(建筑在下方)。它运行所有的测试,所以如果它能工作,那么它真的能,实际上。当然,如果出现错误,您将不会在服务器上部署。因此,如果构建和测试工作正常,那么它会将二进制文件放在后面,这样您就可以确定并完成了

构建过程如下所示
buildserver.sh

#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source

# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# if an error exit right away, don't continue the build
set -e

# some info
echo
#echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.2.0"
echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.0.12"
echo

# check if we are root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
   exit 1
fi

# require mongo branch
#if [ -z "${1}" ]; then
#    echo "First argument must be the MONGODB_BRANCH for example 'v4.1'"
#    exit 1
#fi
#MONGODB_BRANCH="${1}"

# require mongo release
#if [ -z "${2}" ]; then
#    echo "The second argument must be the MONGODB_RELEASE for example 'r4.1.0'"
#    exit 1
#fi
#MONGODB_RELEASE="${2}"

# require mongo release
if [ -z "${1}" ]; then
    echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
    exit 1
fi
MONGODB_RELEASE="${1}"

# delete all mongo other programs, we self compile
apt remove --purge mongo*

# the required packages for debian
apt -y install libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev build-essential gcc python scons git glibc-source libssl-dev python-pip libffi-dev python-dev libcurl4-openssl-dev #libcurl-dev
pip install -U pip pyyaml typing


# generate build directory variable
BUILD=$DIR/../build

# delete previous build directory
rm -rf $BUILD/mongo

# generate new build directory
mkdir -p $BUILD

# the mongodb.conf and systemd services files in a directory variable
ROOT_FS=$DIR/../artifacts/root-filesystem

# find out how many cores we have and we use that many
if [ -z "$CORES" ]; then
    CORES=$(grep -c ^processor /proc/cpuinfo)
fi
echo Using $CORES cores

# go to the build directory
pushd $BUILD

    # clone the mongo by branch
    #git clone -b ${MONGODB_BRANCH} https://github.com/mongodb/mongo.git

    # clone the mongo by branch
    git clone https://github.com/mongodb/mongo.git

    # the mongo directory is a variables
    MONGO=$BUILD/mongo

    # go to the mongo directory
    pushd $MONGO

        # checkout the mongo release
        git checkout tags/${MONGODB_RELEASE}

        # hack to old version python pip cryptography from 1.7.2 to use the latest
        sed -i 's#cryptography == 1.7.2#\#cryptography == 1.7.2#g' buildscripts/requirements.txt
        # this is only because 4.0.12 uses 1.7.2 and
        # https://github.com/pyca/cryptography/issues/4193#issuecomment-381236459
        # support minimum latest (2.2)
        pip install cryptography

        # install the python requirements
        #pip install -r etc/pip/dev-requirements.txt
        pip install -r buildscripts/requirements.txt

        # somewhere in the build it says if we install this, it is faster to build
        pip2 install --user regex

        # build everything
        scons all --disable-warnings-as-errors -j $CORES --ssl

        # install the mongo programs all
        scons install --disable-warnings-as-errors -j $CORES --prefix /usr

        # create a copy of the old config
        #TIMESTAMP=$(($(date +%s%N)/1000000))
        #cp /etc/mongodb.conf /etc/mongodb.conf.$TIMESTAMP.save

        # copy the mongodb.conf configured and the systemd service file
        # dangerous!!! removed
        # cp -avr $ROOT_FS/. /

        MONGODB_SERVICE=etc/systemd/system/mongodb-server.service
        cp $ROOT_FS/$MONGODB_SERVICE /$MONGODB_SERVICE
        chown root:root /$MONGODB_SERVICE
        chmod o-rwx /$MONGODB_SERVICE

        # generate mongodb user and group
        useradd mongodb -d /var/lib/mongodb -s /bin/false || true

        # create the required mongodb database directory and add safety
        mkdir -p /var/lib/mongodb
        chmod o-rwx -R /var/lib/mongodb
        chown -R mongodb:mongodb /var/lib/mongodb

        # create the required mongodb log directory and add safety
        mkdir -p /var/log/mongodb
        chmod o-rwx -R /var/log/mongodb
        chown -R mongodb:mongodb /var/log/mongodb

        # create the required run socket directory and add safety
        mkdir -p /run/mongodb
        chmod o-rwx -R /run/mongodb
        chown -R mongodb:mongodb /run/mongodb

        # add safety to the mongodb config file
        chmod o-rwx /etc/mongodb.conf || true
        chown mongodb:mongodb /etc/mongodb.conf || true

        # reload systemd services
        systemctl daemon-reload

        # enable the mongodb-server
        systemctl enable mongodb-server

        # start the mongodb-server
        #service mongodb-server start

    # exit of the mongo directory
    popd

# exit the build directory
popd

# delete current build directory
rm -rf $BUILD/mongo
#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo-tools

# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# if an error exit right away, don't continue the build
set -e

# some info
echo
echo "Works like command: sudo ./scripts/build-tools.sh r4.0.12"
echo

# check if we are root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
   exit 1
fi

# require mongo release
if [ -z "${1}" ]; then
    echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
    exit 1
fi
MONGODB_RELEASE="${1}"

## delete all mongo other programs, we self compile
##apt remove --purge mongo*

## the required packages for debian
##apt -y install gcc python scons git glibc-source libssl-dev python-pip

apt -y install golang libpcap-dev

export GOROOT=$(go env GOROOT)


# generate build directory variable
BUILD=$DIR/../build/src/github.com/mongodb/

# delete previous build directory
rm -rf $BUILD/mongo-tools

# generate new build directory
mkdir -p $BUILD

# find out how many cores we have and we use that many
CORES=$(grep -c ^processor /proc/cpuinfo)

# go to the build directory
pushd $BUILD

    # clone the mongo by branch
    git clone https://github.com/mongodb/mongo-tools

    # the mongo directory is a variables
    MONGO_TOOLS=$BUILD/mongo-tools

    # go to the mongo directory
    pushd $MONGO_TOOLS

        # checkout the mongo release
        git checkout tags/${MONGODB_RELEASE}

        bash ./build.sh
        chown root:adm -R ./bin
        chmod o-rwx -R ./bin
        chmod ug+rx ./bin/*
        cp -r ./bin/. /usr/bin
#        for PROGRAM in bsondump mongodump mongoexport mongofiles mongoimport mongoreplay mongorestore mongostat mongotop
#        do
#            go build -o bin/${PROGRAM} -tags "ssl sasl" ${PROGRAM}/main/${PROGRAM}.go
#        done

    # exit of the mongo directory
    popd

# exit the build directory
popd

# delete current build directory
rm -rf $BUILD/mongo-tools
popd

# delete current build directory
rm -rf $BUILD/mongo-tools
构建过程如下
构建工具.sh

#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source

# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# if an error exit right away, don't continue the build
set -e

# some info
echo
#echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.2.0"
echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.0.12"
echo

# check if we are root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
   exit 1
fi

# require mongo branch
#if [ -z "${1}" ]; then
#    echo "First argument must be the MONGODB_BRANCH for example 'v4.1'"
#    exit 1
#fi
#MONGODB_BRANCH="${1}"

# require mongo release
#if [ -z "${2}" ]; then
#    echo "The second argument must be the MONGODB_RELEASE for example 'r4.1.0'"
#    exit 1
#fi
#MONGODB_RELEASE="${2}"

# require mongo release
if [ -z "${1}" ]; then
    echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
    exit 1
fi
MONGODB_RELEASE="${1}"

# delete all mongo other programs, we self compile
apt remove --purge mongo*

# the required packages for debian
apt -y install libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev build-essential gcc python scons git glibc-source libssl-dev python-pip libffi-dev python-dev libcurl4-openssl-dev #libcurl-dev
pip install -U pip pyyaml typing


# generate build directory variable
BUILD=$DIR/../build

# delete previous build directory
rm -rf $BUILD/mongo

# generate new build directory
mkdir -p $BUILD

# the mongodb.conf and systemd services files in a directory variable
ROOT_FS=$DIR/../artifacts/root-filesystem

# find out how many cores we have and we use that many
if [ -z "$CORES" ]; then
    CORES=$(grep -c ^processor /proc/cpuinfo)
fi
echo Using $CORES cores

# go to the build directory
pushd $BUILD

    # clone the mongo by branch
    #git clone -b ${MONGODB_BRANCH} https://github.com/mongodb/mongo.git

    # clone the mongo by branch
    git clone https://github.com/mongodb/mongo.git

    # the mongo directory is a variables
    MONGO=$BUILD/mongo

    # go to the mongo directory
    pushd $MONGO

        # checkout the mongo release
        git checkout tags/${MONGODB_RELEASE}

        # hack to old version python pip cryptography from 1.7.2 to use the latest
        sed -i 's#cryptography == 1.7.2#\#cryptography == 1.7.2#g' buildscripts/requirements.txt
        # this is only because 4.0.12 uses 1.7.2 and
        # https://github.com/pyca/cryptography/issues/4193#issuecomment-381236459
        # support minimum latest (2.2)
        pip install cryptography

        # install the python requirements
        #pip install -r etc/pip/dev-requirements.txt
        pip install -r buildscripts/requirements.txt

        # somewhere in the build it says if we install this, it is faster to build
        pip2 install --user regex

        # build everything
        scons all --disable-warnings-as-errors -j $CORES --ssl

        # install the mongo programs all
        scons install --disable-warnings-as-errors -j $CORES --prefix /usr

        # create a copy of the old config
        #TIMESTAMP=$(($(date +%s%N)/1000000))
        #cp /etc/mongodb.conf /etc/mongodb.conf.$TIMESTAMP.save

        # copy the mongodb.conf configured and the systemd service file
        # dangerous!!! removed
        # cp -avr $ROOT_FS/. /

        MONGODB_SERVICE=etc/systemd/system/mongodb-server.service
        cp $ROOT_FS/$MONGODB_SERVICE /$MONGODB_SERVICE
        chown root:root /$MONGODB_SERVICE
        chmod o-rwx /$MONGODB_SERVICE

        # generate mongodb user and group
        useradd mongodb -d /var/lib/mongodb -s /bin/false || true

        # create the required mongodb database directory and add safety
        mkdir -p /var/lib/mongodb
        chmod o-rwx -R /var/lib/mongodb
        chown -R mongodb:mongodb /var/lib/mongodb

        # create the required mongodb log directory and add safety
        mkdir -p /var/log/mongodb
        chmod o-rwx -R /var/log/mongodb
        chown -R mongodb:mongodb /var/log/mongodb

        # create the required run socket directory and add safety
        mkdir -p /run/mongodb
        chmod o-rwx -R /run/mongodb
        chown -R mongodb:mongodb /run/mongodb

        # add safety to the mongodb config file
        chmod o-rwx /etc/mongodb.conf || true
        chown mongodb:mongodb /etc/mongodb.conf || true

        # reload systemd services
        systemctl daemon-reload

        # enable the mongodb-server
        systemctl enable mongodb-server

        # start the mongodb-server
        #service mongodb-server start

    # exit of the mongo directory
    popd

# exit the build directory
popd

# delete current build directory
rm -rf $BUILD/mongo
#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo-tools

# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# if an error exit right away, don't continue the build
set -e

# some info
echo
echo "Works like command: sudo ./scripts/build-tools.sh r4.0.12"
echo

# check if we are root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
   exit 1
fi

# require mongo release
if [ -z "${1}" ]; then
    echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
    exit 1
fi
MONGODB_RELEASE="${1}"

## delete all mongo other programs, we self compile
##apt remove --purge mongo*

## the required packages for debian
##apt -y install gcc python scons git glibc-source libssl-dev python-pip

apt -y install golang libpcap-dev

export GOROOT=$(go env GOROOT)


# generate build directory variable
BUILD=$DIR/../build/src/github.com/mongodb/

# delete previous build directory
rm -rf $BUILD/mongo-tools

# generate new build directory
mkdir -p $BUILD

# find out how many cores we have and we use that many
CORES=$(grep -c ^processor /proc/cpuinfo)

# go to the build directory
pushd $BUILD

    # clone the mongo by branch
    git clone https://github.com/mongodb/mongo-tools

    # the mongo directory is a variables
    MONGO_TOOLS=$BUILD/mongo-tools

    # go to the mongo directory
    pushd $MONGO_TOOLS

        # checkout the mongo release
        git checkout tags/${MONGODB_RELEASE}

        bash ./build.sh
        chown root:adm -R ./bin
        chmod o-rwx -R ./bin
        chmod ug+rx ./bin/*
        cp -r ./bin/. /usr/bin
#        for PROGRAM in bsondump mongodump mongoexport mongofiles mongoimport mongoreplay mongorestore mongostat mongotop
#        do
#            go build -o bin/${PROGRAM} -tags "ssl sasl" ${PROGRAM}/main/${PROGRAM}.go
#        done

    # exit of the mongo directory
    popd

# exit the build directory
popd

# delete current build directory
rm -rf $BUILD/mongo-tools
popd

# delete current build directory
rm -rf $BUILD/mongo-tools

我不知道这是否是一个好主意,但我只是通过添加
sid
repos并使用
mongodb服务器
包安装了它。对我来说,这将安装3.4.18版

我用以下代码创建了
/etc/apt/sources.list.d/sid.list

deb http://deb.debian.org/debian/ sid main
deb-src http://deb.debian.org/debian/ sid main
然后呢

apt update
apt install mongodb-server

并通过连接
mongo

验证它是否正常工作。我不知道这是否是个好主意,但我只是通过添加
sid
repos并使用
mongodb服务器
包安装了它。对我来说,这将安装3.4.18版

我用以下代码创建了
/etc/apt/sources.list.d/sid.list

deb http://deb.debian.org/debian/ sid main
deb-src http://deb.debian.org/debian/ sid main
然后呢

apt update
apt install mongodb-server

并通过连接
mongo

验证了它是否正常工作。我找到了构建脚本的解决方案,说明如下:我找到了构建脚本的解决方案,说明如下: