怎么在Linux系统中安装MongoDB数据库

2022年 10月 16日 发表评论
腾讯云正在大促:点击直达 阿里云超级红包:点击领取
免费/便宜/高性价比服务器汇总入口(已更新):点击这里了解

本文将详细说明如何在Linux系统中安装MongoDB数据库。文章内容质量较高,本站将与大家分享,以供参考。希望大家看完这篇文章后对相关知识有一定的了解。

什么是Linux系统

Linux是一个类似Unix的操作系统,可以自由使用,自由传播。它是一个基于POSIX的多用户、多任务、多线程、多CPU的操作系统。Linux可以运行主要的UNIX工具软件、应用程序和网络协议。

Mongo DB是IT行业非常流行的非关系数据库(NoSql),其灵活的数据存储方式受到IT从业者的青睐。Mongo DB很好的实现了面向对象的思想(OO思想),Mongo DB中的每一条记录都是一个Document对象。Mongo DB最大的优点是所有的数据持久化操作都不需要开发人员手工编写SQL语句,直接调用方法就可以轻松实现CRUD操作。

一、安装配置mongodb

步骤1:设置系统环境,并确保默认端口27107可用

# # #当前环境

#cat/etc/issue

red hatenterprise LinuxServerrelease 6.5(圣地亚哥)

#vi/etc/selinux/config

SELINUX=disabledStep 2:下载安装文件

下载地址:https://www.mongodb.org/downloads.

或者使用curl命令在命令提示符下直接下载它

Curl-ohttps://fastdl.mongodb.org/Linux/mongodb-Linux-x86 _ 64-3 . 0 . 6 . tgzstep :解压缩下载的文件

#pwd

/usr/local/src

# tar-xvf MongoDB-Linux-x86 _ 64-rhel62-3.0.6.gz # # #注意,本文直接从网站下载,所以文件是. gzstep4:将提取的文件复制到运行目录。

#mkdir-p/var/lib/mongodb

# CP-r-n/usr/local/src/MongoDB-Linux-x86 _ 64-rhel 62-3 . 0 . 6/。/var/lib/MongoDB/step5:设置环境变量

例如,EXport PATH=MongoDB-install-directory/bin : $ PATH

#vi~/。bash_profile

export PATH=/var/lib/MongoDB/bin : $ PATH

# source ~/。bash _ profilestep 6:创建数据目录

# mkdir-p/data/mongodata二、启动及验证mongodb

# # #开始蒙古

#mongod - dbpath/data/mongodata

# # #以下内容为开机后输出的相关信息

2015-10-28t 10:0:33.100 0800 IJournal[init and listen]Journal dir=/data/mongodata/Journal

2015-10-28t 10:0:33.101 0800 IJournal[init and listen]recover : nojournal files present,norecoveryneeded

2015-10-28t 10:0:33.264 0800 IJournal[init and lisen]preallocateIsmaster=true 2.18

2015-10-28t 10:0:33.398 0800 IJournal[耐久性]耐久性螺纹开始

2015-10-28t 10:0:33.398 0800 I journal[journal writer]journal writerthreadstarted

2015-10-28t 10:0:33.401 0800 IControl[initand listen]Mongodbstart : PiD=10191 port=27017 db path=/data/Mongodata 64-bit host=Java _ 2

2015-10-28t 103:0:33.401 0800 IControl[init and listen]* *警告:您可以重新运行his process Thresroot user,这是不推荐的。

2015-10-28t 10:03:33.401 0800图标控制[i

nitandlisten] 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten] 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]**WARNING:/sys/kernel/mm/transparent_hugepage/enabledis'always'. 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]**Wesuggestsettingitto'never' 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten] 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]**WARNING:/sys/kernel/mm/transparent_hugepage/defragis'always'. 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]**Wesuggestsettingitto'never' 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten] 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]dbversionv3.0.6 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]gitversion:1ef45a23a4c5e3480ac919b28afcba3c615488f2 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]buildinfo:Linuxip-10-67-194-1232.6.32-220.el6.x86_64#1SMPWedNov908:03:13EST2011x86_64BOOST_LIB_VERSION=1_49 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]allocator:tcmalloc 2015-10-28T10:03:33.402+0800ICONTROL[initandlisten]options:{storage:{dbPath:"/data/mongodata"}} 2015-10-28T10:03:33.404+0800IINDEX[initandlisten]allocatingnewnsfile/data/mongodata/local.ns,fillingwithzeroes... 2015-10-28T10:03:33.491+0800ISTORAGE[FileAllocator]allocatingnewdatafile/data/mongodata/local.0,fillingwithzeroes... 2015-10-28T10:03:33.491+0800ISTORAGE[FileAllocator]creatingdirectory/data/mongodata/_tmp 2015-10-28T10:03:33.497+0800ISTORAGE[FileAllocator]doneallocatingdatafile/data/mongodata/local.0,size:64MB,took0.001secs 2015-10-28T10:03:33.511+0800INETWORK[initandlisten]waitingforconnectionsonport27017 ###停止mongo,直接使用ctrl+c ^C2015-10-28T10:09:21.510+0800ICONTROL[signalProcessingThread]gotsignal2(Interrupt),willterminateaftercurrentcmdends 2015-10-28T10:09:21.511+0800ICONTROL[signalProcessingThread]nowexiting 2015-10-28T10:09:21.511+0800INETWORK[signalProcessingThread]shutdown:goingtocloselisteningsockets... 2015-10-28T10:09:21.511+0800INETWORK[signalProcessingThread]closinglisteningsocket:5 2015-10-28T10:09:21.511+0800INETWORK[signalProcessingThread]closinglisteningsocket:6 2015-10-28T10:09:21.511+0800INETWORK[signalProcessingThread]removingsocketfile:/tmp/mongodb-27017.sock 2015-10-28T10:09:21.511+0800INETWORK[signalProcessingThread]shutdown:goingtoflushdiaglog... 2015-10-28T10:09:21.511+0800INETWORK[signalProcessingThread]shutdown:goingtoclosesockets... 2015-10-28T10:09:21.512+0800ISTORAGE[signalProcessingThread]shutdown:waitingforfspreallocator... 2015-10-28T10:09:21.512+0800ISTORAGE[signalProcessingThread]shutdown:finalcommit... 2015-10-28T10:09:21.512+0800IJOURNAL[signalProcessingThread]journalCleanup... 2015-10-28T10:09:21.512+0800IJOURNAL[signalProcessingThread]removeJournalFiles 2015-10-28T10:09:21.515+0800IJOURNAL[signalProcessingThread]Terminatingdurabilitythread... 2015-10-28T10:09:21.615+0800IJOURNAL[journalwriter]Journalwriterthreadstopped 2015-10-28T10:09:21.615+0800IJOURNAL[durability]Durabilitythreadstopped 2015-10-28T10:09:21.615+0800ISTORAGE[signalProcessingThread]shutdown:closingallfiles... 2015-10-28T10:09:21.618+0800ISTORAGE[signalProcessingThread]closeAllFiles()finished 2015-10-28T10:09:21.618+0800ISTORAGE[signalProcessingThread]shutdown:removingfslock... 2015-10-28T10:09:21.618+0800ICONTROL[signalProcessingThread]dbexit:rc:0 ###修复启动过程中的两个警告,关于使用root用户启动mongo的警告先忽略 #echo"never">/sys/kernel/mm/transparent_hugepage/enabled #echo"never">/sys/kernel/mm/transparent_hugepage/defrag ###再次重启,后置于后台进程, #mongod--dbpath/data/mongodata& ###查看启动后的进程 #ps-ef|grepmongo|grep-vgrep root1111527956010:11pts/200:00:00mongod--dbpath/data/mongodata #lsof-i:27017 COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAME mongod11115root5uIPv4505671190t0TCP*:27017(LISTEN) ###使用mongo连接到mongod #mongo MongoDBshellversion:3.0.6 connectingto:test 2015-10-28T10:14:30.685+0800INETWORK[initandlisten]connectionacceptedfrom127.0.0.1:53907#1(1connectionnowopen) Serverhasstartupwarnings: 2015-10-28T10:11:49.217+0800ICONTROL[initandlisten]**WARNING:Youarerunningthisprocessastherootuser,whichisnotrecommended. 2015-10-28T10:11:49.217+0800ICONTROL[initandlisten] >help db.help()helpondbmethods db.mycoll.help()helponcollectionmethods sh.help()shardinghelpers rs.help()replicasethelpers helpadminadministrativehelp helpconnectconnectingtoadbhelp helpkeyskeyshortcuts helpmiscmiscthingstoknow helpmrmapreduce showdbsshowdatabasenames showcollectionsshowcollectionsincurrentdatabase showusersshowusersincurrentdatabase showprofileshowmostrecentsystem.profileentrieswithtime>=1ms showlogsshowtheaccessibleloggernames showlog[name]printsoutthelastsegmentofloginmemory,'global'isdefault use<db_name>setcurrentdatabase db.foo.find()listobjectsincollectionfoo db.foo.find({a:1})listobjectsinfoowherea==1 itresultofthelastlineevaluated;usetofurtheriterate DBQuery.shellBatchSize=xsetdefaultnumberofitemstodisplayonshell exitquitthemongoshell >db.getCollection("version"); test.version >exit bye

三、mongodb相关工具

###在安装文件下有README,描述了常用的mongodb相关命令行工具  #more/usr/local/mongodb/README  MongoDBREADME  WelcometoMongoDB!  COMPONENTS  bin/mongod-Thedatabaseprocess.  bin/mongos-Shardingcontroller.  bin/mongo-Thedatabaseshell(usesinteractivejavascript).  UTILITIES  bin/mongodump-MongoDBdumptool-forbackups,snapshots,etc..  bin/mongorestore-MongoDBrestoreadump  bin/mongoexport-Exportasinglecollectiontotest(JSON,CSV)  bin/mongoimport-ImportfromJSONorCSV  bin/mongofiles-UtilityforputtingandgettingfilesfromMongoDBGridFS  bin/mongostat-Showperformancestatistics  RUNNING  Forcommandlineoptionsinvoke:  $./mongod--help  Torunasingleserverdatabase:  $mkdir/data/db  $./mongod  $  $#Themongojavascriptshellconnectstolocalhostandtestdatabasebydefault:  $./mongo  >help  DRIVERS  Clientdriversformostprogramminglanguagesareavailableatmongodb.org.Usethe  shell("mongo")foradministrativetasks.  ###获取单个命令用法  #<command>--help  #mongod--help|more  Options:  Generaloptions:  -h[--help]showthisusageinformation  --versionshowversioninformation  #mongod--version  dbversionv3.0.6  gitversion:1ef45a23a4c5e3480ac919b28afcba3c615488f2

关于怎么在Linux系统中安装MongoDB数据库就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

小咸鱼

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: