网上找一篇,通过编辑mongodb的yum源安装:
第一步:设置mongodb的yum源
cd /etc/yum.repos.d/
[root@wangerxiao yum.repos.d]# vim mongodb.repo
在文件中添加一下内容:
[MongoDb]
name=mongo repo baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=0
enabled=1
第二步:安装mongodb
yum install mongodb-org
安装过程有点长哦
安装完成,可以验证一下:
[root@wangerxiao ~]# mongod --version
db version v3.4.1
git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
第三步:设置开机自启动
[root@wangerxiao ~]# systemctl enable mongod.service
[root@wangerxiao ~]# systemctl start mongod.service
[root@wangerxiao ~]# systemctl status mongod.service
第四步:测试
[root@wangerxiao ~]# mongo #启动mongodb
> show dbs;
admin 0.000GB
local 0.000GB
> use dnt
switched to db dnt
> db.user.save({name:'dnt',mobile:'13677834654'})
WriteResult({ "nInserted" : 1 })
> db.user.find()
{ "_id" : ObjectId("5885bbae60d9e4b21544b1b4"), "name" : "dnt", "mobile" : "13677834654" }
> exit
bye