广告
返回顶部
首页 > 资讯 > 操作系统 >Linux中怎么安装MongoDB
  • 768
分享到

Linux中怎么安装MongoDB

2023-06-19 12:06:19 768人浏览 八月长安
摘要

本篇文章给大家分享的是有关linux中怎么安装MongoDB,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。安装mongoDB    &n

本篇文章给大家分享的是有关linux中怎么安装MongoDB,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

安装mongoDB

       monGoDB的tar包下载地址:https://www.mongodb.com/download-center#atlas

     解压安装包   tar -zxvf     xxxxxxxxxx.tar

     移动到安装目录   mv mongodb-linux-x86_64-xxx    /usr/local/mongodb

      添加环境变量   echo "export PATH=\$PATH:/usr/local/mongodb/bin【解压后移动过去会存在一个目录,所以需要配置】" > /etc/profile.d/mongodb.sh    (这个里面要小心了!)

     使环境变量生效   source /etc/profile.d/mongodb.sh

     创建Mongodb用户和组  useradd -r -M -s /sbin/nologin mongod

    ***创建启动数据库和启动日志 mkdir -p /data/mongodb/{db,log}/

     修改权限        chown -R mongod:mongod/data/mongodb/

     配置mongoDB配置文件:    vi /etc/mongod.conf

    #mongod.conf

    #for documentation of all options, see:

   #  Http://docs.mongodb.org/manual/reference/configuration-options/

    #where to write logging data.

   systemLog:

     destination: file

     logAppend: true

     path: /data/mongodb/log/mongod.log

    #Where and how to store data.

   storage:

     dbPath: /data/mongodb/db

     journal:

       enabled: true

   #  engine:

   #  mmapv1:

   #  wiredTiger:

    #how the process runs

   proceSSManagement:

     fork: true  # fork and run inbackground

     pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile

    #network interfaces

   net:

     port: 27017

     bindIp: 127.0.0.1  # Listen tolocal interface only, comment to listen on all interfaces.

   #security:

   #operationProfiling:

   #replication:

   #sharding:

   ## Enterprise-Only Options

   #auditLog:

   #snmp:

备注:

如果MongoDB端口不在27017-27019,28017-28019之间,需要执行以下步骤:

# yum -y install policycoreutils-python

# semanage port -a -t mongod_port_t -p tcp<port_number>   27017

创建MongoDB自启动脚本     vi /etc/init.d/mongod

   #!/bin/bash

    #mongod - Startup script for mongod

    #chkconfig: 35 85 15

    #description: Mongo is a Scalable, document-oriented database.

    #processname: mongod

    #config: /etc/mongod.conf

    #pidfile: /var/run/mongodb/mongod.pid

    ./etc/rc.d/init.d/functions

    #things from mongod.conf get there by mongod reading it

    #NOTE: if you change any OPTIONS here, you get what you pay for:

    #this script assumes all options are in the config file.

   CONFIGFILE="/etc/mongod.conf"

   OPTIONS=" -f $CONFIGFILE"

   SYSCONFIG="/etc/sysconfig/mongod"

   PIDFILEPATH=`awk -F'[:=]' -v IGNORECASE=1'/^[[:blank:]]*(processManagement\.)?pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print$2}' "$CONFIGFILE" | tr -d "[:blank:]\"'" | cut -d"#" -f 1`

   mongod=${MONGOD-/usr/local/mongodb/bin/mongod}

   MONGO_USER=mongod

   MONGO_GROUP=mongod

   if [ -f "$SYSCONFIG" ]; then

       . "$SYSCONFIG"

   fi

   PIDDIR=`dirname $PIDFILEPATH`

    #Handle NUMA access to CPUs (SERVER-3574)

    #This verifies the existence of nuMactl as well as testing that the commandworks

   NUMACTL_ARGS="--interleave=all"

   if which numactl >/dev/null 2>/dev/null && numactl$NUMACTL_ARGS ls / >/dev/null 2>/dev/null

   then

       NUMACTL="numactl $NUMACTL_ARGS"

   else

       NUMACTL=""

   fi

   start()

    {

     # Make sure the default pidfile directory exists

     if [ ! -d $PIDDIR ]; then

       install -d -m 0755 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR

     fi

     # Recommended ulimit values for mongod or mongos

     # Seehttp://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

     #

     ulimit -f unlimited

     ulimit -t unlimited

     ulimit -v unlimited

     ulimit -n 64000

     ulimit -m unlimited

     ulimit -u 64000

     echo -n $"Starting mongod: "

     daemon --user "$MONGO_USER" --check $mongod "$NUMACTL$mongod $OPTIONS >/dev/null 2>&1"

     RETVAL=$?

     echo

     [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod

    }

   stop()

    {

     echo -n $"Stopping mongod: "

     mongo_killproc "$PIDFILEPATH" $mongod

     RETVAL=$?

     echo

     [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod

    }

   restart () {

           stop

           start

    }

    #Send TERM signal to process and wait up to 300 seconds for process to go away.

    #If process is still alive after 300 seconds, send KILL signal.

    #Built-in killproc() (found in /etc/init.d/functions) is on certain versions ofLinux

    #where it sleeps for the full $delay seconds if process does not respond fastenough to

    #the initial TERM signal.

   mongo_killproc()

    {

     local pid_file=$1

     local procname=$2

     local -i delay=300

     local -i duration=10

     local pid=`pidofproc -p "${pid_file}" ${procname}`

     kill -TERM $pid >/dev/null 2>&1

     usleep 100000

     local -i x=0

     while [ $x -le $delay ] && checkpid $pid; do

       sleep $duration

       x=$(( $x + $duration))

     done

     kill -KILL $pid >/dev/null 2>&1

     usleep 100000

     checkpid $pid # returns 0 only if the process exists

     local RC=$?

     [ "$RC" -eq 0 ] && failure "${procname}shutdown" || rm -f "${pid_file}"; success "${procname}shutdown"

     RC=$((! $RC)) # invert return code so we return 0 when process is dead.

     return $RC

    }

   RETVAL=0

   case "$1" in

     start)

       start

       ;;

     stop)

       stop

       ;;

     restart|reload|force-reload)

       restart

       ;;

     condrestart)

       [ -f /var/lock/subsys/mongod ] && restart || :

       ;;

     status)

       status $mongod

       RETVAL=$?

       ;;

     *)

       echo "Usage: $0{start|stop|status|restart|reload|force-reload|condrestart}"

       RETVAL=1

   esac

   exit $RETVAL

设置MongoDB服务开机自启动

   chmod +x /etc/init.d/mongod

   chkconfig mongod on

    启动MongoDB服务

   service mongod start

如果启动不成功:

   主要查看     启动脚本 .sh 文件中的配置的环境变量是否正确,  同时查看db  log的权限是否是脚本中配置的用户和组,同时可执行,我给的777

验证启动成功:

service mongod status

   mongod.service - SYSV: Mongo is a scalable, document-oriented database.

      Loaded: loaded (/etc/rc.d/init.d/mongod)

      Active: active (running) since Fri 2017-12-15 23:34:50 EST; 31min ago

     Process: 7648 ExecStop=/etc/rc.d/init.d/mongod stop (code=exited,status=0/SUCCESS)

     Process: 7677 ExecStart=/etc/rc.d/init.d/mongod start (code=exited,status=0/SUCCESS)

    Main PID: 7688 (mongod)

      CGroup: /system.slice/mongod.service

               └─7688/usr/local/mongodb/mongodb-linux-x86_64-3.6.0/bin/mongod -f /etc/mongod.conf

   Dec 15 23:34:49 localhost.localdomain systemd[1]: Starting SYSV: Mongois a scalable, document-oriented database....

   Dec 15 23:34:49 localhost.localdomain runuser[7684]:pam_unix(runuser:session): session opened for user mongod by (uid=0)

   Dec 15 23:34:50 localhost.localdomain mongod[7677]: Starting mongod:[  OK ]

   Dec 15 23:34:50 localhost.localdomain systemd[1]: Started SYSV: Mongo isa scalable, document-oriented database..

Mongodb编辑:

输入mongo:

   > db.foo.find();

    {"_id" : ObjectId("5a34a3De8420293d5f46b0ee"),"name" : "xiaonanhai", "age" : "23" }

   > show dbs;

   admin   0.000GB

   config  0.000GB

   local   0.000GB

   test    0.000GB

   >

END

以上就是Linux中怎么安装MongoDB,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注编程网操作系统频道。

--结束END--

本文标题: Linux中怎么安装MongoDB

本文链接: https://www.lsjlt.com/news/295970.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Linux中怎么安装MongoDB
    本篇文章给大家分享的是有关Linux中怎么安装MongoDB,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。安装MongoDB    &n...
    99+
    2023-06-19
  • Linux上怎么安装MongoDB
    本篇内容介绍了“Linux上怎么安装MongoDB”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!环境:CentOS 7MongoDB 3.4...
    99+
    2023-06-19
  • Linux中怎么安装并启动MongoDB
    这篇文章将为大家详细讲解有关Linux中怎么安装并启动MongoDB,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。一、从MongoDB官网下载MongoDB...
    99+
    2022-10-18
  • Linux版本怎么安装MongoDB
    这篇文章主要讲解了“Linux版本怎么安装MongoDB”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux版本怎么安装MongoDB”吧!1、环境介绍...
    99+
    2022-10-18
  • linux MongoDB安装
    这里是CentOS系统: 使用yum的方式安装也很简单 ,也不需要下载安装包,官网默认是安装最新的版本: 首先创建文件 /etc/yum.repos.d/mongodb-org-4.2.repo  并填写如下内容 [mongodb-o...
    99+
    2018-10-08
    linux MongoDB安装
  • linux 安装mongodb
    wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.9.tgz 解压tar xvf mongodb-linux-x86_64-2.6....
    99+
    2022-10-18
  • Linux中怎么安装配置MongoDB数据库
    Linux中怎么安装配置MongoDB数据库,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。说明:操作系统:CentOS 5.X 64位IP地址...
    99+
    2022-10-18
  • Linux下安装MongoDB
    下载安装包 下载地址:https://www.mongodb.com/download-center/community curl -O https://fastdl.mongodb.org/linux/mongodb-linux...
    99+
    2018-10-14
    Linux下安装MongoDB
  • linux 下安装mongodb
    [root@sc-wjg ~]# uname -aLinux sc-wjg 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x8...
    99+
    2022-10-18
  • Centos中怎么安装MongoDB
    这篇文章给大家介绍Centos中怎么安装MongoDB,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。安装一 使用yum安装安装步骤配置yum创建文件 /etc/yum.repos.d/mongodb-org-4.0.r...
    99+
    2023-06-05
  • ahjesus中怎么安装mongodb
    这篇文章将为大家详细讲解有关ahjesus中怎么安装mongodb,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。导入共匙代码如下:sudo apt-key adv --keyserver h...
    99+
    2023-06-13
  • 怎么安装mongodb
    这篇文章主要为大家展示了“怎么安装mongodb”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“怎么安装mongodb”这篇文章吧。MongoDB是一个介于关系数...
    99+
    2022-10-18
  • Linux平台安装MongoDB
    MongoDB 提供了 linux 各发行版本 64 位的安装包,你可以在官网下载安装包。下载地址:https://www.mongodb.com/download-center#community下载完安...
    99+
    2022-10-18
  • Linux下mongodb的安装
    下载mongohttps://www.mongodb.org/downloadstar zxf mongodb-linux-x86_64-rhel62-3.4.4.tgzmv mongodb-linux-x...
    99+
    2022-10-18
  • Linux如何安装Mongodb
    小编今天带大家了解Linux如何安装Mongodb,文中知识点介绍的非常详细。觉得有帮助的朋友可以跟着小编一起浏览文章的内容,希望能够帮助更多想解决这个问题的朋友找到问题的答案,下面跟着小编一起深入学习“Linux如何安装Mongodb”的...
    99+
    2023-06-28
  • Linux中怎么安装mongodb数据库的Mongo扩展
    这期内容当中小编将会给大家带来有关Linux中怎么安装mongodb数据库的Mongo扩展,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。  1. 下载扩展安装包  wget http://pecl.php...
    99+
    2023-06-13
  • linux中如何部署安装mongodb
    这篇文章给大家分享的是有关linux中如何部署安装mongodb的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。文档目的在Linux系统中安装Mongodb应用程序,并设置基本的安...
    99+
    2022-10-19
  • Linux系统中如何安装MongoDB
    小编给大家分享一下Linux系统中如何安装MongoDB,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!Linux系统如何安装MongoDB?MongoDB是一个基...
    99+
    2023-06-28
  • ubuntu怎么安装mongodb
    在Ubuntu上安装MongoDB可以通过以下步骤进行:1. 更新系统软件包列表:bashsudo apt update2. 安装M...
    99+
    2023-10-20
    ubuntu mongodb
  • Linux环境下安装MongoDB
    下载安装包 下载地址:https://www.mongodb.com/download-center/community curl -O https://fastdl.mongodb.org/linux/mongodb-linux...
    99+
    2017-05-27
    Linux环境下安装MongoDB
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作