• Mongodb 副本集分片(一)---初始化mongodb安装启动


    写在前面:mongodb是nosql非关系型数据库中,比较受欢迎的产品。在数据持久化及与关系型数据库的关联上也做的比较好,目前各大公司在存放二进制文件(图片、视频等)中应用也比较广泛。其遵循的key-value的数据模式及面向对象的json语句用法,也比较简单。在之后,会系列的跟大家分享,我在学习及生产应用中,使用到的mongodb的一些心得。希望大家共同学习,共同研究探讨。谢谢。

    以下内容,是简单的将整个mongodb的安装过程,进行shell脚本化编辑。很简单的脚本编写。如有任何问题,欢迎大家反馈并与我联系。大家使用过程中,可以将整段内容粘贴至类似mongodbinit.sh的文本脚本中。chmod修改权限+x。之后执行即可。

    注:replSet为副本集名称,可以自由编辑设定,本示例中使用replSet=picture。当使用db.shutdownServer()来关闭db时,只接受本地连接。

    ###install mongodb bags###
    yum install -y openssl-devel openssl
    cd /opt/
    wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.2.tgz
    tar zxvf /opt/mongodb-linux-x86_64-rhel62-3.0.2.tgz -C /usr/local/
    ln -s /usr/local/mongodb-linux-x86_64-rhel62-3.0.2 /usr/local/mongodb-3.0.2

    ###configure limit parameters###
    cat >> /etc/security/limits.conf << EOF
    * soft nofile   655350
    * hard nofile   655350
    * soft nproc    65535
    * hard nproc    65535
    * soft core             unlimited
    * hard core             unlimited
    * soft memlock  50000000
    * hard memlock  50000000
    EOF

    ###prepare the menu for data or logs###
    mkdir -pv /usr/local/mongodb-3.0.2/{data,logs,socket}
    mkdir -pv /var/run/mongodb

    ###edit mongodb config file###
    parastr=(  
    "dbpath=/usr/local/mongodb-3.0.2/data"  
    "logpath=/usr/local/mongodb-3.0.2/logs/mongo.log"  
    "pidfilepath=/var/run/mongodb/mongodb.pid"  
    "unixSocketPrefix=/usr/local/mongodb-3.0.2/socket"  
    "directoryperdb=true"  
    "replSet=picture"
    "shardsvr=true"
    "logappend=true"  
    "bind_ip=0.0.0.0"  
    "port = 27017"
    "maxConns=20000"
    "oplogSize=30720"
    "fork=true"
    "nohttpinterface=true"
    "nojournal=true"  
    )  
     
    if [ ! -f /etc/mongodb.conf ]; then  
      size=${#parastr[@]};  
      for ((i=0;i<$size;i++))  
      do  
        eval tmp=${parastr[i][@]}  
        echo $tmp >> /etc/mongodb.conf
      done  
    fi

    ###/usr/local/mongodb-3.0.2/bin/mongod --config /etc/mongodb.conf

    cat >> /etc/init.d/mongo << EOF
    ulimit -SHn 655350
    #!/bin/sh
    # chkconfig: - 64 36
    # description:mongod

    case $1 in
        start)
        /usr/local/mongodb-3.0.2/bin/mongod --config /etc/mongodb.conf
        ;;

        stop)
        /usr/local/mongodb-3.0.2/bin/mongo 127.0.0.1:27017/admin --eval "db.shutdownServer()"
        #/usr/local/mongodb-3.0.2/bin/mongo 127.0.0.1:27017/admin --eval "db.auth('system', '123456');db.shutdownServer()"
        ;;

        status)
        /usr/local/mongodb-3.0.2/bin/mongo 127.0.0.1:27017/admin --eval "db.stats()"
        #/usr/local/mongodb-3.0.2/bin/mongo 127.0.0.1:27017/admin --eval "db.auth('system', '123456');db.stats()"
        ;;
    esac
    EOF

    chmod +x /etc/init.d/mongo

    /etc/init.d/mongo start

  • 相关阅读:
    [译]JavaScript源码转换:非破坏式与再生式
    [译]ES6中的代理对象
    tensorflow 如何获取graph中的所有tensor name
    python3中的str和bytes
    git submodule 添加 更新 删除 教程
    《重构:改善既有代码的设计》摘抄
    thrift入门教程/thrift资料集合
    将python2代码升级为python3代码最佳实践
    python标准库:subprocess——子进程管理
    安装“python-snappy”遇到“error: command 'x86_64-linux-gnu-gcc' failed with exit status 1”
  • 原文地址:https://www.cnblogs.com/EndlessPang/p/5123365.html
Copyright © 2020-2023  润新知