目录
安装
1.下载mongodb的公钥
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
若提示gnupg未安装,执行
sudo apt-get install gnupg
安装完成后,再执行第一步骤
2.更新apt-get的source-list源文件
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
3.重新加载本地apt-get包
sudo apt-get update
4.安装mongodb
sudo apt-get install -y mongodb-org
启动与停止
sudo service mongod start #启动服务
sudo service mongod status #查看状态
sudo service mongod stop #停止服务
sudo service mongod restart #重启服务
进入shell
mongosh
配置文件格式
mongod.conf默认存放位置为/etc/mongod.conf
通过修改配置文件,可以指定日志存放目录以及数据存储目录以及其他信息
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
# engine:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
若有其他问题,欢迎评论区交流!