1、下载地址
https://www.mongodb.com/try/download/community
2、安装过程
关闭THP,提高性能
# vim /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
创建用户和工作目录
# useradd -d /mongodb mongodb
# mkdir /mongodb/{conf,log,data}
# tar -zxvf mongodb-linux-x86_64-rhel70-4.2.8.tgz
# mv mongodb-linux-x86_64-rhel70-4.2.8/bin/ /mongodb/
# chown mongodb.mongodb /mongodb/ -R
# su - mongodb
# vim .base_profile
export PATH=/mongodb/bin:$PATH:$HOME/.local/bin:$HOME/bin
启动运行 mongodb
## 编辑配置文件
$ cat conf/mongo.conf
systemLog:
destination: file
path: "/mongodb/log/mongodb.log"
logAppend: true
storage:
journal:
enabled: true
dbPath: "/mongodb/data/"
processManagement:
fork: true
net:
port: 27017
bindIp: 0.0.0.0
## 启动 mongodb
$ mongod -f conf/mongo.conf
## 停止 mongodb
$ mongod -f conf/mongo.conf --shutdown
基本操作
## 进入 mongodb
$ mongo
## 查看版本
> db.version()
4.2.8
## 显示当前所在的库
> db
test
> db.getName()
test
## 显示所有的库
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
## 切换库
> use admin
switched to db admin
## 显示当前库状态信息
> db.stats()
{
"db" : "admin",
"collections" : 1,
"views" : 0,
"objects" : 1,
"avgObjSize" : 59,
"dataSize" : 59,
"storageSize" : 20480,
"numExtents" : 0,
"indexes" : 1,
"indexSize" : 20480,
"scaleFactor" : 1,
"fsUsedSize" : 7321313280,
"fsTotalSize" : 30050091008,
"ok" : 1
}
## 显示连接地址信息
> db.getMongo()
connection to 127.0.0.1:27017
标签:bin,安装,##,mongodb,db,conf,过程,transparent
From: https://www.cnblogs.com/zbc230/p/17497268.html