yum安装MongoDB

  1. 添加MongoDB源
    # vi /etc/yum.repos.d/mongodb-org-3.0.repo

    [mongodb-org-3.0]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.0/x86_64/
    gpgcheck=
    enabled=
  2. MongoDB包
    mongodb-org
    This package is a metapackage that will automatically install the four component packages listed below. mongodb-org-server
    This package contains the mongod daemon and associated configuration and init scripts. mongodb-org-mongos
    This package contains the mongos daemon. mongodb-org-shell
    This package contains the mongo shell. mongodb-org-tools
    This package contains the following MongoDB tools: mongoimport bsondump, mongodump, mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop.
  3. 安装MongoDB
    # yum install -y mongodb-org
  4. 设置MongoDB服务开机自启动
    # chkconfig mongod on
  5. 启动MongoDB服务
    # service mongod start

备注:卸载MongoDB

  1. 停止MongoDB服务
    # service mongod stop
  2. 卸载MongoDB安装包
    # yum erase $(rpm -qa | grep mongodb-org)
  3. 删除数据库和日志目录
    # rm -r /var/lib/mongo
    # rm -r /var/log/mongodb

手动安装MongoDB

  1. 下载MongoDB安装包
    # curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.7.tgz
  2. 解压缩MongoDB
    # tar -zxvf mongodb-linux-x86_64-3.0.7.tgz
  3. 移动到安装目录
    # mv mongodb-linux-x86_64-3.0.7 /usr/local/mongodb
  4. 设置环境变量
    # echo "export PATH=\$PATH:/usr/local/mongodb/bin" > /etc/profile.d/mongodb.sh
    # source /etc/profile.d/mongodb.sh
  5. 创建mongod用户和用户组
    # useradd -r -M -s /sbin/nologin mongod
  6. 创建数据库和日志目录并修改属组
    # mkdir -p /data/mongodb/{db,log}/
    # chown -R mongod:mongod /data/mongodb/
  7. 创建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 in background
    pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile # network interfaces
    net:
    port: 27017
    bindIp: 127.0.0.1 # Listen to local 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>

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

    #!/bin/bash
    
    # mongod - Startup script for mongod
    
    # chkconfig:
    # 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= '/^[[: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-)
    # This verifies the existence of numactl as well as testing that the command works
    NUMACTL_ARGS="--interleave=all"
    if which numactl >/dev/null >/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null >/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 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR
    fi # Recommended ulimit values for mongod or mongos
    # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
    #
    ulimit -f unlimited
    ulimit -t unlimited
    ulimit -v unlimited
    ulimit -n
    ulimit -m unlimited
    ulimit -u echo -n $"Starting mongod: "
    daemon --user "$MONGO_USER" --check $mongod "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"
    RETVAL=$?
    echo
    [ $RETVAL -eq ] && touch /var/lock/subsys/mongod
    } stop()
    {
    echo -n $"Stopping mongod: "
    mongo_killproc "$PIDFILEPATH" $mongod
    RETVAL=$?
    echo
    [ $RETVAL -eq ] && rm -f /var/lock/subsys/mongod
    } restart () {
    stop
    start
    } # Send TERM signal to process and wait up to seconds for process to go away.
    # If process is still alive after seconds, send KILL signal.
    # Built-in killproc() (found in /etc/init.d/functions) is on certain versions of Linux
    # where it sleeps for the full $delay seconds if process does not respond fast enough to
    # the initial TERM signal.
    mongo_killproc()
    {
    local pid_file=$
    local procname=$
    local -i delay=
    local -i duration=
    local pid=`pidofproc -p "${pid_file}" ${procname}` kill -TERM $pid >/dev/null >&
    usleep
    local -i x=
    while [ $x -le $delay ] && checkpid $pid; do
    sleep $duration
    x=$(( $x + $duration))
    done kill -KILL $pid >/dev/null >&
    usleep checkpid $pid # returns only if the process exists
    local RC=$?
    [ "$RC" -eq ] && failure "${procname} shutdown" || rm -f "${pid_file}"; success "${procname} shutdown"
    RC=$((! $RC)) # invert return code so we return when process is dead.
    return $RC
    } RETVAL= 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=
    esac exit $RETVAL
  2. 设置MongoDB服务开机自启动
    # chmod +x /etc/init.d/mongod
    # chkconfig mongod on
  3. 启动MongoDB服务
    # service mongod start

备注:

如果启动发生错误,请检查数据库和日志目录及里面文件的权限是否设置正确,再次运行前须删除数据库目录下的mongod.lock文件。

RedHat7搭建MongoDB的更多相关文章

  1. RedHat7搭建MongoDB集群

    下载RPM安装包# wget -c -r -N -np -nd -L -nH https://repo.mongodb.org/yum/redhat/7/mongodb-org/stable/x86_ ...

  2. 搭建mongodb集群(副本集+分片)

    搭建mongodb集群(副本集+分片) 转载自:http://blog.csdn.net/bluejoe2000/article/details/41323051 完整的搭建mongodb集群(副本集 ...

  3. 搭建mongodb分片

    搭建mongodb分片 http://gong1208.iteye.com/blog/1622078 Sharding分片概念 这是一种将海量的数据水平扩展的数据库集群系统,数据分表存储在shardi ...

  4. Docker搭建MongoDB

    1. Docker搭建Mongodb 1.1 获取docker镜像 docker pull mongo 1.2 创建mongodb容器 docker run --name my-mongo -p 27 ...

  5. 在 Azure 虚拟机上快速搭建 MongoDB 集群

    MongoDB 是目前在 NoSQL 市场上非常受欢迎的一个数据库,本文介绍如何使用 Azure PowerShell 和 Azure CLI 在 Azure 虚拟机上搭建单节点 MongoDB(测试 ...

  6. 搭建MongoDB分片集群

    在部门服务器搭建MongoDB分片集群,记录整个操作过程,朋友们也可以参考. 计划如下: 用5台机器搭建,IP分别为:192.168.58.5.192.168.58.6.192.168.58.8.19 ...

  7. RedHat7搭建KVM虚拟机

    RedHat7搭建KVM虚拟机 1. 宿主机安装RedHat7.3系统 1.1选择语言 中文.简体中文(中国) 1.2安装位置 1.2.1自定义分区,选择LVM,将分区空间全部分配给根 1.2.2禁用 ...

  8. MongoDB学习笔记—Linux下搭建MongoDB环境

    1.MongoDB简单说明 a MongoDB是由C++语言编写的一个基于分布式文件存储的开源数据库系统,它的目的在于为WEB应用提供可扩展的高性能数据存储解决方案. b MongoDB是一个介于关系 ...

  9. 使用虚拟机在ubuntu下搭建mongoDB开发环境和简单增删改查操作

    最近在折腾mongodb和nodejs,在imooc上找了一个mongodb的入门教程,跟着里面一步一步的走,下面记录下我操作的步骤和遇到的问题. 课程地址:http://www.imooc.com/ ...

随机推荐

  1. 【Uvalive4960】 Sensor network (苗条树,进化版)

    [题意] 给出N个点,M条边,问这N个点形成的生成树的最大权值边-最小权值边的最小值 InputThe input consists of several test cases, separated ...

  2. http://www.cnblogs.com/xdp-gacl/p/3951952.html

    http://www.cnblogs.com/xdp-gacl/p/3951952.html http://www.cnblogs.com/kristain/articles/2409021.html

  3. in an effort to

    What does "in an effort" to mean? I personally consider in an effort to a stock phrase1. T ...

  4. STL unordered_set

    http://www.cplusplus.com/reference/unordered_set/unordered_set/ template < class Key, // unordere ...

  5. css全局设置

      /***** 全局设置 *****/ body,h1,h2,h3,h4,h5,h6,p,form,ul,ol,li,dt,dl,dd,th,td,label,bottom,input,textar ...

  6. Android源码之Matrix

    Matrix类在Android中主要用来进行矩阵变换,其可操作的对象包括图像.点阵.Vector(向量).矩形等. Matrix支持的变换类型主要有以下几种: 1.Translate:平移变换 2.R ...

  7. windows下 破解 Sublime Text3 和汉化

    这货已经出到3了. windows下载,破解,使用方法: 一:破解 1: 去官网下载最新版本 http://www.sublimetext.com/3 2:下载破解器(SublimeTextKeyge ...

  8. HDU-1716 排列2 (DFS)

    排列2 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  9. java基础(十六)集合(三)

    这里有我之前上课总结的一些知识点以及代码大部分是老师讲的笔记 个人认为是非常好的,,也是比较经典的内容,真诚的希望这些对于那些想学习的人有所帮助! 由于代码是分模块的上传非常的不便.也比较多,讲的也是 ...

  10. JavaScript高级程序设计48.pdf

    设备中的键盘事件 任天堂Wii等设备可以通过键码知道用户按下了哪个键 复合事件 复合事件是DOM3级事件新添加的一类事件,用于处理IME的输入序列.IME(Input Method Editor,输入 ...