1.在mongodb 官网找到自己想要安装的mongodb版本
www.mongodb.com
https://www.mongodb.com/download-center/community
wget https://repo.mongodb.org/yum/redhat/6/mongodb-org/4.0/x86_64/RPMS/mongodb-org-server-4.0.9-1.el6.x86_64.rpm

Create a /etc/yum.repos.d/mongodb-org-4.0.repo file so that you can install MongoDB directly using yum:
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
要将gpgcheck改为0,不然下面的安装步骤会报错
yum install -y mongodb-org

You can specify any available version of MongoDB. However yum upgrades the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. To pin a package, add the following exclude directive to your /etc/yum.conf file:
vim /etc/yum.conf
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools
2.rpm安装方式自动创建目录,并且属主和属组都为mongod
/var/lib/mongo (the data directory)
/var/log/mongodb (the log directory)
3.1)start MongoDB
service mongod start
2)开机启动
chkconfig mongod on
3)stop MongoDB
service mongod stop
4)restart MongoDB
service mongod restart
5)Begin using MongoDB
mongo
网友评论