debian

Debian系统如何安装MongoDB

小樊
61
2025-03-31 08:50:13
栏目: 云计算

在Debian系统上安装MongoDB,可以按照以下步骤进行:

方法一:使用官方APT仓库

  1. 导入MongoDB的GPG密钥

    wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
    
  2. 创建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
    
  3. 更新APT包列表

    sudo apt update
    
  4. 安装MongoDB

    sudo apt install -y mongodb-org
    
  5. 启动并启用MongoDB服务

    sudo systemctl start mongod
    sudo systemctl enable mongod
    
  6. 验证安装

    sudo systemctl status mongod
    mongo --eval 'db.runCommand({ connectionStatus: 1 })'
    

方法二:使用Snap包

如果你更喜欢使用Snap包管理器,可以按照以下步骤进行:

  1. 安装Snap(如果尚未安装)

    sudo apt update
    sudo apt install snapd
    
  2. 启用Snap商店

    sudo snap refresh
    sudo snap find mongodb
    
  3. 安装MongoDB

    sudo snap install mongodb-community --classic
    
  4. 启动MongoDB服务

    sudo systemctl start mongodb-community
    sudo systemctl enable mongodb-community
    
  5. 验证安装

    sudo systemctl status mongodb-community
    mongo --eval 'db.runCommand({ connectionStatus: 1 })'
    

注意事项

通过以上步骤,你应该能够在Debian系统上成功安装并运行MongoDB。

0
看了该问题的人还看了