mongodb 3.2 鍒嗙墖閮ㄧ讲姝ラ

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mongodb 3.2 鍒嗙墖閮ㄧ讲姝ラ相关的知识,希望对你有一定的参考价值。

鏍囩锛?/p>

#linux 缃戠粶浼樺寲1. 鏂囦欢涓?etc/sysctl.conf, 鍔犲叆
net.core.somaxconn = 2048
fs.file-max = 2000000
fs.nr_open = 2000000
net.ipv4.ip_local_port_range = 1024 65535

  • hard nofile 1000000
  • soft nofile 1000000
2. 鏂囦欢/etc/security/limits.conf涓姞鍏?
  • hard nproc 1000000
  • hard nproc 1000000

    3. mongo閮ㄥ垎鐨勪紭鍖?br />echo never >/sys/kernel/mm/transparent_hugepage/enabled
    echo never > /sys/kernel/mm/transparent_hugepage/defrag

 

  1. disable senux
    /etc/selinux/config
    SELINUX=disabled
  1. 闃茬伀澧欓儴鍒? 鏆傛椂鍋滄firewalld
    firewall锛?br />systemctl start firewalld.service #鍚姩firewall
    systemctl stop firewalld.service #鍋滄firewall
    systemctl disable firewalld.service #绂佹firewall寮€鏈哄惎鍔?/li>
  1. mongodb 瀹夎
    濡傛灉鏄В鍘嬪畨瑁? 榛樿鏀惧埌 /tools
    1. 瑙e帇鍒?br />/root/tools/mongodb
    cd /
    ln -s /root/tools

    2. 鍔犲叆PATH
    vim /etc/profile
    export PATH=$PATH:/tools/mongodb/bin

    瀵逛簬rpm鍖? 杩愯涓嬮潰鍛戒护
    rpm -ivh *.rpm

  1. 閰嶇疆mongodb
    mkdir /data/mongodb
    cd /data/mongodb
    mkdir db log

    甯歌閰嶇疆鏂囦欢, 骞跺惎鍔?br />mongod --config configdb.conf

=====================================
https://docs.mongodb.org/manual/tutorial/deploy-shard-cluster/

  1. 閰嶇疆璇存槑 
    234鏈哄櫒涓?
    shard0 192.168.1.234:27018
    shard1 192.168.1.234:27019 
    configsrv 192.168.1.234:30001
  1. 閰嶇疆 configserver
    1. 鏂囦欢閰嶇疆鐨勪緥瀛?br />sharding:
    clusterRole: configsvr
    replication:
    replSetName: configReplSet
    net:
    port: <port>
    storage:
    dbpath: <path>

    2. 鍚姩
    mongod --config configsrv1.conf
    闈炴枃浠舵柟寮?br />mongod --configsvr --replSet configReplSet --port <port> --dbpath <path>

  1. 鍒濆鍖朿onfigserver, 杩欓噷閰嶇疆涓や釜 configure
    1. 杩涘叆mongo shell
    mongo 192.168.1.234:30001
    rs.initiate( {
    _id: "configReplSet",
    configsvr: true,
    members: [ { _id: 0, host: "192.168.1.55:30001" }, { _id: 1, host: "192.168.1.234:30001" }
    ]
    } )

    2. 鏌ョ湅鐘舵€?br />rs.status()

  2. start mongos
    //mongos --configdb configReplSet/192.168.1.55:30001,192.168.1.234:30001 --port 37017&
    mongos --configdb configRS/192.168.1.234:30001 --port 37017 --logappend --logpath /data/mongodb/log/route.log&
  1. connect to mongos
    mongo --host 192.168.1.234 --port 37017
  1. add sharding
    1. 寤虹珛瀹炰緥
    mkdir db2 db3
    淇敼瀵瑰簲鐨勯厤缃枃浠?br />Note锛?杩欎釜鍦版柟闇€瑕佽缃渶澶у唴瀛?br />ulimit -v 10000000 淇敼鏈€澶ц櫄鎷熷湴鍧€绌洪棿涓?0G 
    --wiredTigerCacheSizeGB 5

    2. 鍔犲叆鍒嗙墖
    // sh.addShard( "rs1/192.168.1.234:27018" ) // add a shard for a replica set named rs1 
    sh.addShard( "192.168.1.234:27018" )
    sh.addShard( "192.168.1.234:27019" )

    3. 婵€娲诲垎鐗?br />sh.enableSharding("<database>") // db.runCommand( { enableSharding: <database> } )
    sh.enableSharding("mydb")

    4. 鏌ョ湅鐘舵€?br />sh.status()

#########################
鎻掑叆鍓嶇殑鍑嗗
sh.enableSharding("<database>") // db.runCommand( { enableSharding: <database> } )
sh.enableSharding("gwgps")

db.location.ensureIndex({"hostid":1})
db.location.ensureIndex({"posTime":1})

sh.shardCollection("gwgps.location", { "hostid": 1})

以上是关于mongodb 3.2 鍒嗙墖閮ㄧ讲姝ラ的主要内容,如果未能解决你的问题,请参考以下文章

mongodb 4.2鍗曟満閮ㄧ讲

锛?锛塸rometheus瀹夎閮ㄧ讲

Springboot 鎵撳寘閮ㄧ讲

Flask 鍜?Google App Engine 閮ㄧ讲妯″瀷鏈嶅姟

Linux涔媋nt瀹夎閮ㄧ讲

Docker閮ㄧ讲Egg.js搴旂敤