mongodb
https://www.mongodb.com/try/download/community
rpm -ivh mongodb-org-server-6.0.5-1.el7.x86_64.rpm
mongod --dbpath /home/chengzhong/soft/mongo_data
检测是否安装成功
curl http://localhost:27017
1.冷拷数据:
cp -r mongo_data/ mongo_data_bak/
ps -ef|grep mongod
kill -9 14758 或 mongod --port=27017 --dbpath=/mongodb/data --shutdown
mongod --dbpath /home/chengzhong/soft/mongo_data_bak/
看启动日志:
{"t":{"$date":"2023-03-14T12:09:59.138+08:00"},"s":"I", "c":"FTDC", "id":20625, "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/home/chengzhong/soft/mongo_data_bak/diagnostic.data"}} {"t":{"$date":"2023-03-14T12:09:59.144+08:00"},"s":"I", "c":"REPL", "id":6015317, "ctx":"initandlisten","msg":"Setting new configuration state","attr":{"newState":"ConfigReplicationDisabled","oldState":"ConfigPreStart"}} {"t":{"$date":"2023-03-14T12:09:59.144+08:00"},"s":"I", "c":"STORAGE", "id":22262, "ctx":"initandlisten","msg":"Timestamp monitor starting"} {"t":{"$date":"2023-03-14T12:09:59.146+08:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27017.sock"}} {"t":{"$date":"2023-03-14T12:09:59.146+08:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"127.0.0.1"}} {"t":{"$date":"2023-03-14T12:09:59.146+08:00"},"s":"I", "c":"NETWORK", "id":23016, "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}} {"t":{"$date":"2023-03-14T12:10:00.066+08:00"},"s":"I", "c":"FTDC", "id":20631, "ctx":"ftdc","msg":"Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost","attr":{"error":{"code":0,"codeName":"OK"}}} {"t":{"$date":"2023-03-14T12:10:08.414+08:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:40592","uuid":"0a588590-cf8d-43a5-9aee-5407384abeb7","connectionId":1,"connectionCount":1}}
2.设置内存
mongod.conf
storage: dbPath: /data/mongodb/db journal: enabled: true engine: wiredTiger # 如下配置仅对 wiredTiger 引擎生效(3.0 以上版本) wiredTiger: # wiredTiger 缓存工作集(working set)数据的内存大小,单位:GB # 此值决定了 wiredTiger 与 mmapv1 的内存模型不同,它可以限制 mongod 对内存的使用量,而 mmapv1 则不能(依赖于系统级的 mmap)。默认情况下,cacheSizeGB 的值为假定当前节点只部署一个 mongod 实例,此值的大小为物理内存的一半;如果当前节点部署了多个 mongod 进程,那么需要合理配置此值。如果 mongod 部署在虚拟容器中(比如,lxc,cgroups,Docker)等,它将不能使用整个系统的物理内存,则需要适当调整此值。默认值为物理内存的一半。 engineConfig: cacheSizeGB: 5 systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log net: port: 27017 bindIp: 0.0.0.0 maxIncomingConnections: 10000
3.安装注意事项
4.2.24.tgz包有较多命令文件,而新版本要么没有tgz包。如果安装server包,命令很少。要么有tgz包,解压后命令很少。
4.mongo大数据量,低配置,查询速度如何
数据量,1.2亿:
使用上索引,explain查询速度:
从上图看,只需要5毫秒
看机器配置,cpu2核,内存8G
实际查询时间,主要是网络时间与解析时间:
分片:
配置 ./mongod --config /home/chengzhong/soft/mongo/conf/mongo1.conf ./mongod --config /home/chengzhong/soft/mongo/conf/mongo2.conf ./mongod --config /home/chengzhong/soft/mongo/conf/mongo3.conf ./mongo 192.168.1.7:28021 rs.initiate() rs.add("192.168.1.7:28032") rs.add({host:"192.168.1.7:28023",arbiterOnly:true}) mongos ./mongo 192.168.1.7:29000 use admin db.runCommand({addShard:'ds1/192.168.1.7:28011,192.168.1.7:28012,192.168.1.7:28013'}) db.runCommand({addShard:'ds2/192.168.1.7:28021,192.168.1.7:28022,192.168.1.7:28023'}) db.runCommand({addShard:'ds3/192.168.1.7:28031,192.168.1.7:28032,192.168.1.7:28033'}) 分片的库与表、片键 db.runCommand({enablesharding:'test'}) db.runCommand({shardcollection: 'test.col_student',key: {name: 1}}) db.runCommand({shardcollection: 'test.col_score',key: {_id: "hashed"}})
相关阅读
评论:
↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑