网上的安装流程有点乱,很多都是定制化的流程。自己是小白,那么些配置不太懂。因此写了这一篇。
参考来源
我的系统是centos7.8 mini版,参考的这里
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
网上很多步骤都没有官网的详细,英语无障碍的话还是读原文档的好。
操作流程
我采用的流程如下:
1,配置yum文件
Configure the package management system (yum).
Create a /etc/yum.repos.d/mongodb-org-4.4.repo file so that you can install MongoDB directly using yum:
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
You can also download the .rpm files directly from the MongoDB repository. Downloads are organized by Red Hat / CentOS version (e.g. 7), then MongoDB release version (e.g. 4.4), then architecture (e.g. x86_64). Odd-numbered MongoDB release versions, such as 4.3, are development versions and are unsuitable for production deployment.
2,安装
sudo yum install -y mongodb-org
3,启动
这里有两种启动方式,我选择了其中一种
sudo systemctl start mongod
验证是否启动
sudo systemctl status mongod
这里原文档中详细介绍了可能会遇到的问题。(我没遇到,貌似因为我的系统是干净的)
停止服务
sudo systemctl stop mongod
4,开始使用
mongo
这里没写配置。默认端口是27017
配置文件如下
vi /etc/mongod.conf