mongodb官网:Download MongoDB Community Server | MongoDB
需要注意,在ubantu20.04LTS开始,OPENSSL1.1.x系列已经被OPENSSL3.0取代,如果要安装mongodb4.4.2的话是安装不了的.
所以这里安装的是7.0.8,也是长期稳定版.
导入 MongoDB 公钥:
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
添加 MongoDB 存储库:
echo "deb [ arch=amd64,arm64 ] 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-get update
安装 MongoDB:安装 MongoDB 7.0.8 版本。如果你需要安装特定版本,可以指定版本号,否则将安装存储库中的默认版本。
sudo apt-get install -y mongodb-org=7.0.8 mongodb-org-server=7.0.8 mongodb-org-shell=7.0.8 mongodb-org-mongos=7.0.8 mongodb-org-tools=7.0.8
启动 MongoDB:启动 MongoDB 服务,并设置为开机自启。
sudo systemctl daemon-reload
sudo systemctl start mongod
sudo systemctl enable mongod
配置 MongoDB:根据需要编辑 MongoDB 的配置文件 /etc/mongod.conf
。
重启 MongoDB 服务(如果进行了配置更改):
sudo systemctl restart mongod
验证安装:检查 MongoDB 服务是否正在运行。
sudo systemctl status mongod