標籤:
#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中加入:
- disable senux
/etc/selinux/config
SELINUX=disabled
- 防火牆部分, 暫時停止firewalld
firewall:
systemctl start firewalld.service #啟動firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
- mongodb 安裝
如果是解壓安裝, 預設放到 /tools
1. 解壓到
/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常見設定檔, 並啟動
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. 檔案配置的例子
sharding:
clusterRole: configsvr
replication:
replSetName: configReplSet
net:
port: <port>
storage:
dbpath: <path>2. 啟動
mongod --config configsrv1.conf
非檔案方式
mongod --configsvr --replSet configReplSet --port <port> --dbpath <path>
- 初始化configserver, 這裡配置兩個 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. 查看狀態
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
修改對應的設定檔
Note: 這個地方需要設定最大記憶體
ulimit -v 10000000 修改最大虛擬位址空間為10G
--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. 啟用分區
sh.enableSharding("<database>") // db.runCommand( { enableSharding: <database> } )
sh.enableSharding("mydb")
4. 查看狀態
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 分區部署步驟