Centos7 under MongoDB shard configuration

Source: Internet
Author: User

  • Server architecture:
    序号                角色                ip地址                备注1                   服务器            192.168.8.81     (config  server)2                   路由                192.168.8.82     (mongos)3                   分片节点         192.168.8.83     (shard)4                   分片节点         192.168.8.84     (shard)
  • Server Configuration (192.168.8.81):
    A. Modify the configuration file:
    Vim/etc/mongod.conf
    fork = truepidfilepath = /var/run/mongodb/mongod.pidlogpath = /var/log/mongodb/mongod.logunixSocketPrefix = /var/run/mongodbdbpath = /var/lib/mongodbport=27017configsvr=true

    B. Start the service:

    systemctl  start  mongod
  • Routing Configuration (192.168.8.82):
    A. Modify the configuration file:
    Vim/etc/mongod.conf
    fork = truepidfilepath = /var/run/mongodb/mongod.pidlogpath = /var/log/mongodb/mongod.logunixSocketPrefix = /var/run/mongodb#dbpath = /var/lib/mongodb  (注释掉数据库)port=27017configdb=192.168.8.81:27017

    B. Deleting files in a database:

    rm  -rf  /var/lib/mongodb/*

    C. Start the service:

    mongos  -f  
  • Shard machine Configuration (192.168.8.83/84):
    A. Modify the configuration file:
    Vim/etc/mongod.conf
    fork = truepidfilepath = /var/run/mongodb/mongod.pidlogpath = /var/log/mongodb/mongod.logunixSocketPrefix = /var/run/mongodbdbpath = /var/lib/mongodb

    B. Start the service:

    systemctl  start  mongod
  • Test:
    A. Routing machine (192.168.8.82):
    A-1. Enter Terminal:
    mongo


    A-2. To add a shard machine:

    sh.addShard("192.168.8.83:27017")sh.addShard("192.168.8.84:27017")


    A-3. To view the status of a shard machine:

    sh.status()


    A-4. To add a shard database:

    sh.enableSharding("testdb")


    A-5. To add an index:

    sh.shardCollection("testdb.user",{name:1,age:1})


    A-6. To add test data:

    for  (i = 1;i < 100000; i++)     {            db.user.insert({name:‘user‘+i,age:(i%150),addr:‘#‘+i}    }

    B. Shard Machine (192.168.8.83/84):
    B-1. Enter Terminal:

    mongo


    B-2. To view data that has been processed by sharding:

    use  testdbdb.user.find()

  • Centos7 under MongoDB shard configuration

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.