在CentOS中使用 yum 安装MongoDB及服务器端配置

论坛 期权论坛 脚本     
匿名网站用户   2020-12-20 15:24   11   0
Java代码收藏代码
  1. 一、准备工作:
  2. 运行yum命令查看MongoDB的包信息[root@vm~]#yuminfomongo-10gen
  3. (提示没有相关匹配的信息,)
  4. 说明你的centos系统中的yum源不包含MongoDB的相关资源,所以要在使用yum命令安装MongoDB前需要增加yum源,也就是在/etc/yum.repos.d/目录中增加*.repoyum源配置文件,以下分别是针对centos64位和32位不同的系统的MongoDByum源配置内容:
  5. 我们这里就将该文件命名为:/etc/yum.repos.d/10gen.repo
  6. For64-bityum源配置:
  7. vi/etc/yum.repos.d/10gen.repo
  8. [10gen]
  9. name=10genRepository
  10. baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
  11. gpgcheck=0
  12. For32-bityum源配置:
  13. vi/etc/yum.repos.d/10gen.repo
  14. [10gen]
  15. name=10genRepository
  16. baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
  17. gpgcheck=0
  18. 根据自己的系统选择相应的配置内容
  19. 查看系统是32位还是64位的方法:
  20. $uname-a
  21. 含有x86_64的那说明是64位的,例如我的centos6.064bit系统执行这个命令后显示:
  22. Linuxvm.centos62.6.32-71.29.1.el6.x86_64#1SMPMonJun2719:49:27BST2011x86_64x86_64x86_64GNU/Linux
  23. 做好yum源的配置后,如果配置正确执行下面的命令便可以查询MongoDB相关的信息:
  24. 查看mongoDB的服务器包的信息
  25. [root@vm~]#yuminfomongo-10gen-server
  26. ****(省略多行不重要的信息)*********
  27. AvailablePackages
  28. Name:mongo-10gen-server
  29. Arch:x86_64
  30. Version:1.8.2
  31. Release:mongodb_1
  32. Size:4.7M
  33. Repo:10gen
  34. Summary:mongoserver,shardingserver,andsupportscripts
  35. URL:http://www.mongodb.org
  36. License:AGPL3.0
  37. Description:Mongo(from"huMONGOus")isaschema-freedocument-oriented
  38. :database.
  39. :
  40. :Thispackageprovidesthemongoserversoftware,mongosharding
  41. :serversoftwware,defaultconfigurationfiles,andinit.dscripts.
  42. [root@vm~]#
  43. 查看客户端工具的信息
  44. [root@vm~]#yuminfomongo-10gen
  45. Loadedplugins:fastestmirror
  46. **(省略多行不重要的信息)**
  47. InstalledPackages
  48. Name:mongo-10gen
  49. Arch:x86_64
  50. Version:1.8.2
  51. Release:mongodb_1
  52. Size:55M
  53. Repo:10gen
  54. Summary:mongoclientshellandtools
  55. URL:http://www.mongodb.org
  56. License:AGPL3.0
  57. Description:Mongo(from"huMONGOus")isaschema-freedocument-oriented
  58. :database.Itfeaturesdynamicprofileablequeries,fullindexing,
  59. :replicationandfail-oversupport,efficientstorageoflarge
  60. :binarydataobjects,andauto-sharding.
  61. :
  62. :Thispackageprovidesthemongoshell,import/exporttools,and
  63. :otherclientutilities.
  64. [root@vm~]#
  65. 二、安装MongoDB的服务器端和客户端工具
  66. 1.安装服务器端:
  67. [root@vm~]#yuminstallmongo-10gen-server
  68. [root@vm~]#ls/usr/bin/mongo(tab键)
  69. mongomongodmongodumpmongoexportmongofilesmongoimportmongorestoremongosmongostat
  70. -----------------------------------------------
  71. 这些就是MongoDB的程序文件
  72. 因为mongo-10gen-server包依赖于mongo-10gen,所以安装了服务器后就不需要单独安装客户端工具包mongo-10gen了
  73. 2.单独安装可客户端:
  74. [root@vm~]#yuminstallmongo-10gen
  75. 3.检查
  76. [root@vm~]#/etc/init.d/mongod
  77. Usage:/etc/init.d/mongod{start|stop|status|restart|reload|force-reload|condrestart}
  78. [root@vm~]#/etc/init.d/mongodstatus
  79. mongod(pid1341)isrunning...
  80. [root@vm~]#
  81. 说明安后服务器端已经在运行了
  82. 4.服务器配置:/etc/mongod.conf
  83. [root@vm~]#cat/etc/mongod.conf
  84. #mongo.conf
  85. #wheretolog
  86. logpath=/var/log/mongo/mongod.log
  87. logappend=true#以追加方式写入日志
  88. #forkandruninbackground
  89. fork=true
  90. #port=27017#端口
  91. dbpath=/var/lib/mongo#数据库文件保存位置
  92. #EnablesperiodicloggingofCPUutilizationandI/Owait
  93. #启用定期记录CPU利用率和I/O等待
  94. #cpu=true
  95. #Turnon/offsecurity.Offiscurrentlythedefault
  96. #是否以安全认证方式运行,默认是不认证的非安全方式
  97. #noauth=true
  98. #auth=true
  99. #Verboseloggingoutput.
  100. #详细记录输出
  101. #verbose=true
  102. #Inspectallclientdataforvalidityonreceipt(usefulfor
  103. #developingdrivers)用于开发驱动程序时的检查客户端接收数据的有效性
  104. #objcheck=true
  105. #Enabledbquotamanagement启用数据库配额管理,默认每个db可以有8个文件,可以用quotaFiles参数设置
  106. #quota=true
  107. #设置oplog记录等级
  108. #Setoplogginglevelwherenis
  109. #0=off(default)
  110. #1=W
  111. #2=R
  112. #3=both
  113. #7=W+somereads
  114. #oplog=0
  115. #Diagnostic/debuggingoption动态调试项
  116. #nocursors=true
  117. #Ignorequeryhints忽略查询提示
  118. #nohints=true
  119. #禁用http界面,默认为localhost:28017
  120. #DisabletheHTTPinterface(Defaultstolocalhost:27018).这个端口号写的是错的
  121. #nohttpinterface=true
  122. #关闭服务器端脚本,这将极大的限制功能
  123. #Turnsoffserver-sidescripting.Thiswillresultingreatlylimited
  124. #functionality
  125. #noscripting=true
  126. #关闭扫描表,任何查询将会是扫描失败
  127. #Turnsofftablescans.Anyquerythatwoulddoatablescanfails.
  128. #notablescan=true
  129. #关闭数据文件预分配
  130. #Disabledatafilepreallocation.
  131. #noprealloc=true
  132. #为新数据库指定.ns文件的大小,单位:MB
  133. #Specify.nsfilesizefornewdatabases.
  134. #nssize=<size>
  135. #AccouttokenforMongomonitoringserver.
  136. #mms-token=<token>
  137. #mongo监控服务器的名称
  138. #ServernameforMongomonitoringserver.
  139. #mms-name=<server-name>
  140. #mongo监控服务器的ping间隔
  141. #PingintervalforMongomonitoringserver.
  142. #mms-interval=<seconds>
  143. #ReplicationOptions复制选项
  144. #inreplicatedmongodatabases,specifyherewhetherthisisaslaveormaster在复制中,指定当前是从属关系
  145. #slave=true
  146. #source=master.example.com
  147. #Slaveonly:specifyasingledatabasetoreplicate
  148. #only=master.example.com
  149. #or
  150. #master=true
  151. #source=slave.example.com
  152. [root@vm~]#
  153. 以上是默认的配置文件中的一些参数,更多参数可以用mongod-h命令来查看
  154. [root@vm~]#mongod-h
  155. Allowedoptions:
  156. Generaloptions:
  157. -h[--help]showthisusageinformation
  158. --versionshowversioninformation
  159. -f[--config]argconfigurationfilespecifyingadditionaloptions指定启动配置文件路径
  160. -v[--verbose]bemoreverbose(includemultipletimesformore
  161. verbositye.g.-vvvvv)
  162. --quietquieteroutput
  163. --portargspecifyportnumber端口
  164. --bind_ipargcommaseparatedlistofipaddressestolistenon-
  165. alllocalipsbydefault绑定ip,可以多个
  166. --maxConnsargmaxnumberofsimultaneousconnections最大并发连接数
  167. --logpatharglogfiletosendwritetoinsteadofstdout-hasto
  168. beafile,notdirectory日志文件路径
  169. --logappendappendtologpathinsteadofover-writing日志写入方式
  170. --pidfilepathargfullpathtopidfile(ifnotset,nopidfileis
  171. created)pid文件路径
  172. --keyFileargprivatekeyforclusterauthentication(onlyfor
  173. replicasets)集群认证私钥,仅适用于副本集
  174. --unixSocketPrefixargalternativedirectoryforUNIXdomainsockets
  175. (defaultsto/tmp)替代目录
  176. --forkforkserverprocess
  177. --authrunwithsecurity使用认证方式运行
  178. --cpuperiodicallyshowcpuandiowaitutilization定期显示的CPU和IO等待利用率
  179. --dbpathargdirectoryfordatafiles数据库文件路径
  180. --diaglogarg0=off1=W2=R3=both7=W+somereadsoplog记录等级
  181. --directoryperdbeachdatabasewillbestoredinaseparatedirectory
  182. 每个数据库存储到单独目录
  183. --journalenablejournaling记录日志,建议开启,在异常宕机时可以恢复一些数据
  184. --journalOptionsargjournaldiagnosticoptions
  185. --ipv6enableIPv6support(disabledbydefault)
  186. --jsonpallowJSONPaccessviahttp(hassecurity
  187. implications)允许JSONP通过http访问,该方式存在安全隐患
  188. --noauthrunwithoutsecurity不带安全认证的方式
  189. --nohttpinterfacedisablehttpinterface禁用http接口
  190. --nopreallocdisabledatafilepreallocation-willoftenhurt
  191. performance禁用数据文件的预分配,往往会损害性能
  192. --noscriptingdisablescriptingengine禁用脚本引擎
  193. --notablescandonotallowtablescans不允许表扫描
  194. --nounixsocketdisablelisteningonunixsockets禁止unixsockets监听
  195. --nssizearg(=16).nsfilesize(inMB)fornewdatabases为新数据设置.ns文件的大小
  196. --objcheckinspectclientdataforvalidityonreceipt检查在收到客户端的数据的有效性
  197. --profilearg0=off1=slow,2=all
  198. --quotalimitseachdatabasetoacertainnumberoffiles(8
  199. default)启用数据库配额管理,默认每个db可以有8个文件,可以用quotaFiles参数设置
  200. --quotaFilesargnumberoffilesallowerperdb,requires--quota
  201. --restturnonsimplerestapi开启restapi
  202. --repairrunrepaironalldbs修复所有数据库
  203. --repairpathargrootdirectoryforrepairfiles-defaultstodbpath修复文件的根目录,默
  204. 认为dbpath指定的目录
  205. --slowmsarg(=100)valueofslowforprofileandconsolelog
  206. --smallfilesuseasmallerdefaultfilesize
  207. --syncdelayarg(=60)secondsbetweendisksyncs(0=never,butnot
  208. recommended)与硬盘同步数据的时间,默认60秒,0表示不同步到硬盘(不建议)
  209. --sysinfoprintsomediagnosticsysteminformation打印一些诊断系统信息
  210. --upgradeupgradedbifneeded如果必要,将数据库文件升级到新的格式
  211. (<=1.01.1+升级时所需的)
  212. Replicationoptions:复制选项
  213. --fastsyncindicatethatthisinstanceisstartingfromadbpath
  214. snapshotofthereplpeer从一个dbpath快照开始同步
  215. --autoresyncautomaticallyresyncifslavedataisstale自动同步,如果从机的数据不是新的
  216. 自动同步
  217. --oplogSizeargsizelimit(inMB)foroplogoplog的大小
  218. Master/slaveoptions:主/从配置选项
  219. --mastermastermode主模式
  220. --slaveslavemode从属模式
  221. --sourceargwhenslave:specifymasteras<server:port>从属服务器上指定主服务器地址
  222. --onlyargwhenslave:specifyasingledatabasetoreplicate从属服务器上指定要复制的
  223. 数据库
  224. --slavedelayargspecifydelay(inseconds)tobeusedwhenapplying
  225. masteropstoslave指定从主服务器上同步数据的时间间隔单位秒
  226. Replicasetoptions:副本集选项
  227. --replSetargargis<setname>[/<optionalseedhostlist>]
  228. 参数:<名称>[<种子主机列表>]
  229. Shardingoptions:分片设置选项
  230. --configsvrdeclarethisisaconfigdbofacluster;defaultport
  231. 27019;defaultdir/data/configdb声明这是一个集群的配置数据库,
  232. 默认的端口是27019默认的路径是/data/configdb
  233. --shardsvrdeclarethisisasharddbofacluster;defaultport
  234. 27018声明这是集群的一个分片数据库,默认端口为27018
  235. --noMoveParanoiaturnoffparanoidsavingofdataformoveChunk.this
  236. isonbydefaultfornow,butdefaultwillswitch
  237. 关闭偏着保存大块数据。现在它是默认的,但是会变换
  238. [root@vm~]#
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP