MongoDB在Ubuntu22环境安装如下:
MongoDB版本为7.0
导入包管理系统使用的公钥
sudo apt-get install gnupg curl
导入 MongoDB 公有 GPG 密钥
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
--dearmor
为 MongoDB 创建列表文件
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
重新加载本地包数据库
sudo apt-get update
安装 MongoDB 软件包
sudo apt-get install -y mongodb-org
调整配置文件
以上方式安装的MongoDB的配置文件为
cat /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: /mongodb_data/mongodb/data
# engine:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /mongodb_data/mongodb/log/mongod.log
# network interfaces
net:
port: 9001
bindIp: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
# authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
其中,dbPath和path均为自定义路径,net为服务网络,port默认为27017
bindIp: 默认为127.0.0.1,设置为0.0.0.0则放开网络限制,
#security:
# authorization: enabled
为是否开启验证,bindIp: 0.0.0.0时必须开启验证
启动MongoDB
/usr/bin/mongod -f /etc/mongod.conf
查看进程状态
ps -ef|grep mongo
root 138176 1 0 Feb26 pts/1 00:06:32 /usr/bin/mongod -f /etc/mongod.conf
root 157011 136589 0 10:36 pts/0 00:00:00 grep --color=auto mongo
登录MongoDB
mongosh 127.0.0.1:9001
关库
验证用户后
db.shutdownServer();