杭州市江干建设局网站互联网营销师教材
查看MongoDB版本可以执行如下命令
mongod --version 
 
 
如果是Ubuntu,则直接安装
sudo apt-get install -y mongodb
 
 
如果是其他,比如Amazon Linux2。
查看Linux系统发行版类型
grep ^NAME  /etc/*release 
如果是 Amazon Linux 2,则创建一个repo文件 在这里
/etc/yum.repos.d/mongodb-org-7.0.repo 
其中代码如下
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/7.0/aarch64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
 
然后开始安装
sudo yum install -y mongodb-org
 
查看使用哪一种 init 系统命令行
ps --no-headers -o comm 1 
Then select the appropriate tab below based on the result:
-  
systemd- select the systemd (systemctl) tab below. -  
init- select the System V Init (service) tab below. 
启动MongoDB
sudo systemctl start mongod
 
如果报下面错,
Failed to start mongod.service: Unit mongod.service not found. 
则需要
sudo systemctl daemon-reload
 
查看是否启动成功
sudo systemctl status mongod
 
如果系统经过重启,可以
sudo systemctl enable mongod
 
 
 
参见:Install MongoDB Community Edition on Amazon Linux — MongoDB Manual
