• mongoDB-3.x安装配置(单机版)


    mongoDB-3.x安装配置(单机版)
    官方文档:

    环境:
    CentOS6.5 x64
    mongoDB-3.2.0

    方式一 : yum安装


    方式二 : 二进制包
    1.安装
    tar -xvf mongodb-linux-x86_64-rhel62-3.2.0.tgz -C /opt/
    ln -s /opt/mongodb-linux-x86_64-rhel62-3.2.0/ /opt/mongodb
    cat >>/etc/profile <<HERE
    PATH=$PATH:/opt/mongodb/bin
    HERE
    source /etc/profile
    mkdir -p /opt/mongodb/{log,db,conf}

    2.启动
    mongod --fork --httpinterface --rest --jsonp --setParameter enableLocalhostAuthBypass=0 --pidfilepath /opt/mongodb/mongod.pid --dbpath /opt/mongodb/db --logpath /opt/mongodb/log/mongod.log  --logappend --logRotate rename --timeStampFormat ctime
    可以加入/etc/rc.d/rc.local,以随操作系统重启时自启动
    部分参数解释
    --fork #后台daemon运行
    --bind_ip #监听IP地址列表,以逗号分隔
    --port #监听端口,默认27017
    --setParameter enableLocalhostAuthBypass=0 #所有接口都需要认证
    --pidfilepath #pid文件
    --dbpath #db存放路径
    --logpath #日志文件
    --config #配置文件
    --auth #启用认证
    --httpinterface #启用web接口
    --rest #rest api
    --jsonp #json api
    如果闲命令参数太多,可以指定配置文件

    WARNING

    Ensure that the HTTP status interface, the REST API, and the JSON API are all disabled in production environments to prevent potential data exposure and vulnerability to attackers

    root@master:~#netstat -tunlp|grep mongod
    tcp        0      0 0.0.0.0:28017               0.0.0.0:*                   LISTEN      11896/mongod        
    tcp        0      0 0.0.0.0:27017               0.0.0.0:*                   LISTEN      11896/mongod 
    默认监听端口,db端口为27017, web端口为28017
    mongoDB-3.x安装配置(单机版)

    3.关闭
    mongod --shutdown --dbpath /opt/mongodb/db
    还可以
    命令行模式执行shutdown
    use admin
    db.shutdownServer()
    mongo admin --port 27017 --eval "db.shutdownServer()"

    4.指定配置文件
    Changed in version 2.6: MongoDB 2.6 introduces a YAML-based configuration file format. The 2.4 configuration file format remains for backward compatibility.
    默认的二进制包没有配置文件模板,可以从源码包内提取
    cp /usr/local/src/mongodb-src-r3.2.0/rpm/mongod.conf /opt/mongodb/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
      logRotate: rename
      timeStampFormat: ctime
      path: /opt/mongodb/log/mongod.log

    # Where and how to store data.
    storage:
      dbPath: /opt/mongodb/db
      journal:
        enabled: true
    #  engine:
    #  mmapv1:
    #  wiredTiger:

    # how the process runs
    processManagement:
      fork: true  # fork and run in background
      pidFilePath: /opt/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.
      http:
        enabled: true
        JSONPEnabled: true
        RESTInterfaceEnabled: true
    setParameter:
       enableLocalhostAuthBypass: false

    #security:

    #operationProfiling:

    #replication:

    #sharding:

    ## Enterprise-Only Options

    #auditLog:

    #snmp:
    更多参数和解释请参看官方文档

    5.init管控脚本
    useradd -s /sbin/nologin -r mongod
    chown -R mongod: /opt/mongodb-linux-x86_64-rhel62-3.2.0
    cp /usr/local/src/mongodb-src-r3.2.0/rpm/init.d-mongod /etc/init.d/mongod
    chmod +x /etc/init.d/mongod
    sed -i '/CONFIGFILE=/i MONGOD="/opt/mongodb/bin/mongod"' /etc/init.d/mongod
    sed -i '/CONFIGFILE=/s:/etc/mongod.conf:/opt/mongodb/conf/mongod.conf:g' /etc/init.d/mongod
    mongoDB-3.x安装配置(单机版)
    或systemd
    cat >/lib/system/systemd/mongod.service <<HERE
    [Unit]
    Description=mongoDB
    After=network-online.target

    [Service]
    Type=forking
    User=mongod
    Group=mongod
    LimitNOFILE=65536
    ExecStart=/opt/mongodb/bin/mongod -f /opt/mongodb/conf/mongod.conf

    KillMode=control-group
    Restart=on-failure

    [Install]
    WantedBy=multi-user.target

    HERE
    systemctl daemon-reload


    6.修改内核参数
    cat >>/etc/rc.d/rc.local <<HERE
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    echo never > /sys/kernel/mm/transparent_hugepage/defrag
    HERE
    或者加入/etc/rc.sysinit末尾

    7.优化系统资源限制

    Recommended ulimit Settings

    Every deployment may have unique requirements and settings; however, the following thresholds and settings are particularly important for mongod and mongos deployments:

    • -f (file size): unlimited
    • -t (cpu time): unlimited
    • -v (virtual memory): unlimited [1]
    • -n (open files): 64000
    • -m (memory size): unlimited [1] [2]
    • -u (processes/threads): 64000

    Always remember to restart your mongod and mongos instances after changing the ulimit settings to ensure that the changes take effect.

    cat >/etc/security/limits.d/99-mongodb-nproc.conf <<HERE
    mongod soft fsize unlimited 
    mongod soft cpu unlimited 
    mongod soft as unlimited 
    mongod soft nofile 64000 
    mongod soft nproc 64000 
    mongod hard fsize unlimited 
    mongod hard cpu unlimited 
    mongod hard as unlimited 
    mongod hard nofile 64000 
    mongod hard nproc 64000 
    HERE



    方式三 : 源码安装
    1.升级gcc,g++(>=4.8.2)

    2.升级scons
    rpm -ivh scons-2.4.1-1.noarch.rpm 

    3.安装
    tar -xvf /mnt/samba/mongodb-src-r3.2.0.gz  -C /usr/local/src
    cd /usr/local/src/mongodb-src-r3.2.0
    scons --prefix=/opt/mongodb --full install

  • 相关阅读:
    setInterval的停止与启动
    postgresql常用
    STM32学习笔记(四) RCC外设的学习和理解
    STM32学习笔记(九) 外部中断,待机模式和事件唤醒
    STM32的优先级的理解及其使用
    基于STM32的红外遥控重点解析
    红外协议之NEC协议
    常用运放选型一览表
    运放参数解释及常用运放选型
    算放大器分析----虚短和虚断(转载)
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814273.html
Copyright © 2020-2023  润新知