我们安装的是mongodb-org4.0版本
一步步执行下列命令即可:
1.添加源
cat << EOF | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo [mongodb-org-4.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc EOF
2.安装
yum install -y mongodb-org
3.更改参数(可选)
sed -i "s/^# engine:/ engine: mmapv1/" /etc/mongod.conf
sed -i "s/^#replication:/replication: replSetName: rs01/" /etc/mongod.conf
4.启动服务并设置为开机自启
systemctl enable mongod && systemctl start mongod