• mongodb多实例部署


    安装与管理MongoDB

    1.安装解压源码包

    [root@bogon ~]# tar xf mongodb-linux-x86_64-rhel70-4.0.6.tgz

    [root@bogon ~]# mv mongodb-linux-x86_64-rhel70-4.0.6/ /usr/local/mongodb

    2.指定一个进程同一时间最多可开启的文件数

    [root@bogon ~]# ulimit -n

    1024

    [root@bogon ~]# ulimit -n 65535

    [root@bogon ~]# ulimit -n

    65535

    3.用户最多可开启的程序数目

    [root@bogon ~]# ulimit -u

    11690

    [root@bogon ~]# ulimit -u 65535

    [root@bogon ~]# ulimit -u

    65535

    4.创建数据目录,日志文件及目录并创建相应的配置文件

    [root@mongodb ~]# mkdir -p /data/mongodb1

    [root@mongodb ~]# mkdir -p /data/logs/mongodb

    [root@mongodb ~]# touch /data/logs/mongodb/mongodb1.log

    [root@mongodb ~]# cd /usr/local/mongodb/

    [root@mongodb mongodb]# ls

    bin  LICENSE-Community.txt  MPL-2  README  THIRD-PARTY-NOTICES

    [root@mongodb mongodb]# mkdir conf

    [root@mongodb mongodb]# vim conf/mongodb1.conf

    port=27017

    dbpath=/data/mongodb1

    logpath=/data/logs/mongodb/mongodb1.log

    logappend=true

    fork=true

    maxConns=5000

    storageEngine=mmapv1

    5.启动MongoDB数据库,-f指定配置文件

    [root@mongodb mongodb]# /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf

    about to fork child process, waiting until server is ready for connections.

    forked process: 2324

    child process started successfully, parent exiting

    [root@mongodb mongodb]# netstat -anpt |grep mongod

    tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2324/mongod

       

    6.设置开机自动启动

    [root@mongodb mongodb]# vim /etc/rc.local

    rm -f /data/mongodb1/mongod.lock

    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf

    7.连接数据库

    [root@mongodb ~]# /usr/local/mongodb/bin/mongo

    > show dbs

    admin   0.078GB

    config  0.078GB

    local   0.078GB

    > exit

    bye

    1. 开启服务与关闭服务

    [root@mongodb~]#/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf --shutdown

    killing process with pid: 2806

    [root@mongodb ~]# netstat -anpt |grep mongod

    [root@mongodb~]#/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf

    about to fork child process, waiting until server is ready for connections.

    forked process: 2885

    child process started successfully, parent exiting

    [root@mongodb ~]# netstat -anpt |grep mongod

    tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2885/mongod   

    1. 开启多个实例(两个)

    [root@mongodb ~]# cd /usr/local/mongodb/

    [root@mongodb mongodb]# cd conf/

    [root@mongodb conf]# cp mongodb1.conf mongodb2.conf

    [root@mongodb conf]# vim mongodb2.conf

    [root@mongodb conf]# mkdir /data/mongodb2

    [root@mongodb conf]# touch /data/logs/mongodb/mongodb2.log

    [root@mongodb conf]# chmod 777 /data/logs/mongodb/mongodb2.log

    1. 编写启动停止脚本管理多个实例

    [root@mongodb ~]# cd /etc/init.d

    [root@mongodb init.d]# vim mongodb

    #!/bin/bash

    INSTANCE=$1

    ACTION=$2

    case "$ACTION" in

    'start')

    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf;;

    'stop')

    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf --shutdown;;

    'restart')

    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf --shutdown

    /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf;;

    esac

    [root@mongodb init.d]# chmod +x mongodb

    [root@mongodb ~]# /etc/init.d/mongodb mongodb1 start

    [root@mongodb ~]# /etc/init.d/mongodb mongodb2 start

    [root@mongodb ~]# netstat -anpt |grep mongod

    tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2885/mongod         

    tcp        0      0 127.0.0.1:27018         0.0.0.0:*               LISTEN      3204/mongod

  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    http 请求code状态码
    js 跳转链接
    a标签-伪类
    在linux中如何解压.tgz
    dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
    nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
    微信小程序实现左滑删除效果(原生/uni-app)
  • 原文地址:https://www.cnblogs.com/zc1741845455/p/10921248.html
Copyright © 2020-2023  润新知