以下是Ubuntu上配置MongoDB的详细步骤:
sudo apt update。wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -(以7.0版本为例)。echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list。sudo apt update && sudo apt install mongodb-org -y。sudo nano /etc/mongod.conf。net.port设置监听端口,默认27017;bindIp设置为0.0.0.0允许远程访问。security.authorization设为enabled启用身份验证。storage.dbPath指定数据存储路径,journal.enabled设为true启用日志。systemLog.destination设为file,path指定日志文件路径,logAppend设为true以追加方式记录日志。sudo systemctl restart mongod。sudo systemctl start mongod。sudo systemctl enable mongod。sudo systemctl status mongod。mongo,若配置了身份验证,使用mongosh "mongodb://用户名:密码@服务器IP:端口/数据库名?authSource=数据库名"。