在CentOS 7上安装MongoDB数据库,可以通过以下步骤完成:,,1. **配置Yum源**:, ``bash, sudo vi /etc/yum.repos.d/mongodb-org.repo,
`, 将以下内容添加到文件中:,
`plaintext, [mongodb-org-6.0], name=MongoDB Repository, baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/, gpgcheck=1, enabled=1, gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc,
`,,2. **安装MongoDB**:,
`bash, sudo yum install -y mongodb-org,
`,,3. **启动MongoDB服务**:,
`bash, sudo systemctl start mongod,
`,,4. **设置MongoDB开机自启动**:,
`bash, sudo systemctl enable mongod,
`,,5. **验证MongoDB是否成功启动**:,
`bash, sudo systemctl status mongod,
`,,卸载MongoDB的步骤如下:,,1. **停止MongoDB服务**:,
`bash, sudo systemctl stop mongod,
`,,2. **删除MongoDB软件包**:,
`bash, sudo yum remove mongodb-org -y,
`,,3. **删除数据和日志文件**:,
`bash, sudo rm -rf /var/log/mongodb, sudo rm -rf /var/lib/mongo,
`,,4. **清理残留的用户和组**:,
`bash, sudo userdel mongodb,
`,,5. **清理配置文件和库文件**:,
`bash, sudo rm -f /etc/yum.repos.d/mongodb-org.repo, sudo yum clean all,
``