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
- disable senux
/etc/selinux/config
SELINUX=disabled
- 闃茬伀澧欓儴鍒? 鏆傛椂鍋滄firewalld
firewall锛?br />systemctl start firewalld.service #鍚姩firewall
systemctl stop firewalld.service #鍋滄firewall
systemctl disable firewalld.service #绂佹firewall寮€鏈哄惎鍔?/li>
- mongodb 瀹夎
濡傛灉鏄В鍘嬪畨瑁? 榛樿鏀惧埌 /tools
1. 瑙e帇鍒?br />/root/tools/mongodb
cd /
ln -s /root/tools2. 鍔犲叆PATH
vim /etc/profile
export PATH=$PATH:/tools/mongodb/bin瀵逛簬rpm鍖? 杩愯涓嬮潰鍛戒护
rpm -ivh *.rpm
- 閰嶇疆mongodb
mkdir /data/mongodb
cd /data/mongodb
mkdir db log甯歌閰嶇疆鏂囦欢, 骞跺惎鍔?br />mongod --config configdb.conf
=====================================
https://docs.mongodb.org/manual/tutorial/deploy-shard-cluster/
- 閰嶇疆璇存槑
234鏈哄櫒涓?
shard0 192.168.1.234:27018
shard1 192.168.1.234:27019
configsrv 192.168.1.234:30001
- 閰嶇疆 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>
- 鍒濆鍖朿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()
- 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&
- connect to mongos
mongo --host 192.168.1.234 --port 37017
- add sharding
1. 寤虹珛瀹炰緥
mkdir db2 db3
淇敼瀵瑰簲鐨勯厤缃枃浠?br />Note锛?杩欎釜鍦版柟闇€瑕佽缃渶澶у唴瀛?br />ulimit -v 10000000 淇敼鏈€澶ц櫄鎷熷湴鍧€绌洪棿涓?0G
--wiredTigerCacheSizeGB 52. 鍔犲叆鍒嗙墖
// 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 鍒嗙墖閮ㄧ讲姝ラ的主要内容,如果未能解决你的问题,请参考以下文章