在Debian系统上安装MongoDB,可以按照以下步骤进行:
导入MongoDB的GPG密钥:
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - 创建MongoDB的APT仓库文件:
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 更新APT包列表:
sudo apt update 安装MongoDB:
sudo apt install -y mongodb-org 启动并启用MongoDB服务:
sudo systemctl start mongod sudo systemctl enable mongod 验证安装:
sudo systemctl status mongod mongo --eval 'db.runCommand({ connectionStatus: 1 })' 如果你更喜欢使用Snap包管理器,可以按照以下步骤进行:
安装Snap(如果尚未安装):
sudo apt update sudo apt install snapd 启用Snap商店:
sudo snap refresh sudo snap find mongodb 安装MongoDB:
sudo snap install mongodb-community --classic 启动MongoDB服务:
sudo systemctl start mongodb-community sudo systemctl enable mongodb-community 验证安装:
sudo systemctl status mongodb-community mongo --eval 'db.runCommand({ connectionStatus: 1 })' /var/lib/mongodb,确保该目录的权限正确。/var/log/mongodb/mongod.log,定期检查日志文件以监控MongoDB的运行状态。通过以上步骤,你应该能够在Debian系统上成功安装并运行MongoDB。