網(wǎng)上找一篇孵构,通過(guò)編輯mongodb的yum源安裝:
第一步:設(shè)置mongodb的yum源
cd /etc/yum.repos.d/
[root@wangerxiao yum.repos.d]# vim mongodb.repo
在文件中添加一下內(nèi)容:
[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
安裝過(guò)程有點(diǎn)長(zhǎng)哦
安裝完成,可以驗(yàn)證一下:
[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
第三步:設(shè)置開(kāi)機(jī)自啟動(dòng)
[root@wangerxiao ~]# systemctl enable mongod.service
[root@wangerxiao ~]# systemctl start mongod.service
[root@wangerxiao ~]# systemctl status mongod.service
第四步:測(cè)試
[root@wangerxiao ~]# mongo #啟動(dòng)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