虚位以待(AD)
虚位以待(AD)
首页 > 数据库 > MongoDB数据库 > Linux下Mongodb安装和启动配置

Linux下Mongodb安装和启动配置
类别:MongoDB数据库   作者:码皇   来源:互联网   点击:

MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型。Mongo最大的特点

MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型。Mongo最大的特点是他支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引。

它的特点是高性能、易部署、易使用,存储数据非常方便。主要功能特性有:

面向集合存储,易存储对象类型的数据。

模式自由。

支持动态查询。

支持完全索引,包含内部对象。

支持查询。

支持复制和故障恢复。

使用高效的二进制数据存储,包括大型对象(如视频等)。

自动处理碎片,以支持云计算层次的扩展性

支持RUBY,PYTHON,JAVA,C++,PHP等多种语言。

文件存储格式为BSON(一种JSON的扩展)

可通过网络访问

所谓“面向集合”(Collenction-Orented),意思是数据被分组存储在数据集中,被称为一个集合(Collenction)。每个 集合在数据库中都有一个唯一的标识名,并且可以包含无限数目的文档。集合的概念类似关系型数据库(RDBMS)里的表(table),不同的是它不需要定 义任何模式(schema)。

模式自由(schema-free),意味着对于存储在mongodb数据库中的文件,我们不需要知道它的任何结构定义。如果需要的话,你完全可以把不同结构的文件存储在同一个数据库里。

存储在集合中的文档,被存储为键-值对的形式。键用于唯一标识一个文档,为字符串类型,而值则可以是各中复杂的文件类型。我们称这种存储形式为BSON(Binary Serialized dOcument Format)。

MongoDB官网下载地址:http://www.mongodb.org/downloads

    [root@localhostapp]#tarzxvfmongodb-linux-x86_64-3.4.3.tgzmongodb-linux-x86_64-3.4.3/READMEmongodb-linux-x86_64-3.4.3/THIRD-PARTY-NOTICESmongodb-linux-x86_64-3.4.3/MPL-2mongodb-linux-x86_64-3.4.3/GNU-AGPL-3.0mongodb-linux-x86_64-3.4.3/bin/mongodumpmongodb-linux-x86_64-3.4.3/bin/mongorestoremongodb-linux-x86_64-3.4.3/bin/mongoexportmongodb-linux-x86_64-3.4.3/bin/mongoimportmongodb-linux-x86_64-3.4.3/bin/mongostatmongodb-linux-x86_64-3.4.3/bin/mongotopmongodb-linux-x86_64-3.4.3/bin/bsondumpmongodb-linux-x86_64-3.4.3/bin/mongofilesmongodb-linux-x86_64-3.4.3/bin/mongooplogmongodb-linux-x86_64-3.4.3/bin/mongoreplaymongodb-linux-x86_64-3.4.3/bin/mongoperfmongodb-linux-x86_64-3.4.3/bin/mongodmongodb-linux-x86_64-3.4.3/bin/mongosmongodb-linux-x86_64-3.4.3/bin/mongo[root@localhostapp]#mvmongodb-linux-x86_64-3.4.3mongodb[root@localhostapp]#cdmongodb[root@localhostmongodb]#lsbinGNU-AGPL-3.0MPL-2READMETHIRD-PARTY-NOTICES[root@localhostmongodb]#mkdirdata[root@localhostmongodb]#mkdirlogs[root@localhostmongodb]#lsbindataGNU-AGPL-3.0logsMPL-2READMETHIRD-PARTY-NOTICES[root@localhostmongodb]#cdlogs/[root@localhostlogs]#touchmongodb.log[root@localhostlogs]#cd../bin/[root@localhostbin]#lsbsondumpmongomongodmongodumpmongoexportmongofilesmongoimportmongooplogmongoperfmongoreplaymongorestoremongosmongostatmongotop[root@localhostbin]#./mongod-port10001--dbpath=/app/mongodb/data/--logpath=/app/mongodb/logs/--logappend2017-04-13T10:18:16.690+0800FCONTROL[main]Failedglobalinitialization:FileNotOpen:logpath"/app/mongodb/logs/"shouldnameafile,notadirectory.[root@localhostbin]#./mongod-port10001--dbpath=/app/mongodb/data/--logpath=/app/mongodb/logs/mongodb.log--logappend#启动[root@localhostbin]#./mongod-port10001--dbpath=/app/mongodb/data/--logpath=/app/mongodb/logs/mongodb.log--logappend--fork#后台方式启动abouttoforkchildprocess,waitinguntilserverisreadyforconnections.forkedprocess:19542childprocessstartedsuccessfully,parentexiting[root@localhostmongodb]#cddata/[root@localhostdata]#lscollection-0-338357810244237439.wtdiagnostic.dataindex-3-338357810244237439.wtjournalmongod.lockstorage.bsonWiredTigerLAS.wtWiredTiger.turtlecollection-2-338357810244237439.wtindex-1-338357810244237439.wtindex-4-338357810244237439.wt_mdb_catalog.wtsizeStorer.wtWiredTigerWiredTiger.lockWiredTiger.wt[root@localhostdata]#ps-ef|grep-imongoroot195421010:43?00:00:07./mongod-port10001--dbpath=/app/mongodb/data/--logpath=/app/mongodb/logs/mongodb.log--logappend--forkroot195987588010:58pts/100:00:00grep-imongo[root@localhostbin]#

-dbpath 数据库路径(数据文件)

--logpath 日志文件路径

--master 指定为主机器

--slave 指定为从机器

--source 指定主机器的IP地址

--pologSize 指定日志文件大小不超过64M.因为resync是非常操作量大且耗时,最好通过设置一个足够大的oplogSize来避免resync(默认的 oplog大小是空闲磁盘大小的5%)。

--logappend 日志文件末尾添加

--port 启用端口号,如果不指定则默认27017

--fork 在后台运行

--only 指定只复制哪一个数据库

--slavedelay 指从复制检测的时间间隔

--auth 是否需要验证权限登录(用户名和密码)

    [root@localhostbin]#./mongod-hOptions:Generaloptions:-h[--help]showthisusageinformation--versionshowversioninformation-f[--config]argconfigurationfilespecifyingadditionaloptions-v[--verbose][=arg(=v)]bemoreverbose(includemultipletimesformoreverbositye.g.-vvvvv)--quietquieteroutput#静默模式--portargspecifyportnumber-27017bydefault--bind_ipargcommaseparatedlistofipaddressestolistenon-alllocalipsbydefault--ipv6enableIPv6support(disabledbydefault)--maxConnsargmaxnumberofsimultaneousconnections-1000000bydefault--logpatharglogfiletosendwritetoinsteadofstdout-hastobeafile,notdirectory#指定日志存放目录--sysloglogtosystem'
    ssyslogfacilityinsteadoffileorstdout--syslogFacilityargsyslogfacilityusedformongodbsyslogmessage--logappendappendtologpathinsteadof#指定日志是以追加还是以覆盖的方式写入日志文件over-writing--logRotateargsetthelogrotationbehavior(rename|reopen)--timeStampFormatargDesiredformatfortimestampsinlogmessages.Oneofctime,iso8601-utcoriso8601-local--pidfilepathargfullpathtopidfile(ifnotset,nopidfileiscreated)--keyFileargprivatekeyforclusterauthentication--noauthrunwithoutsecurity#无认证模式运行--setParameterargSetaconfigurableparameter--httpinterfaceenablehttpinterface--transitionToAuthForrollingaccesscontrolupgrade.Attempttoauthenticateoveroutgoingconnectionsandproceedregardlessofsuccess.Acceptincomingconnectionswithorwithoutauthentication.--clusterAuthModeargAuthenticationmodeusedforclusterauthentication.Alternativesare(keyFile|sendKeyFile|sendX509|x509)--nounixsocketdisablelisteningonunixsockets--unixSocketPrefixargalternativedirectoryforUNIXdomainsockets(defaultsto/tmp)--filePermissionsargpermissionstosetonUNIXdomainsocketfile-0700bydefault--forkforkserverprocess#以创建子进程的方式运行--networkMessageCompressorsargComma-separatedlistofcompressorstousefornetworkmessages--authrunwithsecurity#认证模式运行--jsonpallowJSONPaccessviahttp(hassecurityimplications)--restturnonsimplerestapi--slowmsarg(=100)valueofslowforprofileandconsolelog--profilearg0=off1=slow,2=all--cpuperiodicallyshowcpuandiowait#周期性的显示cpu和io的使用情况utilization--sysinfoprintsomediagnosticsysteminformation--noIndexBuildRetrydon'
    tretryanyindexbuildsthatwereinterruptedbyshutdown--noscriptingdisablescriptingengine#关闭脚本引擎--notablescandonotallowtablescans--shutdownkillarunningserver(forinitscripts)Replicationoptions:--oplogSizeargsizetouse(inMB)forreplicationoplog.defaultis5%ofdiskspace(i.e.largeisgood)#指定操作日志的大小Master/slaveoptions(old;
    usereplicasetsinstead):--mastermastermode--slaveslavemode--sourceargwhenslave:specifymasteras#当为从时,指定主的地址和端口--onlyargwhenslave:specifyasingledatabasetoreplicate#当为从时,指定需要从主复制的单一库--slavedelayargspecifydelay(inseconds)tobeusedwhenapplyingmasteropstoslave--autoresyncautomaticallyresyncifslavedataisstale#自动同步从的数据Replicasetoptions:--replSetargargis[/]--replIndexPrefetchargspecifyindexprefetchingbehavior(ifsecondary)[none|_id_only|all]--enableMajorityReadConcernenablesmajorityreadConcernShardingoptions:--configsvrdeclarethisisaconfigdbofacluster;
    defaultport27019;
    defaultdir/data/configdb--shardsvrdeclarethisisasharddbofacluster;
    defaultport27018Storageoptions:--storageEngineargwhatstorageenginetouse-defaultstowiredTigerifnodatafilespresent--dbpathargdirectoryfordatafiles-defaultsto/data/db#指定数据存放目录--directoryperdbeachdatabasewillbestoredinaseparatedirectory--nopreallocdisabledatafilepreallocation-willoftenhurtperformance#关闭数据库文件大小预分配--nssizearg(=16).nsfilesize(inMB)fornewdatabases#新数据库ns文件的默认大小--quotalimitseachdatabasetoacertainnumberoffiles(8default)#开始数据库配额的管理--quotaFilesargnumberoffilesallowedperdb,implies--quota#规定每个数据库允许的文件数--smallfilesuseasmallerdefaultfilesize#使用较小的默认文件大小--syncdelayarg(=60)secondsbetweendisksyncs(0=never,butnotrecommended)#系统同步刷新磁盘的时间,默认是60s--upgradeupgradedbifneeded#如果需要就更新数据库--repairrunrepaironalldbs#修复所有的数据库--repairpathargrootdirectoryforrepairfiles-defaultstodbpath--journalenablejournaling--nojournaldisablejournaling(journalingisonbydefaultfor64bit)--journalOptionsargjournaldiagnosticoptions--journalCommitIntervalarghowoftentogroup/batchcommit(ms)WiredTigeroptions:--wiredTigerCacheSizeGBargmaximumamountofmemorytoallocateforcache;
    defaultsto1/2ofphysicalRAM--wiredTigerStatisticsLogDelaySecsarg(=0)secondstowaitbetweeneachwritetoastatisticsfileinthedbpath;
    0meansdonotlogstatistics--wiredTigerJournalCompressorarg(=snappy)useacompressorforlogrecords[none|snappy|zlib]--wiredTigerDirectoryForIndexesPutindexesanddataindifferentdirectories--wiredTigerCollectionBlockCompressorarg(=snappy)blockcompressionalgorithmforcollectiondata[none|snappy|zlib]--wiredTigerIndexPrefixCompressionarg(=1)useprefixcompressiononrow-storeleafpages[root@localhostbin]#

连接mongodb

    [root@localhostbin]#./mongo--port10001MongoDBshellversionv3.4.3connectingto:mongodb://127.0.0.1:10001/MongoDBserverversion:3.4.3WelcometotheMongoDBshell.Forinteractivehelp,type"help".Formorecomprehensivedocumentation,see http://docs.mongodb.org/Questions?Trythesupportgroup http://groups.google.com/group/mongodb-userServerhasstartupwarnings:2017-04-13T10:43:51.043+0800ISTORAGE[initandlisten]2017-04-13T10:43:51.043+0800ISTORAGE[initandlisten]**WARNING:UsingtheXFSfilesystemisstronglyrecommendedwiththeWiredTigerstorageengine2017-04-13T10:43:51.043+0800ISTORAGE[initandlisten]**Seehttp://dochub.mongodb.org/core/prodnotes-filesystem2017-04-13T10:43:52.492+0800ICONTROL[initandlisten]2017-04-13T10:43:52.508+0800ICONTROL[initandlisten]**WARNING:Accesscontrolisnotenabledforthedatabase.2017-04-13T10:43:52.508+0800ICONTROL[initandlisten]**Readandwriteaccesstodataandconfigurationisunrestricted.2017-04-13T10:43:52.508+0800ICONTROL[initandlisten]**WARNING:Youarerunningthisprocessastherootuser,whichisnotrecommended.2017-04-13T10:43:52.508+0800ICONTROL[initandlisten]2017-04-13T10:43:52.509+0800ICONTROL[initandlisten]2017-04-13T10:43:52.509+0800ICONTROL[initandlisten]**WARNING:softrlimitstoolow.rlimitssetto1818processes,65535files.Numberofprocessesshouldbeatleast32767.5:0.5timesnumberoffiles.>usetest;
    switchedtodbtest>

若数据库出现如不能连上,则是一个data目录下的mongod.lock文件的问题,可以用如下的修复的命令,

    [root@localhostbin]#./mongod--repair2017-04-14T10:40:50.902+0800ICONTROL[initandlisten]MongoDBstarting:pid=23422port=27017dbpath=/data/db64-bithost=localhost.localdomain2017-04-14T10:40:50.902+0800ICONTROL[initandlisten]dbversionv3.4.32017-04-14T10:40:50.902+0800ICONTROL[initandlisten]gitversion:f07437fb5a6cca07c10bafa78365456eb1d6d5e12017-04-14T10:40:50.902+0800ICONTROL[initandlisten]allocator:tcmalloc2017-04-14T10:40:50.902+0800ICONTROL[initandlisten]modules:none2017-04-14T10:40:50.902+0800ICONTROL[initandlisten]buildenvironment:2017-04-14T10:40:50.902+0800ICONTROL[initandlisten]distarch:x86_642017-04-14T10:40:50.902+0800ICONTROL[initandlisten]target_arch:x86_642017-04-14T10:40:50.902+0800ICONTROL[initandlisten]options:{
    repair:true}
    2017-04-14T10:40:50.926+0800ISTORAGE[initandlisten]exceptionininitAndListen:29Datadirectory/data/dbnotfound.,terminating2017-04-14T10:40:50.926+0800INETWORK[initandlisten]shutdown:goingtocloselisteningsockets...2017-04-14T10:40:50.926+0800INETWORK[initandlisten]shutdown:goingtoflushdiaglog...2017-04-14T10:40:50.928+0800ICONTROL[initandlisten]nowexiting2017-04-14T10:40:50.928+0800ICONTROL[initandlisten]shuttingdownwithcode:100[root@localhostbin]#

通过配置文件来配置Mongodb

    [root@localhost/]#cd/app/mongodb[root@localhostmongodb]#lsbindataGNU-AGPL-3.0logsMPL-2READMETHIRD-PARTY-NOTICES[root@localhostmongodb]#mkdiretc[root@localhostmongodb]#mkdirpid[root@localhostmongodb]#touchetc/mongodb.conf[root@localhostmongodb]#vimetc/mongodb.confport=10001dbpath=/app/mongodb/data/logpath=/app/mongodb/mongodb.loglogappend=truemaxConns=20000fork=truepidfilepath=/app/mongodb/pid/mongodb.pid[root@localhostmongodb]#bin/mongod-fetc/mongodb.confabouttoforkchildprocess,waitinguntilserverisreadyforconnections.forkedprocess:23503childprocessstartedsuccessfully,parentexiting[root@localhostmongodb]#lsof-i:10001COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAMEmongod23503root7uIPv4694270t0TCP*:scp-config(LISTEN)[root@localhostmongodb]#
    相关热词搜索: