zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    [LeetCode] Implement Queue using Stacks 用栈来实现队列
    [LeetCode] Power of Two 判断2的次方数
    [LeetCode] 230. Kth Smallest Element in a BST 二叉搜索树中的第K小的元素
    cvReleaseImage 释放内存出错
    FlyCapture2 fc2Image OpenCV IplImage Conversion 两种图像格式之间的转换
    FlyCapture2 Qt5 MinGW Configuration
    [LeetCode] 14. Longest Common Prefix 最长共同前缀
    [LeetCode] 19. Remove Nth Node From End of List 移除链表倒数第N个节点
    [LeetCode] 229. Majority Element II 求大多数之二
    [LeetCode] 23. Merge k Sorted Lists 合并k个有序链表
  • 原文地址:https://www.cnblogs.com/EndlessPang/p/5123365.html
Copyright © 2011-2022 走看看